Пример #1
0
    def test_broken_runner(self):
        # If the object called breaks, the stream is informed about it
        # regardless.
        class BrokenTest(object):
            # broken - no result parameter!
            def __call__(self):
                pass
            def run(self):
                pass
        result = LoggingStream()
        cases = lambda:[(BrokenTest(), '0')]
        suite = ConcurrentStreamTestSuite(cases)
        suite.run(result)
        events = result._events
        # Check the traceback loosely.
        self.assertThat(events[1][6].decode('utf8'), DocTestMatches("""\
Traceback (most recent call last):
  File "...testtools/testsuite.py", line ..., in _run_test
    test.run(process_result)
TypeError: run() takes ...1 ...argument...2...given...
""", doctest.ELLIPSIS))
        events = [event[0:10] + (None,) for event in events]
        events[1] = events[1][:6] + (None,) + events[1][7:]
        self.assertEqual([
            ('status', "broken-runner-'0'", 'inprogress', None, True, None, None, False, None, _u('0'), None),
            ('status', "broken-runner-'0'", None, None, True, 'traceback', None,
             False,
             'text/x-traceback; charset="utf8"; language="python"',
             '0',
             None),
             ('status', "broken-runner-'0'", None, None, True, 'traceback', b'', True,
              'text/x-traceback; charset="utf8"; language="python"', '0', None),
             ('status', "broken-runner-'0'", 'fail', set(), True, None, None, False, None, _u('0'), None)
            ], events)
    def test_broken_runner(self):
        # If the object called breaks, the stream is informed about it
        # regardless.
        class BrokenTest:
            # broken - no result parameter!
            def __call__(self):
                pass

            def run(self):
                pass

        result = LoggingStream()
        cases = lambda: [(BrokenTest(), '0')]
        suite = ConcurrentStreamTestSuite(cases)
        suite.run(result)
        events = result._events
        # Check the traceback loosely.
        self.assertEqual(events[1][6].decode('utf8'),
                         "Traceback (most recent call last):\n")
        self.assertThat(
            events[2][6].decode('utf8'),
            DocTestMatches(
                """\
  File "...testtools/testsuite.py", line ..., in _run_test
    test.run(process_result)
""", doctest.ELLIPSIS))
        self.assertThat(
            events[3][6].decode('utf8'),
            DocTestMatches(
                """\
TypeError: run() takes ...1 ...argument...2...given...
""", doctest.ELLIPSIS))
        events = [event[0:10] + (None, ) for event in events]
        events[1] = events[1][:6] + (None, ) + events[1][7:]
        events[2] = events[2][:6] + (None, ) + events[2][7:]
        events[3] = events[3][:6] + (None, ) + events[3][7:]
        self.assertEqual([
            ('status', "broken-runner-'0'", 'inprogress', None, True, None,
             None, False, None, '0', None),
            ('status', "broken-runner-'0'", None, None, True, 'traceback',
             None, False,
             'text/x-traceback; charset="utf8"; language="python"', '0', None),
            ('status', "broken-runner-'0'", None, None, True, 'traceback',
             None, False,
             'text/x-traceback; charset="utf8"; language="python"', '0', None),
            ('status', "broken-runner-'0'", None, None, True, 'traceback',
             None, True, 'text/x-traceback; charset="utf8"; language="python"',
             '0', None),
            ('status', "broken-runner-'0'", 'fail', set(), True, None, None,
             False, None, '0', None)
        ], events)
Пример #3
0
def main():
    os.environ["PYTHON_API_KEY"] = api_key

    test_suites = _collect_test_suites()
    main_test_suite = TestSuite()

    for test_suite in test_suites:
        main_test_suite.addTests(test_suite)

    concurrent_suite = ConcurrentStreamTestSuite(lambda: ((case, None) for case in main_test_suite))

    result = StreamToDict(callback)
    result.startTestRun()
    try:
        concurrent_suite.run(result)
    finally:
        result.stopTestRun()

    all = SUCCESS + FAILS
    print("All: " + str(all) + " SUCCESS: " + str(SUCCESS) + " FAILS: " + str(FAILS))

    if 'FAILED' in globals() and FAILED:
        sys.exit(1)
Пример #4
0
 def test_trivial(self):
     result = LoggingStream()
     test1 = Sample('test_method1')
     test2 = Sample('test_method2')
     cases = lambda:[(test1, '0'), (test2, '1')]
     suite = ConcurrentStreamTestSuite(cases)
     suite.run(result)
     def freeze(set_or_none):
         if set_or_none is None:
             return set_or_none
         return frozenset(set_or_none)
     # Ignore event order: we're testing the code is all glued together,
     # which just means we can pump events through and they get route codes
     # added appropriately.
     self.assertEqual(set([
         ('status',
          'testtools.tests.test_testsuite.Sample.test_method1',
          'inprogress',
          None,
          True,
          None,
          None,
          False,
          None,
          '0',
          None,
          ),
         ('status',
          'testtools.tests.test_testsuite.Sample.test_method1',
          'success',
          frozenset(),
          True,
          None,
          None,
          False,
          None,
          '0',
          None,
          ),
         ('status',
          'testtools.tests.test_testsuite.Sample.test_method2',
          'inprogress',
          None,
          True,
          None,
          None,
          False,
          None,
          '1',
          None,
          ),
         ('status',
          'testtools.tests.test_testsuite.Sample.test_method2',
          'success',
          frozenset(),
          True,
          None,
          None,
          False,
          None,
          '1',
          None,
          ),
         ]), set(event[0:3] + (freeze(event[3]),) + event[4:10] + (None,)
             for event in result._events))
    def test_trivial(self):
        result = LoggingStream()
        test1 = Sample('test_method1')
        test2 = Sample('test_method2')
        cases = lambda: [(test1, '0'), (test2, '1')]
        suite = ConcurrentStreamTestSuite(cases)
        suite.run(result)

        def freeze(set_or_none):
            if set_or_none is None:
                return set_or_none
            return frozenset(set_or_none)

        # Ignore event order: we're testing the code is all glued together,
        # which just means we can pump events through and they get route codes
        # added appropriately.
        self.assertEqual(
            {
                (
                    'status',
                    'testtools.tests.test_testsuite.Sample.test_method1',
                    'inprogress',
                    None,
                    True,
                    None,
                    None,
                    False,
                    None,
                    '0',
                    None,
                ),
                (
                    'status',
                    'testtools.tests.test_testsuite.Sample.test_method1',
                    'success',
                    frozenset(),
                    True,
                    None,
                    None,
                    False,
                    None,
                    '0',
                    None,
                ),
                (
                    'status',
                    'testtools.tests.test_testsuite.Sample.test_method2',
                    'inprogress',
                    None,
                    True,
                    None,
                    None,
                    False,
                    None,
                    '1',
                    None,
                ),
                (
                    'status',
                    'testtools.tests.test_testsuite.Sample.test_method2',
                    'success',
                    frozenset(),
                    True,
                    None,
                    None,
                    False,
                    None,
                    '1',
                    None,
                ),
            }, {
                event[0:3] + (freeze(event[3]), ) + event[4:10] + (None, )
                for event in result._events
            })