Exemplo n.º 1
0
    def test_visit_return_continue_and_break(self):
        suite = ResultSuite()
        suite.tests.create().body.create_return().body.create_keyword(kwname='R')
        suite.tests.create().body.create_continue().body.create_message(message='C')
        suite.tests.create().body.create_break().body.create_keyword(kwname='B')

        class Visitor(SuiteVisitor):
            visited_return = visited_continue = visited_break = False
            visited_return_body = visited_continue_body = visited_break_body = False

            def start_return(self, return_):
                self.visited_return = True

            def end_continue(self, continue_):
                self.visited_continue = True

            def start_break(self, break_):
                self.visited_break = True

            def start_keyword(self, keyword):
                if keyword.name == 'R':
                    self.visited_return_body = True
                if keyword.name == 'B':
                    self.visited_break_body = True

            def visit_message(self, msg):
                if msg.message == 'C':
                    self.visited_continue_body = True

        visitor = Visitor()
        suite.visit(visitor)
        for visited in 'return', 'continue', 'break':
            assert_equal(getattr(visitor, f'visited_{visited}'), True, visited)
            assert_equal(getattr(visitor, f'visited_{visited}_body'), True, f'{visited}_body')
Exemplo n.º 2
0
 def _assert_removed(self, failing=0, passing=0, messages=0, expected=0):
     suite = TestSuite()
     kw = suite.tests.create().body.create_keyword(
         libname='BuiltIn', kwname='Wait Until Keyword Succeeds'
     )
     for i in range(failing):
         kw.body.create_keyword(status='FAIL')
     for i in range(passing):
         kw.body.create_keyword(status='PASS')
     for i in range(messages):
         kw.body.create_message()
     suite.visit(WaitUntilKeywordSucceedsRemover())
     assert_equal(len(kw.body), expected)
Exemplo n.º 3
0
class TestTestAttributes(unittest.TestCase):
    def setUp(self):
        self.suite = TestSuite()
        self.suite.tests = [TestCase()]
        self.suite.suites = [TestSuite()]
        self.suite.suites[0].tests = [TestCase(tags=['tag'])]

    def test_set_tags(self):
        self.suite.visit(SuiteConfigurer(set_tags=['new']))
        assert_equal(list(self.suite.tests[0].tags), ['new'])
        assert_equal(list(self.suite.suites[0].tests[0].tags), ['new', 'tag'])

    def test_tags_are_normalized(self):
        self.suite.visit(
            SuiteConfigurer(set_tags=['TAG', '', 't a g', 'NONE']))
        assert_equal(list(self.suite.tests[0].tags), ['TAG'])
        assert_equal(list(self.suite.suites[0].tests[0].tags), ['tag'])

    def test_remove_negative_tags(self):
        self.suite.visit(SuiteConfigurer(set_tags=['n', '-TAG']))
        assert_equal(list(self.suite.tests[0].tags), ['n'])
        assert_equal(list(self.suite.suites[0].tests[0].tags), ['n'])

    def test_remove_negative_tags_using_pattern(self):
        self.suite.visit(SuiteConfigurer(set_tags=['-t*', '-nomatch']))
        assert_equal(list(self.suite.tests[0].tags), [])
        assert_equal(list(self.suite.suites[0].tests[0].tags), [])
class TestTestAttributes(unittest.TestCase):

    def setUp(self):
        self.suite = TestSuite()
        self.suite.tests = [TestCase()]
        self.suite.suites = [TestSuite()]
        self.suite.suites[0].tests = [TestCase(tags=['tag'])]

    def test_set_tags(self):
        self.suite.visit(SuiteConfigurer(set_tags=['new']))
        assert_equal(list(self.suite.tests[0].tags), ['new'])
        assert_equal(list(self.suite.suites[0].tests[0].tags), ['new', 'tag'])

    def test_tags_are_normalized(self):
        self.suite.visit(SuiteConfigurer(set_tags=['TAG', '', 't a g', 'NONE']))
        assert_equal(list(self.suite.tests[0].tags), ['TAG'])
        assert_equal(list(self.suite.suites[0].tests[0].tags), ['tag'])

    def test_remove_negative_tags(self):
        self.suite.visit(SuiteConfigurer(set_tags=['n', '-TAG']))
        assert_equal(list(self.suite.tests[0].tags), ['n'])
        assert_equal(list(self.suite.suites[0].tests[0].tags), ['n'])

    def test_remove_negative_tags_using_pattern(self):
        self.suite.visit(SuiteConfigurer(set_tags=['-t*', '-nomatch']))
        assert_equal(list(self.suite.tests[0].tags), [])
        assert_equal(list(self.suite.suites[0].tests[0].tags), [])
