Exemplo n.º 1
0
class TestCriticality(unittest.TestCase):
    def setUp(self):
        self.suite = TestSuite()
        self.sub = self.suite.suites.create()

    def test_default_criticality(self):
        self._verify_criticality(self.suite, [], [])
        self._verify_criticality(self.sub, [], [])

    def test_set_criticality(self):
        self.suite.set_criticality(['c1', 'c2'], 'non')
        self._verify_criticality(self.suite, ['c1', 'c2'], ['non'])
        self._verify_criticality(self.sub, ['c1', 'c2'], ['non'])

    def test_cannot_set_criticality_for_child_suites(self):
        assert_raises(TypeError, self.sub.set_criticality)

    def test_criticality_set_for_child_suites_earlier_is_ignored(self):
        self.suite.set_criticality('use', 'us')
        sub2 = TestSuite()
        sub2.set_criticality('ignore', 'these')
        self.suite.suites.append(sub2)
        self._verify_criticality(self.suite, ['use'], ['us'])
        self._verify_criticality(self.sub, ['use'], ['us'])
        self._verify_criticality(sub2, ['use'], ['us'])

    def _verify_criticality(self, suite, crit, non_crit):
        assert_equal([unicode(t) for t in suite.criticality.critical_tags],
                     crit)
        assert_equal([unicode(t) for t in suite.criticality.non_critical_tags],
                     non_crit)
Exemplo n.º 2
0
 def test_id_with_keyword_parents(self):
     kw = TestSuite().tests.create().keywords.create()
     kw.keywords = [Keyword(), Keyword()]
     kw.keywords[-1].keywords.create()
     assert_equal(kw.keywords[0].id, 's1-t1-k1-k1')
     assert_equal(kw.keywords[1].id, 's1-t1-k1-k2')
     assert_equal(kw.keywords[1].keywords[0].id, 's1-t1-k1-k2-k1')
Exemplo n.º 3
0
class TestCriticality(unittest.TestCase):

    def setUp(self):
        self.suite = TestSuite()
        self.sub = self.suite.suites.create()

    def test_default_criticality(self):
        self._verify_criticality(self.suite, [], [])
        self._verify_criticality(self.sub, [], [])

    def test_set_criticality(self):
        self.suite.set_criticality(['c1', 'c2'], 'non')
        self._verify_criticality(self.suite, ['c1', 'c2'], ['non'])
        self._verify_criticality(self.sub, ['c1', 'c2'], ['non'])

    def test_cannot_set_criticality_for_child_suites(self):
        assert_raises(TypeError, self.sub.set_criticality)

    def test_criticality_set_for_child_suites_earlier_is_ignored(self):
        self.suite.set_criticality('use', 'us')
        sub2 = TestSuite()
        sub2.set_criticality('ignore', 'these')
        self.suite.suites.append(sub2)
        self._verify_criticality(self.suite, ['use'], ['us'])
        self._verify_criticality(self.sub, ['use'], ['us'])
        self._verify_criticality(sub2, ['use'], ['us'])

    def _verify_criticality(self, suite, crit, non_crit):
        assert_equal([unicode(t) for t in suite.criticality.critical_tags], crit)
        assert_equal([unicode(t) for t in suite.criticality.non_critical_tags], non_crit)
Exemplo n.º 4
0
 def test_criticality_set_for_child_suites_earlier_is_ignored(self):
     self.suite.set_criticality('use', 'us')
     sub2 = TestSuite()
     sub2.set_criticality('ignore', 'these')
     self.suite.suites.append(sub2)
     self._verify_criticality(self.suite, ['use'], ['us'])
     self._verify_criticality(self.sub, ['use'], ['us'])
     self._verify_criticality(sub2, ['use'], ['us'])
Exemplo n.º 5
0
 def test_criticality_set_for_child_suites_earlier_is_ignored(self):
     self.suite.set_criticality('use', 'us')
     sub2 = TestSuite()
     sub2.set_criticality('ignore', 'these')
     self.suite.suites.append(sub2)
     self._verify_criticality(self.suite, ['use'], ['us'])
     self._verify_criticality(self.sub, ['use'], ['us'])
     self._verify_criticality(sub2, ['use'], ['us'])
