Ejemplo n.º 1
0
Archivo: run.py Proyecto: endisd/samba
 def run(self, test):
     "Run the given test case or test suite."
     result = TextTestResult(sys.stdout)
     result.startTestRun()
     try:
         return test.run(result)
     finally:
         result.stopTestRun()
Ejemplo n.º 2
0
 def _run(self, stream, test):
     """Run the test, the same as in testtools.run but not to stdout"""
     result = TextTestResult(stream)
     result.startTestRun()
     try:
         return test.run(result)
     finally:
         result.stopTestRun()
 def run(self, test):
     "Run the given test case or test suite."
     result = TextTestResult(unicode_output_stream(self.stdout))
     result.startTestRun()
     try:
         return test.run(result)
     finally:
         result.stopTestRun()
Ejemplo n.º 4
0
def main(argv, prepare_args=prepare_argv, find_tests=find_tests):
    """CLI entry point to adapt a test run to parallel testing."""
    child_args = prepare_argv(argv)
    test_ids = find_tests(argv)

    # We could create a proxy object per test id if desired in future)
    def parallelise_tests(suite):
        test_ids = list(suite)[0]._test_ids
        count = concurrency()
        partitions = partition_tests(test_ids, count)
        return [
            ListTestCase(partition, child_args) for partition in partitions
        ]

    suite = ConcurrentTestSuite(ListTestCase(test_ids, None),
                                parallelise_tests)
    if '--subunit' in argv:
        runner = SubunitTestRunner(sys.stdout)
        result = runner.run(suite)
    else:
        stream = unicode_output_stream(sys.stdout)
        result = TextTestResult(stream)
        result.startTestRun()
        try:
            suite.run(result)
        finally:
            result.stopTestRun()
    if result.wasSuccessful():
        return 0
    return -1
Ejemplo n.º 5
0
def main(argv, prepare_args=prepare_argv, find_tests=find_tests):
    """CLI entry point to adapt a test run to parallel testing."""
    child_args = prepare_argv(argv)
    test_ids = find_tests(argv)
    # We could create a proxy object per test id if desired in future)
    def parallelise_tests(suite):
        test_ids = list(suite)[0]._test_ids
        count = concurrency()
        partitions = partition_tests(test_ids, count)
        return [ListTestCase(partition, child_args) for partition in partitions]
    suite = ConcurrentTestSuite(ListTestCase(test_ids, None), parallelise_tests)
    if '--subunit' in argv:
        runner = SubunitTestRunner(sys.stdout)
        result = runner.run(suite)
    else:
        stream = unicode_output_stream(sys.stdout)
        result = TextTestResult(stream)
        result.startTestRun()
        try:
            suite.run(result)
        finally:
            result.stopTestRun()
    if result.wasSuccessful():
        return 0
    return -1
Ejemplo n.º 6
0
 def run(self, test):
     "Run the given test case or test suite."
     result = TextTestResult(unicode_output_stream(self.stdout))
     result.startTestRun()
     try:
         return test.run(result)
     finally:
         result.stopTestRun()
Ejemplo n.º 7
0
 def _run(self, stream, test):
     """Run the test, the same as in testtools.run but not to stdout"""
     result = TextTestResult(stream)
     result.startTestRun()
     try:
         return test.run(result)
     finally:
         result.stopTestRun()
Ejemplo n.º 8
0
 def setUp(self):
     super(TestTextTestResult, self).setUp()
     self.result = TextTestResult(StringIO())