Exemplo n.º 5
0
class TestFiltering(unittest.TestCase):
    def setUp(self):
        self.suite = TestSuite(name='root')
        self.suite.tests = [
            TestCase(name='n0'),
            TestCase(name='n1', tags=['t1']),
            TestCase(name='n2', tags=['t1', 't2'])
        ]
        self.suite.suites.create(name='sub').tests.create(name='n1',
                                                          tags=['t1'])

    def test_include(self):
        self.suite.visit(
            SuiteConfigurer(include_tags=['t1', 'none', '', '?2']))
        assert_equal([t.name for t in self.suite.tests], ['n1', 'n2'])
        assert_equal([t.name for t in self.suite.suites[0].tests], ['n1'])

    def test_exclude(self):
        self.suite.visit(SuiteConfigurer(exclude_tags=['t1', '?1ANDt2']))
        assert_equal([t.name for t in self.suite.tests], ['n0'])
        assert_equal(list(self.suite.suites), [])

    def test_include_by_names(self):
        self.suite.visit(
            SuiteConfigurer(include_suites=['s?b', 'xxx'],
                            include_tests=['', '*1', 'xxx']))
        assert_equal(list(self.suite.tests), [])
        assert_equal([t.name for t in self.suite.suites[0].tests], ['n1'])

    def test_no_matching_tests_with_one_selector_each(self):
        configurer = SuiteConfigurer(include_tags='i',
                                     exclude_tags='e',
                                     include_suites='s',
                                     include_tests='t')
        assert_raises_with_msg(
            DataError, "Suite 'root' contains no tests with tag 'i', "
            "without tag 'e' and named 't' in suite 's'.", self.suite.visit,
            configurer)

    def test_no_matching_tests_with_multiple_selectors(self):
        configurer = SuiteConfigurer(include_tags=['i1', 'i2'],
                                     exclude_tags=['e1', 'e2'],
                                     include_suites=['s1', 's2', 's3'],
                                     include_tests=['t1', 't2'])
        assert_raises_with_msg(
            DataError, "Suite 'root' contains no tests "
            "with tags 'i1' or 'i2', "
            "without tags 'e1' or 'e2' and "
            "named 't1' or 't2' "
            "in suites 's1', 's2' or 's3'.", self.suite.visit, configurer)

    def test_empty_suite(self):
        suite = TestSuite(name='x')
        suite.visit(SuiteConfigurer(empty_suite_ok=True))
        assert_raises_with_msg(DataError, "Suite 'x' contains no tests.",
                               suite.visit, SuiteConfigurer())