Exemplo n.º 6
0
 def _create_suite(self):
     self.s1 = TestSuite(name='s1')
     self.s21 = self.s1.suites.create(name='s21')
     self.s31 = self.s21.suites.create(name='s31')
     self.s31.tests.create(name='t1', tags=['t1', 's31'])
     self.s31.tests.create(name='t2', tags=['t2', 's31'])
     self.s31.tests.create(name='t3')
     self.s22 = self.s1.suites.create(name='s22')
     self.s22.tests.create(name='t1', tags=['t1', 's22', 'X'])
Exemplo n.º 7
0
 def test_source(self):
     test = TestCase()
     assert_equal(test.source, None)
     suite = TestSuite()
     suite.tests.append(test)
     assert_equal(test.source, None)
     suite.tests.append(test)
     suite.source = '/unit/tests'
     assert_equal(test.source, '/unit/tests')
Exemplo n.º 8
0
 def test_set_tags(self):
     suite = TestSuite()
     suite.tests.create()
     suite.tests.create(tags=['t1', 't2'])
     suite.set_tags(add='a', remove=['t2', 'nonex'])
     suite.tests.create()
     assert_equal(list(suite.tests[0].tags), ['a'])
     assert_equal(list(suite.tests[1].tags), ['a', 't1'])
     assert_equal(list(suite.tests[2].tags), [])
Exemplo n.º 9
0
 def test_set_tags(self):
     suite = TestSuite()
     suite.tests.create()
     suite.tests.create(tags=['t1', 't2'])
     suite.set_tags(add='a', remove=['t2', 'nonex'])
     suite.tests.create()
     assert_equal(list(suite.tests[0].tags), ['a'])
     assert_equal(list(suite.tests[1].tags), ['a', 't1'])
     assert_equal(list(suite.tests[2].tags), [])
Exemplo n.º 10
0
 def test_set_tags(self):
     suite = TestSuite()
     suite.tests.create()
     suite.tests.create(tags=["t1", "t2"])
     suite.set_tags(add="a", remove=["t2", "nonex"])
     suite.tests.create()
     assert_equal(list(suite.tests[0].tags), ["a"])
     assert_equal(list(suite.tests[1].tags), ["a", "t1"])
     assert_equal(list(suite.tests[2].tags), [])
Exemplo n.º 11
0
 def test_keywords_deprecation(self):
     s = TestSuite()
     with warnings.catch_warnings(record=True) as w:
         s.keywords
         assert_true('deprecated' in str(w[0].message))
     try:
         s.keywords = []
         raise AssertionError("Atrribute error not raised.")
     except AttributeError:
         pass
Exemplo n.º 12
0
 def test_suite_name(self):
     suite = TestSuite()
     assert_equal(suite.name, '')
     assert_equal(suite.suites.create(name='foo').name, 'foo')
     assert_equal(suite.suites.create(name='bar').name, 'bar')
     assert_equal(suite.name, 'foo & bar')
     assert_equal(suite.suites.create(name='zap').name, 'zap')
     assert_equal(suite.name, 'foo & bar & zap')
     suite.name = 'new name'
     assert_equal(suite.name, 'new name')
Exemplo n.º 13
0
 def test_suite_name(self):
     suite = TestSuite()
     assert_equal(suite.name, "")
     assert_equal(suite.suites.create(name="foo").name, "foo")
     assert_equal(suite.suites.create(name="bar").name, "bar")
     assert_equal(suite.name, "foo & bar")
     assert_equal(suite.suites.create(name="zap").name, "zap")
     assert_equal(suite.name, "foo & bar & zap")
     suite.name = "new name"
     assert_equal(suite.name, "new name")
Exemplo n.º 14
0
 def test_suite_name(self):
     suite = TestSuite()
     assert_equal(suite.name, '')
     assert_equal(suite.suites.create(name='foo').name, 'foo')
     assert_equal(suite.suites.create(name='bar').name, 'bar')
     assert_equal(suite.name, 'foo & bar')
     assert_equal(suite.suites.create(name='zap').name, 'zap')
     assert_equal(suite.name, 'foo & bar & zap')
     suite.name = 'new name'
     assert_equal(suite.name, 'new name')
