Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / test / test_reflect.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Test cases for twisted.reflect module.
6 """
7
8 import weakref, os
9 from ihooks import ModuleImporter
10
11 try:
12     from collections import deque
13 except ImportError:
14     deque = None
15
16 from twisted.trial import unittest
17 from twisted.python import reflect, util
18 from twisted.python.versions import Version
19
20
21
22 class SettableTest(unittest.TestCase):
23     def setUp(self):
24         self.setter = reflect.Settable()
25
26     def tearDown(self):
27         del self.setter
28
29     def testSet(self):
30         self.setter(a=1, b=2)
31         self.assertEqual(self.setter.a, 1)
32         self.assertEqual(self.setter.b, 2)
33
34
35
36 class AccessorTester(reflect.Accessor):
37
38     def set_x(self, x):
39         self.y = x
40         self.reallySet('x', x)
41
42
43     def get_z(self):
44         self.q = 1
45         return 1
46
47
48     def del_z(self):
49         self.reallyDel("q")
50
51
52
53 class PropertyAccessorTester(reflect.PropertyAccessor):
54     """
55     Test class to check L{reflect.PropertyAccessor} functionalities.
56     """
57     r = 0
58
59     def set_r(self, r):
60         self.s = r
61
62
63     def set_x(self, x):
64         self.y = x
65         self.reallySet('x', x)
66
67
68     def get_z(self):
69         self.q = 1
70         return 1
71
72
73     def del_z(self):
74         self.reallyDel("q")
75
76
77
78 class AccessorTest(unittest.TestCase):
79     def setUp(self):
80         self.tester = AccessorTester()
81
82     def testSet(self):
83         self.tester.x = 1
84         self.assertEqual(self.tester.x, 1)
85         self.assertEqual(self.tester.y, 1)
86
87     def testGet(self):
88         self.assertEqual(self.tester.z, 1)
89         self.assertEqual(self.tester.q, 1)
90
91     def testDel(self):
92         self.tester.z
93         self.assertEqual(self.tester.q, 1)
94         del self.tester.z
95         self.assertEqual(hasattr(self.tester, "q"), 0)
96         self.tester.x = 1
97         del self.tester.x
98         self.assertEqual(hasattr(self.tester, "x"), 0)
99
100
101
102 class PropertyAccessorTest(AccessorTest):
103     """
104     Tests for L{reflect.PropertyAccessor}, using L{PropertyAccessorTester}.
105     """
106
107     def setUp(self):
108         self.tester = PropertyAccessorTester()
109
110
111     def test_setWithDefaultValue(self):
112         """
113         If an attribute is present in the class, it can be retrieved by
114         default.
115         """
116         self.assertEqual(self.tester.r, 0)
117         self.tester.r = 1
118         self.assertEqual(self.tester.r, 0)
119         self.assertEqual(self.tester.s, 1)
120
121
122     def test_getValueInDict(self):
123         """
124         The attribute value can be overriden by directly modifying the value in
125         C{__dict__}.
126         """
127         self.tester.__dict__["r"] = 10
128         self.assertEqual(self.tester.r, 10)
129
130
131     def test_notYetInDict(self):
132         """
133         If a getter is defined on an attribute but without any default value,
134         it raises C{AttributeError} when trying to access it.
135         """
136         self.assertRaises(AttributeError, getattr, self.tester, "x")
137
138
139
140 class LookupsTestCase(unittest.TestCase):
141     """
142     Tests for L{namedClass}, L{namedModule}, and L{namedAny}.
143     """
144
145     def test_namedClassLookup(self):
146         """
147         L{namedClass} should return the class object for the name it is passed.
148         """
149         self.assertIdentical(
150             reflect.namedClass("twisted.python.reflect.Summer"),
151             reflect.Summer)
152
153
154     def test_namedModuleLookup(self):
155         """
156         L{namedModule} should return the module object for the name it is
157         passed.
158         """
159         self.assertIdentical(
160             reflect.namedModule("twisted.python.reflect"), reflect)
161
162
163     def test_namedAnyPackageLookup(self):
164         """
165         L{namedAny} should return the package object for the name it is passed.
166         """
167         import twisted.python
168         self.assertIdentical(
169             reflect.namedAny("twisted.python"), twisted.python)
170
171     def test_namedAnyModuleLookup(self):
172         """
173         L{namedAny} should return the module object for the name it is passed.
174         """
175         self.assertIdentical(
176             reflect.namedAny("twisted.python.reflect"), reflect)
177
178
179     def test_namedAnyClassLookup(self):
180         """
181         L{namedAny} should return the class object for the name it is passed.
182         """
183         self.assertIdentical(
184             reflect.namedAny("twisted.python.reflect.Summer"), reflect.Summer)
185
186
187     def test_namedAnyAttributeLookup(self):
188         """
189         L{namedAny} should return the object an attribute of a non-module,
190         non-package object is bound to for the name it is passed.
191         """
192         # Note - not assertEqual because unbound method lookup creates a new
193         # object every time.  This is a foolishness of Python's object
194         # implementation, not a bug in Twisted.
195         self.assertEqual(
196             reflect.namedAny("twisted.python.reflect.Summer.reallySet"),
197             reflect.Summer.reallySet)
198
199
200     def test_namedAnySecondAttributeLookup(self):
201         """
202         L{namedAny} should return the object an attribute of an object which
203         itself was an attribute of a non-module, non-package object is bound to
204         for the name it is passed.
205         """
206         self.assertIdentical(
207             reflect.namedAny(
208                 "twisted.python.reflect.Summer.reallySet.__doc__"),
209             reflect.Summer.reallySet.__doc__)
210
211
212     def test_importExceptions(self):
213         """
214         Exceptions raised by modules which L{namedAny} causes to be imported
215         should pass through L{namedAny} to the caller.
216         """
217         self.assertRaises(
218             ZeroDivisionError,
219             reflect.namedAny, "twisted.test.reflect_helper_ZDE")
220         # Make sure that this behavior is *consistent* for 2.3, where there is
221         # no post-failed-import cleanup
222         self.assertRaises(
223             ZeroDivisionError,
224             reflect.namedAny, "twisted.test.reflect_helper_ZDE")
225         self.assertRaises(
226             ValueError,
227             reflect.namedAny, "twisted.test.reflect_helper_VE")
228         # Modules which themselves raise ImportError when imported should result in an ImportError
229         self.assertRaises(
230             ImportError,
231             reflect.namedAny, "twisted.test.reflect_helper_IE")
232
233
234     def test_attributeExceptions(self):
235         """
236         If segments on the end of a fully-qualified Python name represents
237         attributes which aren't actually present on the object represented by
238         the earlier segments, L{namedAny} should raise an L{AttributeError}.
239         """
240         self.assertRaises(
241             AttributeError,
242             reflect.namedAny, "twisted.nosuchmoduleintheworld")
243         # ImportError behaves somewhat differently between "import
244         # extant.nonextant" and "import extant.nonextant.nonextant", so test
245         # the latter as well.
246         self.assertRaises(
247             AttributeError,
248             reflect.namedAny, "twisted.nosuch.modulein.theworld")
249         self.assertRaises(
250             AttributeError,
251             reflect.namedAny, "twisted.python.reflect.Summer.nosuchattributeintheworld")
252
253
254     def test_invalidNames(self):
255         """
256         Passing a name which isn't a fully-qualified Python name to L{namedAny}
257         should result in one of the following exceptions:
258         - L{InvalidName}: the name is not a dot-separated list of Python objects
259         - L{ObjectNotFound}: the object doesn't exist
260         - L{ModuleNotFound}: the object doesn't exist and there is only one
261           component in the name
262         """
263         err = self.assertRaises(reflect.ModuleNotFound, reflect.namedAny,
264                                 'nosuchmoduleintheworld')
265         self.assertEqual(str(err), "No module named 'nosuchmoduleintheworld'")
266
267         # This is a dot-separated list, but it isn't valid!
268         err = self.assertRaises(reflect.ObjectNotFound, reflect.namedAny,
269                                 "@#$@(#.!@(#!@#")
270         self.assertEqual(str(err), "'@#$@(#.!@(#!@#' does not name an object")
271
272         err = self.assertRaises(reflect.ObjectNotFound, reflect.namedAny,
273                                 "tcelfer.nohtyp.detsiwt")
274         self.assertEqual(
275             str(err),
276             "'tcelfer.nohtyp.detsiwt' does not name an object")
277
278         err = self.assertRaises(reflect.InvalidName, reflect.namedAny, '')
279         self.assertEqual(str(err), 'Empty module name')
280
281         for invalidName in ['.twisted', 'twisted.', 'twisted..python']:
282             err = self.assertRaises(
283                 reflect.InvalidName, reflect.namedAny, invalidName)
284             self.assertEqual(
285                 str(err),
286                 "name must be a string giving a '.'-separated list of Python "
287                 "identifiers, not %r" % (invalidName,))
288
289
290
291 class ImportHooksLookupTests(LookupsTestCase):
292     """
293     Tests for lookup methods in the presence of L{ihooks}-style import hooks.
294     Runs all of the tests from L{LookupsTestCase} after installing a custom
295     import hook.
296     """
297     def setUp(self):
298         """
299         Perturb the normal import behavior subtly by installing an import
300         hook.  No custom behavior is provided, but this adds some extra
301         frames to the call stack, which L{namedAny} must be able to account
302         for.
303         """
304         self.importer = ModuleImporter()
305         self.importer.install()
306
307
308     def tearDown(self):
309         """
310         Uninstall the custom import hook.
311         """
312         self.importer.uninstall()
313
314
315
316 class ObjectGrep(unittest.TestCase):
317     def test_dictionary(self):
318         """
319         Test references search through a dictionnary, as a key or as a value.
320         """
321         o = object()
322         d1 = {None: o}
323         d2 = {o: None}
324
325         self.assertIn("[None]", reflect.objgrep(d1, o, reflect.isSame))
326         self.assertIn("{None}", reflect.objgrep(d2, o, reflect.isSame))
327
328     def test_list(self):
329         """
330         Test references search through a list.
331         """
332         o = object()
333         L = [None, o]
334
335         self.assertIn("[1]", reflect.objgrep(L, o, reflect.isSame))
336
337     def test_tuple(self):
338         """
339         Test references search through a tuple.
340         """
341         o = object()
342         T = (o, None)
343
344         self.assertIn("[0]", reflect.objgrep(T, o, reflect.isSame))
345
346     def test_instance(self):
347         """
348         Test references search through an object attribute.
349         """
350         class Dummy:
351             pass
352         o = object()
353         d = Dummy()
354         d.o = o
355
356         self.assertIn(".o", reflect.objgrep(d, o, reflect.isSame))
357
358     def test_weakref(self):
359         """
360         Test references search through a weakref object.
361         """
362         class Dummy:
363             pass
364         o = Dummy()
365         w1 = weakref.ref(o)
366
367         self.assertIn("()", reflect.objgrep(w1, o, reflect.isSame))
368
369     def test_boundMethod(self):
370         """
371         Test references search through method special attributes.
372         """
373         class Dummy:
374             def dummy(self):
375                 pass
376         o = Dummy()
377         m = o.dummy
378
379         self.assertIn(".im_self", reflect.objgrep(m, m.im_self, reflect.isSame))
380         self.assertIn(".im_class", reflect.objgrep(m, m.im_class, reflect.isSame))
381         self.assertIn(".im_func", reflect.objgrep(m, m.im_func, reflect.isSame))
382
383     def test_everything(self):
384         """
385         Test references search using complex set of objects.
386         """
387         class Dummy:
388             def method(self):
389                 pass
390
391         o = Dummy()
392         D1 = {(): "baz", None: "Quux", o: "Foosh"}
393         L = [None, (), D1, 3]
394         T = (L, {}, Dummy())
395         D2 = {0: "foo", 1: "bar", 2: T}
396         i = Dummy()
397         i.attr = D2
398         m = i.method
399         w = weakref.ref(m)
400
401         self.assertIn("().im_self.attr[2][0][2]{'Foosh'}", reflect.objgrep(w, o, reflect.isSame))
402
403     def test_depthLimit(self):
404         """
405         Test the depth of references search.
406         """
407         a = []
408         b = [a]
409         c = [a, b]
410         d = [a, c]
411
412         self.assertEqual(['[0]'], reflect.objgrep(d, a, reflect.isSame, maxDepth=1))
413         self.assertEqual(['[0]', '[1][0]'], reflect.objgrep(d, a, reflect.isSame, maxDepth=2))
414         self.assertEqual(['[0]', '[1][0]', '[1][1][0]'], reflect.objgrep(d, a, reflect.isSame, maxDepth=3))
415
416     def test_deque(self):
417         """
418         Test references search through a deque object. Only for Python > 2.3.
419         """
420         o = object()
421         D = deque()
422         D.append(None)
423         D.append(o)
424
425         self.assertIn("[1]", reflect.objgrep(D, o, reflect.isSame))
426
427     if deque is None:
428         test_deque.skip = "Deque not available"
429
430
431 class GetClass(unittest.TestCase):
432     def testOld(self):
433         class OldClass:
434             pass
435         old = OldClass()
436         self.assertIn(reflect.getClass(OldClass).__name__, ('class', 'classobj'))
437         self.assertEqual(reflect.getClass(old).__name__, 'OldClass')
438
439     def testNew(self):
440         class NewClass(object):
441             pass
442         new = NewClass()
443         self.assertEqual(reflect.getClass(NewClass).__name__, 'type')
444         self.assertEqual(reflect.getClass(new).__name__, 'NewClass')
445
446
447
448 class Breakable(object):
449
450     breakRepr = False
451     breakStr = False
452
453     def __str__(self):
454         if self.breakStr:
455             raise RuntimeError("str!")
456         else:
457             return '<Breakable>'
458
459     def __repr__(self):
460         if self.breakRepr:
461             raise RuntimeError("repr!")
462         else:
463             return 'Breakable()'
464
465
466
467 class BrokenType(Breakable, type):
468     breakName = False
469
470     def get___name__(self):
471         if self.breakName:
472             raise RuntimeError("no name")
473         return 'BrokenType'
474     __name__ = property(get___name__)
475
476
477
478 class BTBase(Breakable):
479     __metaclass__ = BrokenType
480     breakRepr = True
481     breakStr = True
482
483
484
485 class NoClassAttr(Breakable):
486     __class__ = property(lambda x: x.not_class)
487
488
489
490 class SafeRepr(unittest.TestCase):
491     """
492     Tests for L{reflect.safe_repr} function.
493     """
494
495     def test_workingRepr(self):
496         """
497         L{reflect.safe_repr} produces the same output as C{repr} on a working
498         object.
499         """
500         x = [1, 2, 3]
501         self.assertEqual(reflect.safe_repr(x), repr(x))
502
503
504     def test_brokenRepr(self):
505         """
506         L{reflect.safe_repr} returns a string with class name, address, and
507         traceback when the repr call failed.
508         """
509         b = Breakable()
510         b.breakRepr = True
511         bRepr = reflect.safe_repr(b)
512         self.assertIn("Breakable instance at 0x", bRepr)
513         # Check that the file is in the repr, but without the extension as it
514         # can be .py/.pyc
515         self.assertIn(os.path.splitext(__file__)[0], bRepr)
516         self.assertIn("RuntimeError: repr!", bRepr)
517
518
519     def test_brokenStr(self):
520         """
521         L{reflect.safe_repr} isn't affected by a broken C{__str__} method.
522         """
523         b = Breakable()
524         b.breakStr = True
525         self.assertEqual(reflect.safe_repr(b), repr(b))
526
527
528     def test_brokenClassRepr(self):
529         class X(BTBase):
530             breakRepr = True
531         reflect.safe_repr(X)
532         reflect.safe_repr(X())
533
534
535     def test_unsignedID(self):
536         """
537         L{unsignedID} is used to print ID of the object in case of error, not
538         standard ID value which can be negative.
539         """
540         class X(BTBase):
541             breakRepr = True
542
543         ids = {X: 100}
544         def fakeID(obj):
545             try:
546                 return ids[obj]
547             except (TypeError, KeyError):
548                 return id(obj)
549         self.addCleanup(util.setIDFunction, util.setIDFunction(fakeID))
550
551         xRepr = reflect.safe_repr(X)
552         self.assertIn("0x64", xRepr)
553
554
555     def test_brokenClassStr(self):
556         class X(BTBase):
557             breakStr = True
558         reflect.safe_repr(X)
559         reflect.safe_repr(X())
560
561
562     def test_brokenClassAttribute(self):
563         """
564         If an object raises an exception when accessing its C{__class__}
565         attribute, L{reflect.safe_repr} uses C{type} to retrieve the class
566         object.
567         """
568         b = NoClassAttr()
569         b.breakRepr = True
570         bRepr = reflect.safe_repr(b)
571         self.assertIn("NoClassAttr instance at 0x", bRepr)
572         self.assertIn(os.path.splitext(__file__)[0], bRepr)
573         self.assertIn("RuntimeError: repr!", bRepr)
574
575
576     def test_brokenClassNameAttribute(self):
577         """
578         If a class raises an exception when accessing its C{__name__} attribute
579         B{and} when calling its C{__str__} implementation, L{reflect.safe_repr}
580         returns 'BROKEN CLASS' instead of the class name.
581         """
582         class X(BTBase):
583             breakName = True
584         xRepr = reflect.safe_repr(X())
585         self.assertIn("<BROKEN CLASS AT 0x", xRepr)
586         self.assertIn(os.path.splitext(__file__)[0], xRepr)
587         self.assertIn("RuntimeError: repr!", xRepr)
588
589
590
591 class SafeStr(unittest.TestCase):
592     """
593     Tests for L{reflect.safe_str} function.
594     """
595
596     def test_workingStr(self):
597         x = [1, 2, 3]
598         self.assertEqual(reflect.safe_str(x), str(x))
599
600
601     def test_brokenStr(self):
602         b = Breakable()
603         b.breakStr = True
604         reflect.safe_str(b)
605
606
607     def test_brokenRepr(self):
608         b = Breakable()
609         b.breakRepr = True
610         reflect.safe_str(b)
611
612
613     def test_brokenClassStr(self):
614         class X(BTBase):
615             breakStr = True
616         reflect.safe_str(X)
617         reflect.safe_str(X())
618
619
620     def test_brokenClassRepr(self):
621         class X(BTBase):
622             breakRepr = True
623         reflect.safe_str(X)
624         reflect.safe_str(X())
625
626
627     def test_brokenClassAttribute(self):
628         """
629         If an object raises an exception when accessing its C{__class__}
630         attribute, L{reflect.safe_str} uses C{type} to retrieve the class
631         object.
632         """
633         b = NoClassAttr()
634         b.breakStr = True
635         bStr = reflect.safe_str(b)
636         self.assertIn("NoClassAttr instance at 0x", bStr)
637         self.assertIn(os.path.splitext(__file__)[0], bStr)
638         self.assertIn("RuntimeError: str!", bStr)
639
640
641     def test_brokenClassNameAttribute(self):
642         """
643         If a class raises an exception when accessing its C{__name__} attribute
644         B{and} when calling its C{__str__} implementation, L{reflect.safe_str}
645         returns 'BROKEN CLASS' instead of the class name.
646         """
647         class X(BTBase):
648             breakName = True
649         xStr = reflect.safe_str(X())
650         self.assertIn("<BROKEN CLASS AT 0x", xStr)
651         self.assertIn(os.path.splitext(__file__)[0], xStr)
652         self.assertIn("RuntimeError: str!", xStr)
653
654
655
656 class FilenameToModule(unittest.TestCase):
657     """
658     Test L{reflect.filenameToModuleName} detection.
659     """
660     def test_directory(self):
661         """
662         Tests it finds good name for directories/packages.
663         """
664         module = reflect.filenameToModuleName(os.path.join('twisted', 'test'))
665         self.assertEqual(module, 'test')
666         module = reflect.filenameToModuleName(os.path.join('twisted', 'test')
667                                               + os.path.sep)
668         self.assertEqual(module, 'test')
669
670     def test_file(self):
671         """
672         Test it finds good name for files.
673         """
674         module = reflect.filenameToModuleName(
675             os.path.join('twisted', 'test', 'test_reflect.py'))
676         self.assertEqual(module, 'test_reflect')
677
678
679
680 class FullyQualifiedNameTests(unittest.TestCase):
681     """
682     Test for L{reflect.fullyQualifiedName}.
683     """
684
685     def _checkFullyQualifiedName(self, obj, expected):
686         """
687         Helper to check that fully qualified name of C{obj} results to
688         C{expected}.
689         """
690         self.assertEqual(
691             reflect.fullyQualifiedName(obj), expected)
692
693
694     def test_package(self):
695         """
696         L{reflect.fullyQualifiedName} returns the full name of a package and
697         a subpackage.
698         """
699         import twisted
700         self._checkFullyQualifiedName(twisted, 'twisted')
701         import twisted.python
702         self._checkFullyQualifiedName(twisted.python, 'twisted.python')
703
704
705     def test_module(self):
706         """
707         L{reflect.fullyQualifiedName} returns the name of a module inside a a
708         package.
709         """
710         self._checkFullyQualifiedName(reflect, 'twisted.python.reflect')
711         import twisted.trial.unittest
712         self._checkFullyQualifiedName(twisted.trial.unittest,
713                                       'twisted.trial.unittest')
714
715
716     def test_class(self):
717         """
718         L{reflect.fullyQualifiedName} returns the name of a class and its
719         module.
720         """
721         self._checkFullyQualifiedName(reflect.Settable,
722                                       'twisted.python.reflect.Settable')
723
724
725     def test_function(self):
726         """
727         L{reflect.fullyQualifiedName} returns the name of a function inside its
728         module.
729         """
730         self._checkFullyQualifiedName(reflect.fullyQualifiedName,
731             "twisted.python.reflect.fullyQualifiedName")
732
733
734     def test_boundMethod(self):
735         """
736         L{reflect.fullyQualifiedName} returns the name of a bound method inside
737         its class and its module.
738         """
739         self._checkFullyQualifiedName(
740             reflect.PropertyAccessor().reallyDel,
741             "twisted.python.reflect.PropertyAccessor.reallyDel")
742
743
744     def test_unboundMethod(self):
745         """
746         L{reflect.fullyQualifiedName} returns the name of an unbound method
747         inside its class and its module.
748         """
749         self._checkFullyQualifiedName(
750             reflect.PropertyAccessor.reallyDel,
751             "twisted.python.reflect.PropertyAccessor.reallyDel")
752
753
754
755 class DeprecationTestCase(unittest.TestCase):
756     """
757     Test deprecations in twisted.python.reflect
758     """
759
760     def test_allYourBase(self):
761         """
762         Test deprecation of L{reflect.allYourBase}. See #5481 for removal.
763         """
764         self.callDeprecated(
765             (Version("Twisted", 11, 0, 0), "inspect.getmro"),
766             reflect.allYourBase, DeprecationTestCase)
767
768
769     def test_accumulateBases(self):
770         """
771         Test deprecation of L{reflect.accumulateBases}. See #5481 for removal.
772         """
773         l = []
774         self.callDeprecated(
775             (Version("Twisted", 11, 0, 0), "inspect.getmro"),
776             reflect.accumulateBases, DeprecationTestCase, l, None)
777
778
779     def lookForDeprecationWarning(self, testMethod, attributeName, warningMsg):
780         """
781         Test deprecation of attribute 'reflect.attributeName' by calling
782         'reflect.testMethod' and verifying the warning message
783         'reflect.warningMsg'
784
785         @param testMethod: Name of the offending function to be used with
786             flushWarnings
787         @type testmethod: C{str}
788
789         @param attributeName: Name of attribute to be checked for deprecation
790         @type attributeName: C{str}
791
792         @param warningMsg: Deprecation warning message
793         @type warningMsg: C{str}
794         """
795         warningsShown = self.flushWarnings([testMethod])
796         self.assertEqual(len(warningsShown), 1)
797         self.assertIdentical(warningsShown[0]['category'], DeprecationWarning)
798         self.assertEqual(
799             warningsShown[0]['message'],
800             "twisted.python.reflect." + attributeName + " "
801             "was deprecated in Twisted 12.1.0: " + warningMsg + ".")
802
803
804     def test_settable(self):
805         """
806         Test deprecation of L{reflect.Settable}.
807         """
808         reflect.Settable()
809         self.lookForDeprecationWarning(
810             self.test_settable, "Settable",
811             "Settable is old and untested. Please write your own version of this "
812             "functionality if you need it")
813
814
815     def test_accessorType(self):
816         """
817         Test deprecation of L{reflect.AccessorType}.
818         """
819         reflect.AccessorType(' ', ( ), { })
820         self.lookForDeprecationWarning(
821             self.test_accessorType, "AccessorType",
822             "AccessorType is old and untested. Please write your own version of "
823             "this functionality if you need it")
824
825
826     def test_propertyAccessor(self):
827         """
828         Test deprecation of L{reflect.PropertyAccessor}.
829         """
830         reflect.PropertyAccessor()
831         self.lookForDeprecationWarning(
832             self.test_propertyAccessor, "PropertyAccessor",
833             "PropertyAccessor is old and untested. Please write your own "
834             "version of this functionality if you need it")
835
836
837     def test_accessor(self):
838         """
839         Test deprecation of L{reflect.Accessor}.
840         """
841         reflect.Accessor()
842         self.lookForDeprecationWarning(
843             self.test_accessor, "Accessor",
844             "Accessor is an implementation for Python 2.1 which is no longer "
845             "supported by Twisted")
846
847
848     def test_originalAccessor(self):
849         """
850         Test deprecation of L{reflect.OriginalAccessor}.
851         """
852         reflect.OriginalAccessor()
853         self.lookForDeprecationWarning(
854             self.test_originalAccessor, "OriginalAccessor",
855             "OriginalAccessor is a reference to class "
856             "twisted.python.reflect.Accessor which is deprecated")
857
858
859     def test_summer(self):
860         """
861         Test deprecation of L{reflect.Summer}.
862         """
863         reflect.Summer()
864         self.lookForDeprecationWarning(
865             self.test_summer, "Summer",
866             "Summer is a child class of twisted.python.reflect.Accessor which "
867             "is deprecated")