sample.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. """This module is used by test_loader to test the Trial test loading
  2. functionality. Do NOT change the number of tests in this module. Do NOT change
  3. the names the tests in this module.
  4. """
  5. from __future__ import absolute_import, division
  6. import unittest as pyunit
  7. from twisted.trial import unittest
  8. from twisted.python.util import mergeFunctionMetadata
  9. class FooTest(unittest.SynchronousTestCase):
  10. def test_foo(self):
  11. pass
  12. def test_bar(self):
  13. pass
  14. def badDecorator(fn):
  15. """
  16. Decorate a function without preserving the name of the original function.
  17. Always return a function with the same name.
  18. """
  19. def nameCollision(*args, **kwargs):
  20. return fn(*args, **kwargs)
  21. return nameCollision
  22. def goodDecorator(fn):
  23. """
  24. Decorate a function and preserve the original name.
  25. """
  26. def nameCollision(*args, **kwargs):
  27. return fn(*args, **kwargs)
  28. return mergeFunctionMetadata(fn, nameCollision)
  29. class DecorationTest(unittest.SynchronousTestCase):
  30. def test_badDecorator(self):
  31. """
  32. This test method is decorated in a way that gives it a confusing name
  33. that collides with another method.
  34. """
  35. test_badDecorator = badDecorator(test_badDecorator)
  36. def test_goodDecorator(self):
  37. """
  38. This test method is decorated in a way that preserves its name.
  39. """
  40. test_goodDecorator = goodDecorator(test_goodDecorator)
  41. def renamedDecorator(self):
  42. """
  43. This is secretly a test method and will be decorated and then renamed so
  44. test discovery can find it.
  45. """
  46. test_renamedDecorator = goodDecorator(renamedDecorator)
  47. def nameCollision(self):
  48. """
  49. This isn't a test, it's just here to collide with tests.
  50. """
  51. class PyunitTest(pyunit.TestCase):
  52. def test_foo(self):
  53. pass
  54. def test_bar(self):
  55. pass
  56. class NotATest(object):
  57. def test_foo(self):
  58. pass
  59. class AlphabetTest(unittest.SynchronousTestCase):
  60. def test_a(self):
  61. pass
  62. def test_b(self):
  63. pass
  64. def test_c(self):
  65. pass