Exemplo n.º 15
0
 def test_set_tags_also_to_new_child(self):
     suite = TestSuite()
     suite.tests.create()
     suite.set_tags(add='a', remove=['t2', 'nonex'], persist=True)
     suite.tests.create(tags=['t1', 't2'])
     suite.tests = list(suite.tests)
     suite.tests.create()
     suite.suites.create().tests.create()
     assert_equal(list(suite.tests[0].tags), ['a'])
     assert_equal(list(suite.tests[1].tags), ['a', 't1'])
     assert_equal(list(suite.tests[2].tags), ['a'])
     assert_equal(list(suite.suites[0].tests[0].tags), ['a'])
Exemplo n.º 16
0
 def test_set_tags_also_to_new_child(self):
     suite = TestSuite()
     suite.tests.create()
     suite.set_tags(add="a", remove=["t2", "nonex"], persist=True)
     suite.tests.create(tags=["t1", "t2"])
     suite.tests = list(suite.tests)
     suite.tests.create()
     suite.suites.create().tests.create()
     assert_equal(list(suite.tests[0].tags), ["a"])
     assert_equal(list(suite.tests[1].tags), ["a", "t1"])
     assert_equal(list(suite.tests[2].tags), ["a"])
     assert_equal(list(suite.suites[0].tests[0].tags), ["a"])
Exemplo n.º 17
0
 def test_set_tags_also_to_new_child(self):
     suite = TestSuite()
     suite.tests.create()
     suite.set_tags(add='a', remove=['t2', 'nonex'], persist=True)
     suite.tests.create(tags=['t1', 't2'])
     suite.tests = list(suite.tests)
     suite.tests.create()
     suite.suites.create().tests.create()
     assert_equal(list(suite.tests[0].tags), ['a'])
     assert_equal(list(suite.tests[1].tags), ['a', 't1'])
     assert_equal(list(suite.tests[2].tags), ['a'])
     assert_equal(list(suite.suites[0].tests[0].tags), ['a'])
Exemplo n.º 18
0
 def test_reset_suites(self):
     s1 = TestSuite(name='s1')
     self.suite.suites = [s1]
     s2 = self.suite.suites.create(name='s2')
     assert_true(s1.parent is self.suite)
     assert_true(s2.parent is self.suite)
     assert_equal(list(self.suite.suites), [s1, s2])
Exemplo n.º 19
0
 def test_create_and_add_suite(self):
     s1 = self.suite.suites.create(name='s1')
     s2 = TestSuite(name='s2')
     self.suite.suites.append(s2)
     assert_true(s1.parent is self.suite)
     assert_true(s2.parent is self.suite)
     assert_equal(list(self.suite.suites), [s1, s2])
Exemplo n.º 20
0
 def test_id_with_parent(self):
     suite = TestSuite()
     suite.suites.create().tests = [TestCase(), TestCase()]
     suite.suites.create().tests = [TestCase()]
     assert_equal(suite.suites[0].tests[0].id, 's1-s1-t1')
     assert_equal(suite.suites[0].tests[1].id, 's1-s1-t2')
     assert_equal(suite.suites[1].tests[0].id, 's1-s2-t1')
Exemplo n.º 21
0
class FilterBaseTest(unittest.TestCase):
    def _create_suite(self):
        self.s1 = TestSuite(name='s1')
        self.s21 = self.s1.suites.create(name='s21')
        self.s31 = self.s21.suites.create(name='s31')
        self.s31.tests.create(name='t1', tags=['t1', 's31'])
        self.s31.tests.create(name='t2', tags=['t2', 's31'])
        self.s31.tests.create(name='t3')
        self.s22 = self.s1.suites.create(name='s22')
        self.s22.tests.create(name='t1', tags=['t1', 's22', 'X'])

    def _test(self, filter, s31_tests, s22_tests):
        self._create_suite()
        self.s1.visit(filter)
        assert_equal([t.name for t in self.s31.tests], s31_tests)
        assert_equal([t.name for t in self.s22.tests], s22_tests)
        assert_equal(self.s1.test_count, len(s31_tests + s22_tests))
