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