Python twisted.trial.unittest.SynchronousTestCase() Examples
The following are 30
code examples of twisted.trial.unittest.SynchronousTestCase().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
twisted.trial.unittest
, or try the search function
.
Example #1
Source File: test_dns.py From learn_python3_spider with MIT License | 6 votes |
def assertIsNotSubdomainOf(testCase, descendant, ancestor): """ Assert that C{descendant} *is not* a subdomain of C{ancestor}. @type testCase: L{unittest.SynchronousTestCase} @param testCase: The test case on which to run the assertions. @type descendant: C{str} @param descendant: The subdomain name to test. @type ancestor: C{str} @param ancestor: The superdomain name to test. """ testCase.assertFalse( dns._isSubdomainOf(descendant, ancestor), '%r is a subdomain of %r' % (descendant, ancestor))
Example #2
Source File: reactormixins.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def makeTestCaseClasses(cls): """ Create a L{SynchronousTestCase} subclass which mixes in C{cls} for each known reactor and return a dict mapping their names to them. """ classes = {} for reactor in cls._reactors: shortReactorName = reactor.split(".")[-1] name = (cls.__name__ + "." + shortReactorName + "Tests").replace(".", "_") class testcase(cls, SynchronousTestCase): __module__ = cls.__module__ if reactor in cls.skippedReactors: skip = cls.skippedReactors[reactor] try: reactorFactory = namedAny(reactor) except: skip = Failure().getErrorMessage() testcase.__name__ = name if hasattr(cls, "__qualname__"): testcase.__qualname__ = ".".join(cls.__qualname__.split()[0:-1] + [name]) classes[testcase.__name__] = testcase return classes
Example #3
Source File: test_assertions.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_failureResultOfWithWrongFailureMultiExpectedFailure(self): """ L{SynchronousTestCase.failureResultOf} raises L{SynchronousTestCase.failureException} when called with a L{Deferred} with a failure type that was not expected, and the L{SynchronousTestCase.failureException} message contains the original failure traceback as well as the expected failure types in the error message """ try: self.failureResultOf(fail(self.failure), KeyError, IOError) except self.failureException as e: self.assertIn(self.failure.getTraceback(), str(e)) self.assertIn( "Failure of type ({0}.{1} or {2}.{3}) expected on".format( KeyError.__module__, KeyError.__name__, IOError.__module__, IOError.__name__), str(e))
Example #4
Source File: test_dns.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def assertIsSubdomainOf(testCase, descendant, ancestor): """ Assert that C{descendant} *is* a subdomain of C{ancestor}. @type testCase: L{unittest.SynchronousTestCase} @param testCase: The test case on which to run the assertions. @type descendant: C{str} @param descendant: The subdomain name to test. @type ancestor: C{str} @param ancestor: The superdomain name to test. """ testCase.assertTrue( dns._isSubdomainOf(descendant, ancestor), '%r is not a subdomain of %r' % (descendant, ancestor))
Example #5
Source File: test_dns.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def assertIsNotSubdomainOf(testCase, descendant, ancestor): """ Assert that C{descendant} *is not* a subdomain of C{ancestor}. @type testCase: L{unittest.SynchronousTestCase} @param testCase: The test case on which to run the assertions. @type descendant: C{str} @param descendant: The subdomain name to test. @type ancestor: C{str} @param ancestor: The superdomain name to test. """ testCase.assertFalse( dns._isSubdomainOf(descendant, ancestor), '%r is a subdomain of %r' % (descendant, ancestor))
Example #6
Source File: reactormixins.py From learn_python3_spider with MIT License | 6 votes |
def makeTestCaseClasses(cls): """ Create a L{SynchronousTestCase} subclass which mixes in C{cls} for each known reactor and return a dict mapping their names to them. """ classes = {} for reactor in cls._reactors: shortReactorName = reactor.split(".")[-1] name = (cls.__name__ + "." + shortReactorName + "Tests").replace(".", "_") class testcase(cls, SynchronousTestCase): __module__ = cls.__module__ if reactor in cls.skippedReactors: skip = cls.skippedReactors[reactor] try: reactorFactory = namedAny(reactor) except: skip = Failure().getErrorMessage() testcase.__name__ = name if hasattr(cls, "__qualname__"): testcase.__qualname__ = ".".join(cls.__qualname__.split()[0:-1] + [name]) classes[testcase.__name__] = testcase return classes
Example #7
Source File: test_tests.py From learn_python3_spider with MIT License | 6 votes |
def test_tearDownRunsOnTestFailure(self): """ L{SynchronousTestCase.tearDown} runs when a test method fails. """ suite = self.loader.loadTestsFromTestCase( self.TestFailureButTearDownRuns) case = list(suite)[0] self.assertFalse(case.tornDown) suite.run(self.reporter) errors = self.reporter.errors self.assertTrue(len(errors) > 0) self.assertIsInstance(errors[0][1].value, erroneous.FoolishError) self.assertEqual(0, self.reporter.successes) self.assertTrue(case.tornDown)
Example #8
Source File: test_assertions.py From learn_python3_spider with MIT License | 6 votes |
def test_failureResultOfWithWrongFailureOneExpectedFailure(self): """ L{SynchronousTestCase.failureResultOf} raises L{SynchronousTestCase.failureException} when called with a L{Deferred} with a failure type that was not expected, and the L{SynchronousTestCase.failureException} message contains the original failure traceback as well as the expected failure type """ try: self.failureResultOf(fail(self.failure), KeyError) except self.failureException as e: self.assertIn(self.failure.getTraceback(), str(e)) self.assertIn( "Failure of type ({0}.{1}) expected on".format( KeyError.__module__, KeyError.__name__), str(e))
Example #9
Source File: test_assertions.py From learn_python3_spider with MIT License | 6 votes |
def test_failureResultOfWithWrongFailureMultiExpectedFailure(self): """ L{SynchronousTestCase.failureResultOf} raises L{SynchronousTestCase.failureException} when called with a L{Deferred} with a failure type that was not expected, and the L{SynchronousTestCase.failureException} message contains the original failure traceback as well as the expected failure types in the error message """ try: self.failureResultOf(fail(self.failure), KeyError, IOError) except self.failureException as e: self.assertIn(self.failure.getTraceback(), str(e)) self.assertIn( "Failure of type ({0}.{1} or {2}.{3}) expected on".format( KeyError.__module__, KeyError.__name__, IOError.__module__, IOError.__name__), str(e))
Example #10
Source File: test_dns.py From learn_python3_spider with MIT License | 6 votes |
def assertIsSubdomainOf(testCase, descendant, ancestor): """ Assert that C{descendant} *is* a subdomain of C{ancestor}. @type testCase: L{unittest.SynchronousTestCase} @param testCase: The test case on which to run the assertions. @type descendant: C{str} @param descendant: The subdomain name to test. @type ancestor: C{str} @param ancestor: The superdomain name to test. """ testCase.assertTrue( dns._isSubdomainOf(descendant, ancestor), '%r is not a subdomain of %r' % (descendant, ancestor))
Example #11
Source File: test_suppression.py From learn_python3_spider with MIT License | 5 votes |
def test_suppressClass(self): """ A suppression set on a L{SynchronousTestCase} subclass prevents warnings emitted by any test methods defined on that class which match the suppression from being emitted. """ self.runTests( self._load(self.TestSuppression, "testSuppressClass")) warningsShown = self.flushWarnings([ self.TestSuppression._emit]) self.assertEqual( warningsShown[0]['message'], suppression.METHOD_WARNING_MSG) self.assertEqual( warningsShown[1]['message'], suppression.MODULE_WARNING_MSG) self.assertEqual(len(warningsShown), 2)
Example #12
Source File: test_assertions.py From learn_python3_spider with MIT License | 5 votes |
def test_assertNoResultSwallowsImmediateFailure(self): """ When passed a L{Deferred} which currently has a L{Failure} result, L{SynchronousTestCase.assertNoResult} changes the result of the L{Deferred} to a success. """ d = fail(self.failure) try: self.assertNoResult(d) except self.failureException: pass self.assertEqual(None, self.successResultOf(d))
Example #13
Source File: test_assertions.py From learn_python3_spider with MIT License | 5 votes |
def test_assertNoResultPropagatesLaterFailure(self): """ When passed a L{Deferred} with no current result, which is then fired with a L{Failure} result, L{SynchronousTestCase.assertNoResult} doesn't modify the result of the L{Deferred}. """ d = Deferred() self.assertNoResult(d) d.errback(self.failure) self.assertEqual(self.failure, self.failureResultOf(d))
Example #14
Source File: test_assertions.py From learn_python3_spider with MIT License | 5 votes |
def test_withoutSuccessResult(self): """ L{SynchronousTestCase.successResultOf} raises L{SynchronousTestCase.failureException} when called with a L{Deferred} with no current result. """ self.assertRaises( self.failureException, self.successResultOf, Deferred())
Example #15
Source File: test_assertions.py From learn_python3_spider with MIT License | 5 votes |
def test_failUnlessTrue(self): """ L{SynchronousTestCase.failUnless} returns its argument if its argument is considered true. """ self._assertTrueTrue(self.failUnless)
Example #16
Source File: test_assertions.py From learn_python3_spider with MIT License | 5 votes |
def test_failUnlessFalse(self): """ L{SynchronousTestCase.failUnless} raises L{SynchronousTestCase.failureException} if its argument is not considered true. """ self._assertTrueFalse(self.failUnless)
Example #17
Source File: test_assertions.py From learn_python3_spider with MIT License | 5 votes |
def test_assertTrueFalse(self): """ L{SynchronousTestCase.assertTrue} raises L{SynchronousTestCase.failureException} if its argument is not considered true. """ self._assertTrueFalse(self.assertTrue)
Example #18
Source File: test_assertions.py From learn_python3_spider with MIT License | 5 votes |
def test_assertFalseTrue(self): """ L{SynchronousTestCase.assertFalse} raises L{SynchronousTestCase.failureException} if its argument is considered true. """ self._assertFalseTrue(self.assertFalse)
Example #19
Source File: test_assertions.py From learn_python3_spider with MIT License | 5 votes |
def test_failIfTrue(self): """ L{SynchronousTestCase.failIf} raises L{SynchronousTestCase.failureException} if its argument is considered true. """ self._assertFalseTrue(self.failIf)
Example #20
Source File: test_assertions.py From learn_python3_spider with MIT License | 5 votes |
def test_assertFalseFalse(self): """ L{SynchronousTestCase.assertFalse} returns its argument if its argument is not considered true. """ self._assertFalseFalse(self.assertFalse)
Example #21
Source File: test_assertions.py From learn_python3_spider with MIT License | 5 votes |
def test_failingExceptionFails(self): """ When a test method raises L{SynchronousTestCase.failureException}, the test is marked as having failed on the L{TestResult}. """ result = pyunit.TestResult() self.suite.run(result) self.assertFalse(result.wasSuccessful()) self.assertEqual(result.errors, []) self.assertEqual(len(result.failures), 1) self.assertEqual(result.failures[0][0], self.test)
Example #22
Source File: test_assertions.py From learn_python3_spider with MIT License | 5 votes |
def test_fail(self): """ L{SynchronousTestCase.fail} raises L{SynchronousTestCase.failureException} with the given argument. """ try: self.test.fail("failed") except self.test.failureException as result: self.assertEqual("failed", str(result)) else: self.fail( "SynchronousTestCase.fail method did not raise " "SynchronousTestCase.failureException")
Example #23
Source File: test_pyunitcompat.py From learn_python3_spider with MIT License | 5 votes |
def test_pyunitSkip(self): """ Skips using pyunit's skipping functionality are reported as skips in the L{pyunit.TestResult}. """ class SkipTest(SynchronousTestCase): @pyunit.skip("skippy") def test_skip(self): 1/0 test = SkipTest('test_skip') result = pyunit.TestResult() test.run(result) self.assertEqual(result.skipped, [(test, "skippy")])
Example #24
Source File: test_pyunitcompat.py From learn_python3_spider with MIT License | 5 votes |
def test_trialSkip(self): """ Skips using trial's skipping functionality are reported as skips in the L{pyunit.TestResult}. """ class SkipTest(SynchronousTestCase): def test_skip(self): 1/0 test_skip.skip = "Let's skip!" test = SkipTest('test_skip') result = pyunit.TestResult() test.run(result) self.assertEqual(result.skipped, [(test, "Let's skip!")])
Example #25
Source File: test_pyunitcompat.py From learn_python3_spider with MIT License | 5 votes |
def test_traceback(self): """ As test_tracebackFromFailure, but covering more code. """ class ErrorTest(SynchronousTestCase): exc_info = None def test_foo(self): try: 1/0 except ZeroDivisionError: self.exc_info = sys.exc_info() raise test = ErrorTest('test_foo') result = pyunit.TestResult() test.run(result) # We can't test that the tracebacks are equal, because Trial's # machinery inserts a few extra frames on the top and we don't really # want to trim them off without an extremely good reason. # # So, we just test that the result's stack ends with the # exception's stack. expected_stack = ''.join(traceback.format_tb(test.exc_info[2])) observed_stack = '\n'.join(result.errors[0][1].splitlines()[:-1]) self.assertEqual(expected_stack.strip(), observed_stack[-len(expected_stack):].strip())
Example #26
Source File: test_pyunitcompat.py From learn_python3_spider with MIT License | 5 votes |
def test_failure(self): class FailureTest(SynchronousTestCase): ran = False def test_foo(s): s.ran = True s.fail('boom!') test = FailureTest('test_foo') result = pyunit.TestResult() test.run(result) self.assertTrue(test.ran) self.assertEqual(1, result.testsRun) self.assertEqual(1, len(result.failures)) self.assertFalse(result.wasSuccessful())
Example #27
Source File: test_pyunitcompat.py From learn_python3_spider with MIT License | 5 votes |
def test_success(self): class SuccessTest(SynchronousTestCase): ran = False def test_foo(s): s.ran = True test = SuccessTest('test_foo') result = pyunit.TestResult() test.run(result) self.assertTrue(test.ran) self.assertEqual(1, result.testsRun) self.assertTrue(result.wasSuccessful())
Example #28
Source File: test_tests.py From learn_python3_spider with MIT License | 5 votes |
def test_synchronousTestCaseErrorOnGeneratorFunction(self): """ In a SynchronousTestCase, a test method which is a generator function is reported as an error, as such a method will never run assertions. """ class GeneratorSynchronousTestCase(unittest.SynchronousTestCase): """ A fake SynchronousTestCase for testing purposes. """ def test_generator(self): """ A method which is also a generator function, for testing purposes. """ self.fail('this should never be reached') yield testCase = GeneratorSynchronousTestCase('test_generator') result = reporter.TestResult() testCase.run(result) self.assertEqual(len(result.failures), 0) self.assertEqual(len(result.errors), 1) self.assertIn("GeneratorSynchronousTestCase.test_generator", result.errors[0][1].value.args[0]) self.assertIn("GeneratorSynchronousTestCase testMethod=test_generator", result.errors[0][1].value.args[0]) self.assertIn("is a generator function and therefore will never run", result.errors[0][1].value.args[0])
Example #29
Source File: test_pyunitcompat.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def test_pyunitSkip(self): """ Skips using pyunit's skipping functionality are reported as skips in the L{pyunit.TestResult}. """ class SkipTest(SynchronousTestCase): @pyunit.skip("skippy") def test_skip(self): 1/0 test = SkipTest('test_skip') result = pyunit.TestResult() test.run(result) self.assertEqual(result.skipped, [(test, "skippy")])
Example #30
Source File: test_assertions.py From learn_python3_spider with MIT License | 5 votes |
def test_successResultOfWithFailure(self): """ L{SynchronousTestCase.successResultOf} raises L{SynchronousTestCase.failureException} when called with a L{Deferred} with a failure result. """ self.assertRaises( self.failureException, self.successResultOf, fail(self.failure))