Ejemplo n.º 9
0
class TestTextTestResult(TestCase):
    """Tests for `TextTestResult`."""

    def setUp(self):
        super(TestTextTestResult, self).setUp()
        self.result = TextTestResult(StringIO())

    def make_erroring_test(self):
        class Test(TestCase):
            def error(self):
                1/0
        return Test("error")

    def make_failing_test(self):
        class Test(TestCase):
            def failed(self):
                self.fail("yo!")
        return Test("failed")

    def make_unexpectedly_successful_test(self):
        class Test(TestCase):
            def succeeded(self):
                self.expectFailure("yo!", lambda: None)
        return Test("succeeded")

    def make_test(self):
        class Test(TestCase):
            def test(self):
                pass
        return Test("test")

    def getvalue(self):
        return self.result.stream.getvalue()

    def test__init_sets_stream(self):
        result = TextTestResult("fp")
        self.assertEqual("fp", result.stream)

    def reset_output(self):
        self.result.stream = StringIO()

    def test_startTestRun(self):
        self.result.startTestRun()
        self.assertEqual("Tests running...\n", self.getvalue())

    def test_stopTestRun_count_many(self):
        test = self.make_test()
        self.result.startTestRun()
        self.result.startTest(test)
        self.result.stopTest(test)
        self.result.startTest(test)
        self.result.stopTest(test)
        self.result.stream = StringIO()
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("Ran 2 tests in ...s\n...", doctest.ELLIPSIS))

    def test_stopTestRun_count_single(self):
        test = self.make_test()
        self.result.startTestRun()
        self.result.startTest(test)
        self.result.stopTest(test)
        self.reset_output()
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("Ran 1 test in ...s\n\nOK\n", doctest.ELLIPSIS))

    def test_stopTestRun_count_zero(self):
        self.result.startTestRun()
        self.reset_output()
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("Ran 0 tests in ...s\n\nOK\n", doctest.ELLIPSIS))

    def test_stopTestRun_current_time(self):
        test = self.make_test()
        now = datetime.datetime.now(utc)
        self.result.time(now)
        self.result.startTestRun()
        self.result.startTest(test)
        now = now + datetime.timedelta(0, 0, 0, 1)
        self.result.time(now)
        self.result.stopTest(test)
        self.reset_output()
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("... in 0.001s\n...", doctest.ELLIPSIS))

    def test_stopTestRun_successful(self):
        self.result.startTestRun()
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("...\n\nOK\n", doctest.ELLIPSIS))

    def test_stopTestRun_not_successful_failure(self):
        test = self.make_failing_test()
        self.result.startTestRun()
        test.run(self.result)
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("...\n\nFAILED (failures=1)\n", doctest.ELLIPSIS))

    def test_stopTestRun_not_successful_error(self):
        test = self.make_erroring_test()
        self.result.startTestRun()
        test.run(self.result)
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("...\n\nFAILED (failures=1)\n", doctest.ELLIPSIS))

    def test_stopTestRun_not_successful_unexpected_success(self):
        test = self.make_unexpectedly_successful_test()
        self.result.startTestRun()
        test.run(self.result)
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("...\n\nFAILED (failures=1)\n", doctest.ELLIPSIS))

    def test_stopTestRun_shows_details(self):
        self.result.startTestRun()
        self.make_erroring_test().run(self.result)
        self.make_unexpectedly_successful_test().run(self.result)
        self.make_failing_test().run(self.result)
        self.reset_output()
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("""...======================================================================
ERROR: testtools.tests.test_testresult.Test.error
----------------------------------------------------------------------
Text attachment: traceback
------------
Traceback (most recent call last):
  File "...testtools...runtest.py", line ..., in _run_user...
    return fn(*args, **kwargs)
  File "...testtools...testcase.py", line ..., in _run_test_method
    return self._get_test_method()()
  File "...testtools...tests...test_testresult.py", line ..., in error
    1/0
ZeroDivisionError:... divi... by zero...
------------
======================================================================
FAIL: testtools.tests.test_testresult.Test.failed
----------------------------------------------------------------------
Text attachment: traceback
------------
Traceback (most recent call last):
  File "...testtools...runtest.py", line ..., in _run_user...
    return fn(*args, **kwargs)
  File "...testtools...testcase.py", line ..., in _run_test_method
    return self._get_test_method()()
  File "...testtools...tests...test_testresult.py", line ..., in failed
    self.fail("yo!")
AssertionError: yo!
------------
======================================================================
UNEXPECTED SUCCESS: testtools.tests.test_testresult.Test.succeeded
----------------------------------------------------------------------
...""", doctest.ELLIPSIS | doctest.REPORT_NDIFF))
Ejemplo n.º 10
0
 def test__init_sets_stream(self):
     result = TextTestResult("fp")
     self.assertEqual("fp", result.stream)
Ejemplo n.º 11
0
 def setUp(self):
     super(TestTextTestResult, self).setUp()
     self.result = TextTestResult(StringIO())
