<commit_before>import unittest
import sys

from robot.utils.asserts import assert_equals, assert_raises_with_msg,\
    assert_true, assert_false
from robot import utils
from robot.errors import DataError

from robot.common.model import BaseTestSuite, BaseTestCase, _Critical

def _get_suite():
    suite = BaseTestSuite('Root')
    suite.suites = [ BaseTestSuite('Sub1', parent=suite), BaseTestSuite('Sub2', parent=suite) ]
    suite.suites[0].suites = [ BaseTestSuite('Sub11', parent=suite.suites[0]), 
                              BaseTestSuite('Sub', parent=suite.suites[0])]
    suite.suites[0].suites[0].tests \
            = [ BaseTestCase('T11', suite.suites[0].suites[0]), 
               BaseTestCase('T12', suite.suites[0].suites[0]) ]
    suite.suites[0].suites[0].suites \
            = [ BaseTestSuite('Sub', parent=suite.suites[0].suites[0]) ]
    suite.suites[0].suites[0].suites[0].tests \
            = [ BaseTestCase('T', suite.suites[0].suites[0].suites[0]) ]
    suite.suites[0].suites[1].tests = [ BaseTestCase('T', parent=suite.suites[0].suites[1]) ]
    suite.suites[1].tests = [ BaseTestCase('T21', suite.suites[1]) ]
    return suite

class TestGetLongName(unittest.TestCase):
    
    def setUp(self):
        self.suite = _get_suite()
        
    def test_get_long_name_for_root_suite(self):
        assert_equals(self.suite.get_long_name(), 'Root')

    def test_get_long_name_for_sub_suite(self):
        assert_equals(self.suite.suites[0].get_long_name(), 'Root.Sub1')

    def test_get_long_name_for_sub_sub_suite(self):
        assert_equals(self.suite.suites[0].suites[1].get_long_name(), 
                      'Root.Sub1.Sub')

    def test_get_long_name_for_test(self):
        assert_equals(self.suite.suites[0].suites[0].tests[0].get_long_name(), 
                      'Root.Sub1.Sub11.T11')

    def test_get_long_name_for_test_with_non_default_separator(self):
        assert_equals(self.suite.suites[0].suites[0].tests[0].get_long_name(separator='|'), 
                      'Root|Sub1|Sub11|T11')

    def test_get_long_name_for_sub_suite_with_parts(self):
        assert_equals(self.suite.suites[0].get_long_name(separator=None), 
                      ['Root', 'Sub1'])

    def test_get_long_name_for_test_with_parts(self):
        assert_equals(self.suite.suites[0].suites[0].tests[0].get_long_name(separator=None), 
                      ['Root', 'Sub1', 'Sub11', 'T11'])

    def test_get_long_name_for_sub_suite_with_split_level_smaller(self):
        assert_equals(self.suite.suites[0].get_long_name(split_level=1), 
                      'Sub1')

    def test_get_long_name_for_sub_suite_with_split_level_same(self):
        assert_equals(self.suite.suites[0].get_long_name(split_level=2), 
                      'Root.Sub1')

    def test_get_long_name_for_sub_suite_with_split_level_larger(self):
        assert_equals(self.suite.suites[0].get_long_name(split_level=3), 
                      'Root.Sub1')

    def test_get_long_name_for_test_with_split_level_smaller(self):
        assert_equals(self.suite.suites[0].suites[0].tests[0].get_long_name(split_level=2), 
                      'Sub11.T11')

    def test_get_long_name_for_test_with_split_level_at_parent_suite_level(self):
        assert_equals(self.suite.suites[0].suites[0].tests[0].get_long_name(split_level=3), 
                      'Root.Sub1.Sub11.T11')

    def test_get_long_name_for_test_with_split_level_same(self):
        assert_equals(self.suite.suites[0].suites[0].tests[0].get_long_name(split_level=4), 
                      'Root.Sub1.Sub11.T11')

    def test_get_long_name_for_test_with_split_level_larger(self):
        assert_equals(self.suite.suites[0].suites[0].tests[0].get_long_name(split_level=5), 
                      'Root.Sub1.Sub11.T11')
    