Exemplo n.º 22
0
class FilterBaseTest(unittest.TestCase):

    def _create_suite(self):
        self.s1 = TestSuite(name='s1')
        self.s21 = self.s1.suites.create(name='s21')
        self.s31 = self.s21.suites.create(name='s31')
        self.s31.tests.create(name='t1', tags=['t1', 's31'])
        self.s31.tests.create(name='t2', tags=['t2', 's31'])
        self.s31.tests.create(name='t3')
        self.s22 = self.s1.suites.create(name='s22')
        self.s22.tests.create(name='t1', tags=['t1', 's22', 'X'])

    def _test(self, filter, s31_tests, s22_tests):
        self._create_suite()
        self.s1.visit(filter)
        assert_equal([t.name for t in self.s31.tests], s31_tests)
        assert_equal([t.name for t in self.s22.tests], s22_tests)
        assert_equal(self.s1.test_count, len(s31_tests + s22_tests))
Exemplo n.º 23
0
 def setUp(self):
     self.suite = suite = TestSuite()
     suite.setup.config(name='SS')
     suite.teardown.config(name='ST')
     test = suite.tests.create()
     test.setup.config(name='TS')
     test.teardown.config(name='TT')
     kw = test.body.create_keyword()
     kw.teardown.config(name='KT')
Exemplo n.º 24
0
 def test_suite_setup_and_teardown_id(self):
     suite = TestSuite()
     assert_equal(suite.setup.id, None)
     assert_equal(suite.teardown.id, None)
     suite.teardown.config(name='T')
     assert_equal(suite.teardown.id, 's1-k1')
     suite.setup.config(name='S')
     assert_equal(suite.setup.id, 's1-k1')
     assert_equal(suite.teardown.id, 's1-k2')
Exemplo n.º 25
0
 def test_test_setup_and_teardown_id(self):
     test = TestSuite().tests.create()
     assert_equal(test.setup.id, None)
     assert_equal(test.teardown.id, None)
     test.setup.config(name='S')
     test.teardown.config(name='T')
     assert_equal(test.setup.id, 's1-t1-k1')
     assert_equal(test.teardown.id, 's1-t1-k2')
     test.body.create_keyword()
     assert_equal(test.setup.id, 's1-t1-k1')
     assert_equal(test.teardown.id, 's1-t1-k3')
Exemplo n.º 26
0
 def test_nested_subsuites(self):
     suite = TestSuite(name='top')
     sub1 = suite.suites.create(name='sub1')
     sub2 = sub1.suites.create(name='sub2')
     assert_equal(list(suite.suites), [sub1])
     assert_equal(list(sub1.suites), [sub2])
Exemplo n.º 27
0
 def setUp(self):
     self.suite = TestSuite()
     self.tests = TestCases(parent=self.suite,
                            tests=[TestCase(name=c) for c in 'abc'])
Exemplo n.º 28
0
 def setUp(self):
     self.empty = TestSuite()
     self.ascii = TestSuite(name='Kekkonen')
     self.non_ascii = TestSuite(name=u'hyv\xe4 nimi')
Exemplo n.º 29
0
 def test_id_with_suite_parent(self):
     assert_equal(TestSuite().keywords.create().id, 's1-k1')
Exemplo n.º 30
0
 def test_longname(self):
     assert_equal(self.test.longname, 'test')
     self.test.parent = TestSuite(name='suite').suites.create(
         name='sub suite')
     assert_equal(self.test.longname, 'suite.sub suite.test')
Exemplo n.º 31
0
 def setUp(self):
     self.suite = TestSuite()
     self.sub = self.suite.suites.create()
Exemplo n.º 32
0
 def test_test_body_id(self):
     kws = [Keyword(), Keyword(), Keyword()]
     TestSuite().tests.create().body.extend(kws)
     assert_equal([k.id for k in kws], ['s1-t1-k1', 's1-t1-k2', 's1-t1-k3'])