Ejemplo n.º 12
0
class TestTextTestResult(TestCase):
    """Tests for 'TextTestResult'."""

    def setUp(self):
        super(TestTextTestResult, self).setUp()
        self.result = TextTestResult(StringIO())

    def make_erroring_test(self):
        class Test(TestCase):
            def error(self):
                1/0
        return Test("error")

    def make_failing_test(self):
        class Test(TestCase):
            def failed(self):
                self.fail("yo!")
        return Test("failed")

    def make_unexpectedly_successful_test(self):
        class Test(TestCase):
            def succeeded(self):
                self.expectFailure("yo!", lambda: None)
        return Test("succeeded")

    def make_test(self):
        class Test(TestCase):
            def test(self):
                pass
        return Test("test")

    def getvalue(self):
        return self.result.stream.getvalue()

    def test__init_sets_stream(self):
        result = TextTestResult("fp")
        self.assertEqual("fp", result.stream)

    def reset_output(self):
        self.result.stream = StringIO()

    def test_startTestRun(self):
        self.result.startTestRun()
        self.assertEqual("Tests running...\n", self.getvalue())

    def test_stopTestRun_count_many(self):
        test = self.make_test()
        self.result.startTestRun()
        self.result.startTest(test)
        self.result.stopTest(test)
        self.result.startTest(test)
        self.result.stopTest(test)
        self.result.stream = StringIO()
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("Ran 2 tests in ...s\n...", doctest.ELLIPSIS))

    def test_stopTestRun_count_single(self):
        test = self.make_test()
        self.result.startTestRun()
        self.result.startTest(test)
        self.result.stopTest(test)
        self.reset_output()
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("Ran 1 test in ...s\n\nOK\n", doctest.ELLIPSIS))

    def test_stopTestRun_count_zero(self):
        self.result.startTestRun()
        self.reset_output()
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("Ran 0 tests in ...s\n\nOK\n", doctest.ELLIPSIS))

    def test_stopTestRun_current_time(self):
        test = self.make_test()
        now = datetime.datetime.now(utc)
        self.result.time(now)
        self.result.startTestRun()
        self.result.startTest(test)
        now = now + datetime.timedelta(0, 0, 0, 1)
        self.result.time(now)
        self.result.stopTest(test)
        self.reset_output()
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("... in 0.001s\n...", doctest.ELLIPSIS))

    def test_stopTestRun_successful(self):
        self.result.startTestRun()
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("...\n\nOK\n", doctest.ELLIPSIS))

    def test_stopTestRun_not_successful_failure(self):
        test = self.make_failing_test()
        self.result.startTestRun()
        test.run(self.result)
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("...\n\nFAILED (failures=1)\n", doctest.ELLIPSIS))

    def test_stopTestRun_not_successful_error(self):
        test = self.make_erroring_test()
        self.result.startTestRun()
        test.run(self.result)
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("...\n\nFAILED (failures=1)\n", doctest.ELLIPSIS))

    def test_stopTestRun_not_successful_unexpected_success(self):
        test = self.make_unexpectedly_successful_test()
        self.result.startTestRun()
        test.run(self.result)
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("...\n\nFAILED (failures=1)\n", doctest.ELLIPSIS))

    def test_stopTestRun_shows_details(self):
        self.result.startTestRun()
        self.make_erroring_test().run(self.result)
        self.make_unexpectedly_successful_test().run(self.result)
        self.make_failing_test().run(self.result)
        self.reset_output()
        self.result.stopTestRun()
        self.assertThat(self.getvalue(),
            DocTestMatches("""...======================================================================
ERROR: testtools.tests.test_testresult.Test.error
----------------------------------------------------------------------
Text attachment: traceback
------------
Traceback (most recent call last):
  File "...testtools...runtest.py", line ..., in _run_user...
    return fn(*args, **kwargs)
  File "...testtools...testcase.py", line ..., in _run_test_method
    return self._get_test_method()()
  File "...testtools...tests...test_testresult.py", line ..., in error
    1/0
ZeroDivisionError:... divi... by zero...
------------
======================================================================
FAIL: testtools.tests.test_testresult.Test.failed
----------------------------------------------------------------------
Text attachment: traceback
------------
Traceback (most recent call last):
  File "...testtools...runtest.py", line ..., in _run_user...
    return fn(*args, **kwargs)
  File "...testtools...testcase.py", line ..., in _run_test_method
    return self._get_test_method()()
  File "...testtools...tests...test_testresult.py", line ..., in failed
    self.fail("yo!")
AssertionError: yo!
------------
======================================================================
UNEXPECTED SUCCESS: testtools.tests.test_testresult.Test.succeeded
----------------------------------------------------------------------
...""", doctest.ELLIPSIS | doctest.REPORT_NDIFF))
Ejemplo n.º 13
0
 def makeResult(self):
     return TextTestResult(StringIO())
Ejemplo n.º 14
0
def _construct_text(**kwargs):
    stream = kwargs.pop('stream')
    failfast = kwargs.pop('failfast')
    _raise_on_unknown_kwargs(kwargs)
    return LoggedTestResultDecorator(TextTestResult(stream, failfast))