class TestFiltering(unittest.TestCase):

    def setUp(self):
        self.suite = TestSuite(name='root')
        self.suite.tests = [TestCase(name='n0'), TestCase(name='n1', tags=['t1']),
                            TestCase(name='n2', tags=['t1', 't2'])]
        self.suite.suites.create(name='sub').tests.create(name='n1', tags=['t1'])

    def test_include(self):
        self.suite.visit(SuiteConfigurer(include_tags=['t1', 'none', '', '?2']))
        assert_equal([t.name for t in self.suite.tests], ['n1', 'n2'])
        assert_equal([t.name for t in self.suite.suites[0].tests], ['n1'])

    def test_exclude(self):
        self.suite.visit(SuiteConfigurer(exclude_tags=['t1', '?1ANDt2']))
        assert_equal([t.name for t in self.suite.tests], ['n0'])
        assert_equal(list(self.suite.suites), [])

    def test_include_by_names(self):
        self.suite.visit(SuiteConfigurer(include_suites=['s?b', 'xxx'],
                                         include_tests=['', '*1', 'xxx']))
        assert_equal(list(self.suite.tests), [])
        assert_equal([t.name for t in self.suite.suites[0].tests], ['n1'])

    def test_no_matching_tests_with_one_selector_each(self):
        configurer = SuiteConfigurer(include_tags='i', exclude_tags='e',
                                     include_suites='s', include_tests='t')
        assert_raises_with_msg(DataError,
                               "Suite 'root' contains no tests with tag 'i', "
                               "without tag 'e' and named 't' in suite 's'.",
                               self.suite.visit, configurer)

    def test_no_matching_tests_with_multiple_selectors(self):
        configurer = SuiteConfigurer(include_tags=['i1', 'i2'],
                                     exclude_tags=['e1', 'e2'],
                                     include_suites=['s1', 's2', 's3'],
                                     include_tests=['t1', 't2'])
        assert_raises_with_msg(DataError,
                               "Suite 'root' contains no tests "
                               "with tags 'i1' or 'i2', "
                               "without tags 'e1' or 'e2' and "
                               "named 't1' or 't2' "
                               "in suites 's1', 's2' or 's3'.",
                               self.suite.visit, configurer)

    def test_empty_suite(self):
        suite = TestSuite(name='x')
        suite.visit(SuiteConfigurer(empty_suite_ok=True))
        assert_raises_with_msg(DataError,
                               "Suite 'x' contains no tests.",
                               suite.visit, SuiteConfigurer())
Exemplo n.º 7
0
class TestSuiteAttributes(unittest.TestCase):
    def setUp(self):
        self.suite = TestSuite(name='Suite', metadata={'A A': '1', 'bb': '1'})
        self.suite.tests.create(name='Make suite non-empty')

    def test_name_and_doc(self):
        self.suite.visit(SuiteConfigurer(name='New Name', doc='New Doc'))
        assert_equal(self.suite.name, 'New Name')
        assert_equal(self.suite.doc, 'New Doc')

    def test_metadata(self):
        self.suite.visit(SuiteConfigurer(metadata={'bb': '2', 'C': '2'}))
        assert_equal(self.suite.metadata, {'A A': '1', 'bb': '2', 'C': '2'})

    def test_metadata_is_normalized(self):
        self.suite.visit(SuiteConfigurer(metadata={'aa': '2', 'B_B': '2'}))
        assert_equal(self.suite.metadata, {'A A': '2', 'bb': '2'})
class TestSuiteAttributes(unittest.TestCase):

    def setUp(self):
        self.suite = TestSuite(name='Suite', metadata={'A A': '1', 'bb': '1'})
        self.suite.tests.create(name='Make suite non-empty')

    def test_name_and_doc(self):
        self.suite.visit(SuiteConfigurer(name='New Name', doc='New Doc'))
        assert_equal(self.suite.name, 'New Name')
        assert_equal(self.suite.doc, 'New Doc')

    def test_metadata(self):
        self.suite.visit(SuiteConfigurer(metadata={'bb': '2', 'C': '2'}))
        assert_equal(self.suite.metadata, {'A A': '1', 'bb': '2', 'C': '2'})

    def test_metadata_is_normalized(self):
        self.suite.visit(SuiteConfigurer(metadata={'aa': '2', 'B_B': '2'}))
        assert_equal(self.suite.metadata, {'A A': '2', 'bb': '2'})
Exemplo n.º 9
0
 def test_empty_suite(self):
     suite = TestSuite(name='x')
     suite.visit(SuiteConfigurer(empty_suite_ok=True))
     assert_raises_with_msg(DataError, "Suite 'x' contains no tests.",
                            suite.visit, SuiteConfigurer())
 def test_empty_suite(self):
     suite = TestSuite(name='x')
     suite.visit(SuiteConfigurer(empty_suite_ok=True))
     assert_raises_with_msg(DataError,
                            "Suite 'x' contains no tests.",
                            suite.visit, SuiteConfigurer())