class TestFilterByNames(unittest.TestCase):
    
    
    def test_with_suites(self):
        for names, count in [ (['Root'], 5),
                              (['Sub1'], 4),
                              (['Sub 11'], 3),
                              (['s u b 2'], 1), 
                              (['Sub?'], 5),
                              (['Sub 1*'], 4),
                              (['ROOT','Sub1'], 5),
                              (['Sub2','Nonex'], 1),
                              (['Sub11.Sub'], 1),
                              (['Root.Sub1.Sub'], 1)]:
            suite = _get_suite()
            suite.filter_by_names(names, [])
            assert_equals(suite.get_test_count(), count, names)

    def test_with_suites_no_matches(self):
        suite = _get_suite()
        err =  "Suite 'Root' contains no test suites named '%s'."
        assert_raises_with_msg(DataError, err % ('nonex'), 
                               suite.filter_by_names, ['nonex'], [])
        assert_raises_with_msg(DataError, err % ('b1.Sub'), 
                               suite.filter_by_names, ['b1.Sub'], [])

    def test_with_tests(self):
        for names, count in [ (['T11'], 1),
                              (['?12'], 1),
                              (['t 2  1'], 1), 
                              (['t*'], 5),
                              (['??1'], 2),
                              (['T11','T12'], 2),
                              (['Nonex','T21','Nonex2'], 1) ]:
            suite = _get_suite()
            suite.filter_by_names([], names)
            assert_equals(suite.get_test_count(), count)

    def test_with_tests_no_matches(self):
        suite = _get_suite()
        err =  "Suite 'Root' contains no test cases named 'x', 'y' or 'z'."
        assert_raises_with_msg(DataError, err, suite.filter_by_names, [], ['x','y','z'])

    def test_with_suites_and_tests(self):
        for suites, tests, count in [ (['Root'], ['T11'], 1),
                                      (['Sub1'], ['t 1  2'], 1), 
                                      (['sub11'], ['t11','nonex'], 1),
                                      (['sub1'], ['t11','t2.1'], 1),
                                      (['sub?'], ['t11','t21'], 2),
                                      (['ROOT','nonex'], ['t11','t21'], 2),
                                      (['*'], ['t*'], 5) ]:
            suite = _get_suite()
            suite.filter_by_names(suites, tests)
            assert_equals(suite.get_test_count(), count, '%s & %s'%(suites,tests))

    def test_with_suites_and_tests_no_matches(self):
        suite = _get_suite()
        for suites, tests in [ (['Root'], ['nonex']),
                               (['Nonex'], ['T1.1']),
                               (['Sub2'], ['T1.1']), ]:
            msg = ("Suite 'Root' contains no test cases %s in suites %s." <commit_msg>test_baseobject: Add test for long name --test filter<commit_after>import unittest
import sys

from robot.utils.asserts import assert_equals, assert_raises_with_msg,\
    assert_true, assert_false
from robot import utils
from robot.errors import DataError

from robot.common.model import BaseTestSuite, BaseTestCase, _Critical

def _get_suite():
    suite = BaseTestSuite('Root')
    suite.suites = [ BaseTestSuite('Sub1', parent=suite), BaseTestSuite('Sub2', parent=suite) ]
    suite.suites[0].suites = [ BaseTestSuite('Sub11', parent=suite.suites[0]), 
                              BaseTestSuite('Sub', parent=suite.suites[0])]
    suite.suites[0].suites[0].tests \
            = [ BaseTestCase('T11', suite.suites[0].suites[0]), 
               BaseTestCase('T12', suite.suites[0].suites[0]) ]
    suite.suites[0].suites[0].suites \
            = [ BaseTestSuite('Sub', parent=suite.suites[0].suites[0]) ]
    suite.suites[0].suites[0].suites[0].tests \
            = [ BaseTestCase('T', suite.suites[0].suites[0].suites[0]) ]
    suite.suites[0].suites[1].tests = [ BaseTestCase('T', parent=suite.suites[0].suites[1]) ]
    suite.suites[1].tests = [ BaseTestCase('T21', suite.suites[1]) ]
    return suite

class TestGetLongName(unittest.TestCase):
    
    def setUp(self):
        self.suite = _get_suite()
        
    def test_get_long_name_for_root_suite(self):
        assert_equals(self.suite.get_long_name(), 'Root')

    def test_get_long_name_for_sub_suite(self):
        assert_equals(self.suite.suites[0].get_long_name(), 'Root.Sub1')

    def test_get_long_name_for_sub_sub_suite(self):
        assert_equals(self.suite.suites[0].suites[1].get_long_name(), 
                      'Root.Sub1.Sub')

    def test_get_long_name_for_test(self):
        assert_equals(self.suite.suites[0].suites[0].tests[0].get_long_name(), 
                      'Root.Sub1.Sub11.T11')

    def test_get_long_name_for_test_with_non_default_separator(self):
        assert_equals(self.suite.suites[0].suites[0].tests[0].get_long_name(separator='|'), 
                      'Root|Sub1|Sub11|T11')

    def test_get_long_name_for_sub_suite_with_parts(self):
        assert_equals(self.suite.suites[0].get_long_name(separator=None), 
                      ['Root', 'Sub1'])

    def test_get_long_name_for_test_with_parts(self):
        assert_equals(self.suite.suites[0].suites[0].tests[0].get_long_name(separator=None), 
                      ['Root', 'Sub1', 'Sub11', 'T11'])

    def test_get_long_name_for_sub_suite_with_split_level_smaller(self):
        assert_equals(self.suite.suites[0].get_long_name(split_level=1), 
                      'Sub1')

    def test_get_long_name_for_sub_suite_with_split_level_same(self):
        assert_equals(self.suite.suites[0].get_long_name(split_level=2), 
                      'Root.Sub1')

    def test_get_long_name_for_sub_suite_with_split_level_larger(self):
        assert_equals(self.suite.suites[0].get_long_name(split_level=3), 
                      'Root.Sub1')

    def test_get_long_name_for_test_with_split_level_smaller(self):
        assert_equals(self.suite.suites[0].suites[0].tests[0].get_long_name(split_level=2), 
                      'Sub11.T11')

    def test_get_long_name_for_test_with_split_level_at_parent_suite_level(self):
        assert_equals(self.suite.suites[0].suites[0].tests[0].get_long_name(split_level=3), 
                      'Root.Sub1.Sub11.T11')

    def test_get_long_name_for_test_with_split_level_same(self):
        assert_equals(self.suite.suites[0].suites[0].tests[0].get_long_name(split_level=4), 
                      'Root.Sub1.Sub11.T11')

    def test_get_long_name_for_test_with_split_level_larger(self):
        assert_equals(self.suite.suites[0].suites[0].tests[0].get_long_name(split_level=5), 
                      'Root.Sub1.Sub11.T11')
    

class TestFilterByNames(unittest.TestCase):
    
    
    def test_with_suites(self):
        for names, count in [ (['Root'], 5),
                              (['Sub1'], 4),
                              (['Sub 11'], 3),
                              (['s u b 2'], 1), 
                              (['Sub?'], 5),
                              (['Sub 1*'], 4),
                              (['ROOT','Sub1'], 5),
                              (['Sub2','Nonex'], 1),
                              (['Sub11.Sub'], 1),
                              (['Root.Sub1.Sub'], 1)]:
            suite = _get_suite()
            suite.filter_by_names(names, [])
            assert_equals(suite.get_test_count(), count, names)

    def test_with_suites_no_matches(self):
        suite = _get_suite()
        err =  "Suite 'Root' contains no test suites named '%s'."
        assert_raises_with_msg(DataError, err % ('nonex'), 
                               suite.filter_by_names, ['nonex'], [])
        assert_raises_with_msg(DataError, err % ('b1.Sub'), 
                               suite.filter_by_names, ['b1.Sub'], [])

    def test_with_tests(self):
        for names, count in [ (['T11'], 1),
                              (['?12'], 1),
                              (['t 2  1'], 1), 
                              (['t*'], 5),
                              (['??1'], 2),
                              (['T11','T12'], 2),
                              (['Nonex','T21','Nonex2'], 1),
                              (['Root.Sub1.Sub11.Sub.T'], 1),
                              (['Root.Sub1.Sub.T'], 1) ]:
            suite = _get_suite()
            suite.filter_by_names([], names)
            assert_equals(suite.get_test_count(), count)

    def test_with_tests_no_matches(self):
        suite = _get_suite()
        err =  "Suite 'Root' contains no test cases named 'x', 'y' or 'z'."
        assert_raises_with_msg(DataError, err, suite.filter_by_names, [], ['x','y','z'])

    def test_with_suites_and_tests(self):
        for suites, tests, count in [ (['Root'], ['T11'], 1),
                                      (['Sub1'], ['t 1  2'], 1), 
                                      (['sub11'], ['t11','nonex'], 1),
                                      (['sub1'], ['t11','t2.1'], 1),
                                      (['sub?'], ['t11','t21'], 2),
                                      (['ROOT','nonex'], ['t11','t21'], 2),
                                      (['*'], ['t*'], 5) ]:
            suite = _get_suite()
            suite.filter_by_names(suites, tests)
            assert_equals(suite.get_test_count(), count, '%s & %s'%(suites,tests))

    def test_with_suites_and_tests_no_matches(self):
        suite = _get_suite()
        for suites, tests in [ (['Root'], ['nonex']),
                               (['Nonex'], ['T1.1']),
                               (['Sub2'], ['T1.1']), ]:
            msg = ("Suite 'Root' contains no test cases %s in suites %s." 
{'fraction_non_alphanumeric': 0.14948835829749368, 'fraction_numerical': 0.02817736912353552, 'mean_word_length': 2.0575833144411697, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1058288', 'n_tokens_mistral': 4590, 'n_tokens_neox': 4280, 'n_words': 603}