Exemplo n.º 33
0
def run_robot_suite(
    kernel: DisplayKernel,
    suite: TestSuite,
    listeners: list,
    silent: bool,
    display_id: str,
    path: str,
    widget: bool = False,
):
    return_values = []
    if not (silent or widget):
        progress = ProgressUpdater(kernel, display_id, sys.__stdout__)
    else:
        progress = None

    # Init status
    listeners = listeners[:]
    if not (silent or widget):
        listeners.append(
            StatusEventListener(lambda data: progress.update(data)), )
    if not silent:
        listeners.append(
            ReturnValueListener(lambda v: return_values.append(v)), )

    stdout = StringIO()
    if progress is not None:
        sys.__stdout__ = progress
    try:
        results = suite.run(
            outputdir=path,
            stdout=stdout,
            listener=listeners,
        )
    finally:
        if progress is not None:
            sys.__stdout__ = progress.stdout

    stats = results.statistics

    # Reply error on error
    if stats.total.critical.failed:
        if not silent:
            kernel.send_error({
                'ename': '',
                'evalue': '',
                'traceback': stdout.getvalue().splitlines(),
            })

    # Display result of the last keyword
    elif (len(return_values) and return_values[-1] is not None
          and return_values[-1] is not '' and return_values[-1] is not b''
          and not silent):  # this comparison is "numpy compatible"
        bundle, metadata = to_mime_and_metadata(return_values[-1])
        if bundle:
            kernel.send_execute_result(bundle, metadata)

    # Process screenshots
    process_screenshots(kernel, path, silent)

    # Generate report
    writer = ResultWriter(os.path.join(path, 'output.xml'))
    writer.write_results(
        log=os.path.join(path, 'log.html'),
        report=os.path.join(path, 'report.html'),
        rpa=getattr(suite, 'rpa', False),
    )

    with open(os.path.join(path, 'log.html'), 'rb') as fp:
        log = fp.read()
        log = log.replace(
            b'"reportURL":"report.html"',
            b'"reportURL":null',
        )

    with open(os.path.join(path, 'report.html'), 'rb') as fp:
        report = fp.read()
        report = report.replace(b'"logURL":"log.html"', b'"logURL":null')

    # Clear status and display results
    if not silent:
        (
            widget and kernel.send_display_data
            or kernel.send_update_display_data
        )(
            {
                'text/html':
                ''
                '<p><a href="{}">Log</a> | <a href="{}">Report</a></p>'.format(
                    javascript_uri(log, 'log.html'),
                    javascript_uri(report, 'report.html'),
                ),
            },
            display_id=display_id,
        )

    # Reply ok on pass
    if stats.total.critical.failed:
        return {
            'status': 'error',
            'ename': '',
            'evalue': '',
            'traceback': stdout.getvalue().splitlines(),
        }
    else:
        return {
            'status': 'ok',
            'execution_count': kernel.execution_count,
        }
Exemplo n.º 34
0
 def test_id_with_suite_parent(self):
     assert_equal(TestSuite().setup.config(name='KW').id, 's1-k1')
Exemplo n.º 35
0
 def test_critical_with_parent(self):
     suite = TestSuite()
     assert_equal(suite.tests.create().critical, True)
     suite.set_criticality(critical_tags=['crit'])
     assert_equal(suite.tests.create().critical, False)
     assert_equal(suite.tests.create(tags=['crit']).critical, True)
Exemplo n.º 36
0
 def test_one_suite(self):
     assert_equal(TestSuite().id, 's1')
Exemplo n.º 37
0
 def test_sub_suites(self):
     parent = TestSuite()
     for i in range(10):
         assert_equal(parent.suites.create().id, 's1-s%s' % (i + 1))
     assert_equal(parent.suites[-1].suites.create().id, 's1-s10-s1')
Exemplo n.º 38
0
 def test_id_is_dynamic(self):
     suite = TestSuite()
     sub = suite.suites.create().suites.create()
     assert_equal(sub.id, 's1-s1-s1')
     suite.suites = [sub]
     assert_equal(sub.id, 's1-s1')
Exemplo n.º 39
0
 def test_id_is_dynamic(self):
     suite = TestSuite()
     sub = suite.suites.create().suites.create()
     assert_equal(sub.id, 's1-s1-s1')
     suite.suites = [sub]
     assert_equal(sub.id, 's1-s1')
Exemplo n.º 40
0
 def setUp(self):
     self.suite = TestSuite(metadata={'M': 'V'})
Exemplo n.º 41
0
 def test_id_with_test_parent(self):
     assert_equal(TestSuite().tests.create().body.create().id, 's1-t1-k1')
Exemplo n.º 42
0
 def setUp(self):
     self.suite = TestSuite()
     self.sub = self.suite.suites.create()