Here are the examples of the python api twisted.trial.reporter.TestResult taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
38 Examples
3
Example 1
Project: filesync-server Source File: test_capabilities.py
def test_mismatch(self):
"""test tha a test is correctly skipped"""
result = TestResult()
syncdaemon.REQUIRED_CAPS = set(['supercalifragilistico'])
class FakeTest(TestCase):
"""Testcase to test the decorator"""
@required_caps([], validate=False)
def test_method(innerself):
"""test method that allways fails"""
innerself.fail()
FakeTest('test_method').run(result)
self.assertEquals(1, len(result.skips))
3
Example 2
Project: filesync-server Source File: test_capabilities.py
def test_match(self):
"""Check that a test is executed when the caps match."""
result = TestResult()
syncdaemon.REQUIRED_CAPS = server_module.MIN_CAP
class FakeTest(TestCase):
"""Testcase to test the decorator"""
@required_caps(server_module.MIN_CAP)
def test_method(innerself):
"""Test method that always pass."""
innerself.assertTrue(True)
FakeTest('test_method').run(result)
self.assertEquals(0, len(result.skips))
self.assertEquals(1, result.successes)
3
Example 3
Project: filesync-server Source File: test_capabilities.py
def test_not_validate(self):
"""test that a test is executed when the supported_caps_set don't match
the server SUPPORTED_CAPS and validate=False.
"""
result = TestResult()
syncdaemon.REQUIRED_CAPS = set(['supercalifragilistico'])
class FakeTest(TestCase):
"""Testcase to test the decorator"""
@required_caps(['supercalifragilistico'], validate=False)
def test_method(innerself):
"""test method that always pass"""
innerself.assertTrue(True)
FakeTest('test_method').run(result)
self.assertEquals(0, len(result.skips))
self.assertEquals(1, result.successes)
3
Example 4
def test_validate(self):
"""test tha a test fails when the supported_caps_set don't match
the server SUPPORTED_CAPS and validate=True.
"""
result = TestResult()
class FakeTest(TestCase):
"""Testcase to test the decorator"""
@required_caps([], ['supercalifragilistico', 'foo'], ['foo'])
def test_method(innerself):
"""test method that always pass"""
innerself.assertTrue(True)
the_test = FakeTest('test_method')
the_test.run(result)
self.assertEquals(0, len(result.skips))
self.assertEquals(1, len(result.failures))
self.assertEquals(the_test, result.failures[0][0])
3
Example 5
def test_failingException_fails(self):
test = runner.TestLoader().loadClass(TestAssertions.FailingTest)
result = reporter.TestResult()
test.run(result)
self.failIf(result.wasSuccessful())
self.failUnlessEqual(result.errors, [])
self.failUnlessEqual(len(result.failures), 1)
3
Example 6
Project: mythbox Source File: test_assertions.py
def test_assertFailure_masked(self):
"""
A single wrong assertFailure should fail the whole test.
"""
class ExampleFailure(Exception):
pass
class TC(unittest.TestCase):
failureException = ExampleFailure
def test_assertFailure(self):
d = defer.maybeDeferred(lambda: 1/0)
self.assertFailure(d, OverflowError)
self.assertFailure(d, ZeroDivisionError)
return d
test = TC('test_assertFailure')
result = reporter.TestResult()
test.run(result)
self.assertEqual(1, len(result.failures))
3
Example 7
def test_classTimeout(self):
loader = runner.TestLoader()
suite = loader.loadClass(detests.TestClassTimeoutAttribute)
result = reporter.TestResult()
suite.run(result)
self.failUnlessEqual(len(result.errors), 1)
self._wasTimeout(result.errors[0][1])
3
Example 8
def _testRun(self, suite):
"""
Run C{suite} and check the result.
"""
result = reporter.TestResult()
suite.run(result)
self.assertEqual(5, result.successes)
# doctest reports failures as errors in 2.3
self.assertEqual(2, len(result.errors) + len(result.failures))
3
Example 9
def test_loadFailingMethod(self):
# test added for issue1353
import erroneous
suite = self.loader.loadMethod(erroneous.TestRegularFail.test_fail)
result = reporter.TestResult()
suite.run(result)
self.failUnlessEqual(result.testsRun, 1)
self.failUnlessEqual(len(result.failures), 1)
3
Example 10
Project: mythbox Source File: test_runner.py
def test_capturesError(self):
"""
Chek that a L{LoggedSuite} reports any logged errors to its result.
"""
result = reporter.TestResult()
suite = runner.LoggedSuite([BreakingSuite()])
suite.run(result)
self.assertEqual(len(result.errors), 1)
self.assertEqual(result.errors[0][0].id(), runner.NOT_IN_TEST)
self.failUnless(result.errors[0][1].check(RuntimeError))
3
Example 11
Project: mythbox Source File: test_runner.py
def test_basic(self):
"""
Thes destructive test suite should run the tests normally.
"""
called = []
class MockTest(unittest.TestCase):
def test_foo(test):
called.append(True)
test = MockTest('test_foo')
result = reporter.TestResult()
suite = runner.DestructiveTestSuite([test])
self.assertEquals(called, [])
suite.run(result)
self.assertEquals(called, [True])
self.assertEquals(suite.countTestCases(), 0)
3
Example 12
Project: mythbox Source File: test_runner.py
def test_cleanup(self):
"""
Checks that the test suite cleanups its tests during the run, so that
it ends empty.
"""
class MockTest(unittest.TestCase):
def test_foo(test):
pass
test = MockTest('test_foo')
result = reporter.TestResult()
suite = runner.DestructiveTestSuite([test])
self.assertEquals(suite.countTestCases(), 1)
suite.run(result)
self.assertEquals(suite.countTestCases(), 0)
3
Example 13
def test_collectNotDefault(self):
"""
By default, tests should not force garbage collection.
"""
test = self.BasicTest('test_foo')
result = reporter.TestResult()
test.run(result)
self.failUnlessEqual(self._collectCalled, ['setUp', 'test', 'tearDown'])
3
Example 14
Project: mythbox Source File: test_tests.py
def test_collectCalled(self):
"""
test gc.collect is called before and after each test.
"""
test = TestGarbageCollection.BasicTest('test_foo')
test = unittest._ForceGarbageCollectionDecorator(test)
result = reporter.TestResult()
test.run(result)
self.failUnlessEqual(
self._collectCalled,
['collect', 'setUp', 'test', 'tearDown', 'collect'])
3
Example 15
Project: mythbox Source File: test_tests.py
def test_isReported(self):
"""
Forcing garbage collection should cause unhandled Deferreds to be
reported as errors.
"""
result = reporter.TestResult()
self.test1(result)
self.assertEqual(len(result.errors), 1,
'Unhandled deferred passed without notice')
3
Example 16
Project: mythbox Source File: test_tests.py
def test_doesntBleed(self):
"""
Forcing garbage collection in the test should mean that there are
no unreachable cycles immediately after the test completes.
"""
result = reporter.TestResult()
self.test1(result)
self.flushLoggedErrors() # test1 logs errors that get caught be us.
# test1 created unreachable cycle.
# it & all others should have been collected by now.
n = gc.collect()
self.assertEqual(n, 0, 'unreachable cycle still existed')
# check that last gc.collect didn't log more errors
x = self.flushLoggedErrors()
self.assertEqual(len(x), 0, 'Errors logged after gc.collect')
3
Example 17
Project: mythbox Source File: test_warning.py
def test_flushed(self):
"""
Any warnings emitted by a test which are flushed are not emitted to the
Python warning system.
"""
result = TestResult()
case = Mask.MockTests('test_flushed')
output = StringIO()
monkey = self.patch(sys, 'stdout', output)
case.run(result)
monkey.restore()
self.assertEqual(output.getvalue(), "")
3
Example 18
def test_classTimeout(self):
loader = runner.TestLoader()
suite = loader.loadClass(detests.TestClassTimeoutAttribute)
result = reporter.TestResult()
suite.run(result)
self.assertEqual(len(result.errors), 1)
self._wasTimeout(result.errors[0][1])
3
Example 19
def test_loadFailingMethod(self):
# test added for issue1353
import erroneous
suite = self.loader.loadMethod(erroneous.TestRegularFail.test_fail)
result = reporter.TestResult()
suite.run(result)
self.assertEqual(result.testsRun, 1)
self.assertEqual(len(result.failures), 1)
3
Example 20
Project: SubliminalCollaborator Source File: test_runner.py
def test_basic(self):
"""
Thes destructive test suite should run the tests normally.
"""
called = []
class MockTest(unittest.TestCase):
def test_foo(test):
called.append(True)
test = MockTest('test_foo')
result = reporter.TestResult()
suite = runner.DestructiveTestSuite([test])
self.assertEqual(called, [])
suite.run(result)
self.assertEqual(called, [True])
self.assertEqual(suite.countTestCases(), 0)
3
Example 21
Project: SubliminalCollaborator Source File: test_runner.py
def test_cleanup(self):
"""
Checks that the test suite cleanups its tests during the run, so that
it ends empty.
"""
class MockTest(unittest.TestCase):
def test_foo(test):
pass
test = MockTest('test_foo')
result = reporter.TestResult()
suite = runner.DestructiveTestSuite([test])
self.assertEqual(suite.countTestCases(), 1)
suite.run(result)
self.assertEqual(suite.countTestCases(), 0)
3
Example 22
Project: SubliminalCollaborator Source File: test_tests.py
def loadSuite(self, suite):
"""
Load tests from the given test case class and create a new reporter to
use for running it.
"""
self.loader = runner.TestLoader()
self.suite = self.loader.loadClass(suite)
self.reporter = reporter.TestResult()
3
Example 23
def test_collectNotDefault(self):
"""
By default, tests should not force garbage collection.
"""
test = self.BasicTest('test_foo')
result = reporter.TestResult()
test.run(result)
self.assertEqual(self._collectCalled, ['setUp', 'test', 'tearDown'])
3
Example 24
Project: SubliminalCollaborator Source File: test_tests.py
def test_collectCalled(self):
"""
test gc.collect is called before and after each test.
"""
test = TestGarbageCollection.BasicTest('test_foo')
test = unittest._ForceGarbageCollectionDecorator(test)
result = reporter.TestResult()
test.run(result)
self.assertEqual(
self._collectCalled,
['collect', 'setUp', 'test', 'tearDown', 'collect'])
0
Example 25
def _loadSuite(self, klass):
loader = runner.TestLoader()
r = reporter.TestResult()
s = loader.loadClass(klass)
return r, s
0
Example 26
def runTest(self, name):
result = reporter.TestResult()
self.getTest(name).run(result)
return result
0
Example 27
def setUp(self):
self.output = StringIO.StringIO()
self.reporter = reporter.TestResult()
self.loader = runner.TestLoader()
0
Example 28
def setUp(self):
self.result = reporter.TestResult()
self.observer = unittest._LogObserver()
0
Example 29
def setUp(self):
self.result = reporter.TestResult()
0
Example 30
Project: mythbox Source File: test_runner.py
def test_shouldStop(self):
"""
Test the C{shouldStop} management: raising a C{KeyboardInterrupt} must
interrupt the suite.
"""
called = []
class MockTest(unittest.TestCase):
def test_foo1(test):
called.append(1)
def test_foo2(test):
raise KeyboardInterrupt()
def test_foo3(test):
called.append(2)
result = reporter.TestResult()
loader = runner.TestLoader()
loader.suiteFactory = runner.DestructiveTestSuite
suite = loader.loadClass(MockTest)
self.assertEquals(called, [])
suite.run(result)
self.assertEquals(called, [1])
# The last test shouldn't have been run
self.assertEquals(suite.countTestCases(), 1)
0
Example 31
def loadSuite(self, suite):
self.loader = runner.TestLoader()
self.suite = self.loader.loadClass(suite)
self.reporter = reporter.TestResult()
0
Example 32
def runTests(self, suite):
suite.run(reporter.TestResult())
0
Example 33
def setUp(self):
unittest.TestCase.setUp(self)
self.result = reporter.TestResult()
self.test = TestAddCleanup.MockTest()
0
Example 34
Project: mythbox Source File: test_warning.py
def test_unflushed(self):
"""
Any warnings emitted by a test which are not flushed are emitted to the
Python warning system.
"""
result = TestResult()
case = Mask.MockTests('test_unflushed')
case.run(result)
warningsShown = self.flushWarnings([Mask.MockTests.test_unflushed])
self.assertEqual(warningsShown[0]['message'], 'some warning text')
self.assertIdentical(warningsShown[0]['category'], UserWarning)
where = case.test_unflushed.im_func.func_code
filename = where.co_filename
# If someone edits MockTests.test_unflushed, the value added to
# firstlineno might need to change.
lineno = where.co_firstlineno + 4
self.assertEqual(warningsShown[0]['filename'], filename)
self.assertEqual(warningsShown[0]['lineno'], lineno)
self.assertEqual(len(warningsShown), 1)
0
Example 35
Project: mythbox Source File: test_warning.py
def test_warningsConfiguredAsErrors(self):
"""
If a warnings filter has been installed which turns warnings into
exceptions, tests have an error added to the reporter for them for each
unflushed warning.
"""
class CustomWarning(Warning):
pass
result = TestResult()
case = Mask.MockTests('test_unflushed')
case.category = CustomWarning
originalWarnings = warnings.filters[:]
try:
warnings.simplefilter('error')
case.run(result)
self.assertEqual(len(result.errors), 1)
self.assertIdentical(result.errors[0][0], case)
result.errors[0][1].trap(CustomWarning)
finally:
warnings.filters[:] = originalWarnings
0
Example 36
Project: mythbox Source File: test_warning.py
def test_flushedWarningsConfiguredAsErrors(self):
"""
If a warnings filter has been installed which turns warnings into
exceptions, tests which emit those warnings but flush them do not have
an error added to the reporter.
"""
class CustomWarning(Warning):
pass
result = TestResult()
case = Mask.MockTests('test_flushed')
case.category = CustomWarning
originalWarnings = warnings.filters[:]
try:
warnings.simplefilter('error')
case.run(result)
self.assertEqual(result.errors, [])
finally:
warnings.filters[:] = originalWarnings
0
Example 37
Project: SubliminalCollaborator Source File: test_runner.py
def test_shouldStop(self):
"""
Test the C{shouldStop} management: raising a C{KeyboardInterrupt} must
interrupt the suite.
"""
called = []
class MockTest(unittest.TestCase):
def test_foo1(test):
called.append(1)
def test_foo2(test):
raise KeyboardInterrupt()
def test_foo3(test):
called.append(2)
result = reporter.TestResult()
loader = runner.TestLoader()
loader.suiteFactory = runner.DestructiveTestSuite
suite = loader.loadClass(MockTest)
self.assertEqual(called, [])
suite.run(result)
self.assertEqual(called, [1])
# The last test shouldn't have been run
self.assertEqual(suite.countTestCases(), 1)
0
Example 38
def setUp(self):
super(AddCleanupMixin, self).setUp()
self.result = reporter.TestResult()
self.test = self.AddCleanup()