test_doctest.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Test Twisted's doctest support.
  5. """
  6. from __future__ import absolute_import, division
  7. from twisted.trial import itrial, runner, unittest, reporter
  8. from twisted.trial.test import mockdoctest
  9. class RunnersTests(unittest.SynchronousTestCase):
  10. """
  11. Tests for Twisted's doctest support.
  12. """
  13. def test_id(self):
  14. """
  15. Check that the id() of the doctests' case object contains the FQPN of
  16. the actual tests.
  17. """
  18. loader = runner.TestLoader()
  19. suite = loader.loadDoctests(mockdoctest)
  20. idPrefix = 'twisted.trial.test.mockdoctest.Counter'
  21. for test in suite._tests:
  22. self.assertIn(idPrefix, itrial.ITestCase(test).id())
  23. def test_basicTrialIntegration(self):
  24. """
  25. L{loadDoctests} loads all of the doctests in the given module.
  26. """
  27. loader = runner.TestLoader()
  28. suite = loader.loadDoctests(mockdoctest)
  29. self.assertEqual(7, suite.countTestCases())
  30. def _testRun(self, suite):
  31. """
  32. Run C{suite} and check the result.
  33. """
  34. result = reporter.TestResult()
  35. suite.run(result)
  36. self.assertEqual(5, result.successes)
  37. self.assertEqual(2, len(result.failures))
  38. def test_expectedResults(self, count=1):
  39. """
  40. Trial can correctly run doctests with its xUnit test APIs.
  41. """
  42. suite = runner.TestLoader().loadDoctests(mockdoctest)
  43. self._testRun(suite)
  44. def test_repeatable(self):
  45. """
  46. Doctests should be runnable repeatably.
  47. """
  48. suite = runner.TestLoader().loadDoctests(mockdoctest)
  49. self._testRun(suite)
  50. self._testRun(suite)