/usr/lib/python3/dist-packages/twisted/test
NameSizeModeActions
__pycache__/-0755rm
cert.pem.no_trailing_newline14140644editdlrm
crash_test_dummy.py5430644editdlrm
iosim.py178430644editdlrm
key.pem.no_trailing_newline17070644editdlrm
mock_win32process.py14990644editdlrm
myrebuilder1.py1580644editdlrm
myrebuilder2.py1580644editdlrm
plugin_basic.py9430644editdlrm
plugin_extra1.py4070644editdlrm
plugin_extra2.py5790644editdlrm
process_cmdline.py1620644editdlrm
process_echoer.py2140644editdlrm
process_fds.py9450644editdlrm
process_getargv.py2830644editdlrm
process_getenv.py2680644editdlrm
process_linger.py2860644editdlrm
process_reader.py1880644editdlrm
process_signal.py2140644editdlrm
process_stdinreader.py8570644editdlrm
process_tester.py10350644editdlrm
process_tty.py1300644editdlrm
process_twisted.py12060644editdlrm
proto_helpers.py286870644editdlrm
raiser.cpython-38-x86_64-linux-gnu.so238640644editdlrm
reflect_helper_IE.py610644editdlrm
reflect_helper_VE.py820644editdlrm
reflect_helper_ZDE.py470644editdlrm
server.pem44440644editdlrm
ssl_helpers.py10320644editdlrm
stdio_test_consumer.py12160644editdlrm
stdio_test_halfclose.py19380644editdlrm
stdio_test_hostpeer.py10210644editdlrm
stdio_test_lastwrite.py12060644editdlrm
stdio_test_loseconn.py15480644editdlrm
stdio_test_producer.py15070644editdlrm
stdio_test_write.py9230644editdlrm
stdio_test_writeseq.py9150644editdlrm
testutils.py53210644editdlrm
test_abstract.py34970644editdlrm
test_adbapi.py261480644editdlrm
test_amp.py1105530644editdlrm
test_application.py328160644editdlrm
test_compat.py292780644editdlrm
test_context.py15150644editdlrm
test_cooperator.py214670644editdlrm
test_defer.py1034070644editdlrm
test_defgen.py107010644editdlrm
test_dict.py14420644editdlrm
test_dirdbm.py66950644editdlrm
test_error.py85930644editdlrm
test_factories.py46370644editdlrm
test_failure.py322880644editdlrm
test_fdesc.py73710644editdlrm
test_finger.py19970644editdlrm
test_formmethod.py36450644editdlrm
test_ftp.py1303210644editdlrm
test_ftp_options.py26850644editdlrm
test_htb.py31900644editdlrm
test_ident.py70150644editdlrm
test_internet.py464220644editdlrm
test_iosim.py90600644editdlrm
test_iutils.py134450644editdlrm
test_lockfile.py155060644editdlrm
test_log.py363300644editdlrm
test_logfile.py182270644editdlrm
test_loopback.py144860644editdlrm
test_main.py25010644editdlrm
test_memcache.py251430644editdlrm
test_modules.py178880644editdlrm
test_monkey.py56370644editdlrm
test_nooldstyle.py59550644editdlrm
test_paths.py743570644editdlrm
test_pcp.py125510644editdlrm
test_persisted.py146240644editdlrm
test_plugin.py261130644editdlrm
test_policies.py334990644editdlrm
test_postfix.py42430644editdlrm
test_process.py861200644editdlrm
test_protocols.py74500644editdlrm
test_randbytes.py33570644editdlrm
test_rebuild.py84950644editdlrm
test_reflect.py260850644editdlrm
test_roots.py18120644editdlrm
test_shortcut.py19910644editdlrm
test_sip.py252840644editdlrm
test_sob.py56320644editdlrm
test_socks.py177380644editdlrm
test_ssl.py238460644editdlrm
test_sslverify.py1133220644editdlrm
test_stateful.py20210644editdlrm
test_stdio.py131560644editdlrm
test_strerror.py51830644editdlrm
test_stringtransport.py132640644editdlrm
test_strports.py17970644editdlrm
test_task.py393260644editdlrm
test_tcp.py658200644editdlrm
test_tcp_internals.py131170644editdlrm
test_text.py64560644editdlrm
test_threadable.py37380644editdlrm
test_threadpool.py222040644editdlrm
test_threads.py132680644editdlrm
test_tpfile.py16010644editdlrm
test_twistd.py742010644editdlrm
test_twisted.py111730644editdlrm
test_udp.py246760644editdlrm
test_unix.py151570644editdlrm
test_usage.py236450644editdlrm
__init__.py1030644editdlrm
Edit: /usr/lib/python3/dist-packages/twisted/test/test_reflect.py (26085B)
# Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Test cases for the L{twisted.python.reflect} module. """ from __future__ import division, absolute_import import os import weakref from collections import deque from twisted.python.compat import _PY3 from twisted.trial import unittest from twisted.trial.unittest import SynchronousTestCase as TestCase from twisted.python import reflect from twisted.python.reflect import ( accumulateMethods, prefixedMethods, prefixedMethodNames, addMethodNamesToDict, fullyQualifiedName) class Base(object): """ A no-op class which can be used to verify the behavior of method-discovering APIs. """ def method(self): """ A no-op method which can be discovered. """ class Sub(Base): """ A subclass of a class with a method which can be discovered. """ class Separate(object): """ A no-op class with methods with differing prefixes. """ def good_method(self): """ A no-op method which a matching prefix to be discovered. """ def bad_method(self): """ A no-op method with a mismatched prefix to not be discovered. """ class AccumulateMethodsTests(TestCase): """ Tests for L{accumulateMethods} which finds methods on a class hierarchy and adds them to a dictionary. """ def test_ownClass(self): """ If x is and instance of Base and Base defines a method named method, L{accumulateMethods} adds an item to the given dictionary with C{"method"} as the key and a bound method object for Base.method value. """ x = Base() output = {} accumulateMethods(x, output) self.assertEqual({"method": x.method}, output) def test_baseClass(self): """ If x is an instance of Sub and Sub is a subclass of Base and Base defines a method named method, L{accumulateMethods} adds an item to the given dictionary with C{"method"} as the key and a bound method object for Base.method as the value. """ x = Sub() output = {} accumulateMethods(x, output) self.assertEqual({"method": x.method}, output) def test_prefix(self): """ If a prefix is given, L{accumulateMethods} limits its results to methods beginning with that prefix. Keys in the resulting dictionary also have the prefix removed from them. """ x = Separate() output = {} accumulateMethods(x, output, 'good_') self.assertEqual({'method': x.good_method}, output) class PrefixedMethodsTests(TestCase): """ Tests for L{prefixedMethods} which finds methods on a class hierarchy and adds them to a dictionary. """ def test_onlyObject(self): """ L{prefixedMethods} returns a list of the methods discovered on an object. """ x = Base() output = prefixedMethods(x) self.assertEqual([x.method], output) def test_prefix(self): """ If a prefix is given, L{prefixedMethods} returns only methods named with that prefix. """ x = Separate() output = prefixedMethods(x, 'good_') self.assertEqual([x.good_method], output) class PrefixedMethodNamesTests(TestCase): """ Tests for L{prefixedMethodNames}. """ def test_method(self): """ L{prefixedMethodNames} returns a list including methods with the given prefix defined on the class passed to it. """ self.assertEqual(["method"], prefixedMethodNames(Separate, "good_")) def test_inheritedMethod(self): """ L{prefixedMethodNames} returns a list included methods with the given prefix defined on base classes of the class passed to it. """ class Child(Separate): pass self.assertEqual(["method"], prefixedMethodNames(Child, "good_")) class AddMethodNamesToDictTests(TestCase): """ Tests for L{addMethodNamesToDict}. """ def test_baseClass(self): """ If C{baseClass} is passed to L{addMethodNamesToDict}, only methods which are a subclass of C{baseClass} are added to the result dictionary. """ class Alternate(object): pass class Child(Separate, Alternate): def good_alternate(self): pass result = {} addMethodNamesToDict(Child, result, 'good_', Alternate) self.assertEqual({'alternate': 1}, result) class Summer(object): """ A class we look up as part of the LookupsTests. """ def reallySet(self): """ Do something. """ class LookupsTests(TestCase): """ Tests for L{namedClass}, L{namedModule}, and L{namedAny}. """ def test_namedClassLookup(self): """ L{namedClass} should return the class object for the name it is passed. """ self.assertIs( reflect.namedClass("twisted.test.test_reflect.Summer"), Summer) def test_namedModuleLookup(self): """ L{namedModule} should return the module object for the name it is passed. """ from twisted.python import monkey self.assertIs( reflect.namedModule("twisted.python.monkey"), monkey) def test_namedAnyPackageLookup(self): """ L{namedAny} should return the package object for the name it is passed. """ import twisted.python self.assertIs( reflect.namedAny("twisted.python"), twisted.python) def test_namedAnyModuleLookup(self): """ L{namedAny} should return the module object for the name it is passed. """ from twisted.python import monkey self.assertIs( reflect.namedAny("twisted.python.monkey"), monkey) def test_namedAnyClassLookup(self): """ L{namedAny} should return the class object for the name it is passed. """ self.assertIs( reflect.namedAny("twisted.test.test_reflect.Summer"), Summer) def test_namedAnyAttributeLookup(self): """ L{namedAny} should return the object an attribute of a non-module, non-package object is bound to for the name it is passed. """ # Note - not assertIs because unbound method lookup creates a new # object every time. This is a foolishness of Python's object # implementation, not a bug in Twisted. self.assertEqual( reflect.namedAny( "twisted.test.test_reflect.Summer.reallySet"), Summer.reallySet) def test_namedAnySecondAttributeLookup(self): """ L{namedAny} should return the object an attribute of an object which itself was an attribute of a non-module, non-package object is bound to for the name it is passed. """ self.assertIs( reflect.namedAny( "twisted.test.test_reflect." "Summer.reallySet.__doc__"), Summer.reallySet.__doc__) def test_importExceptions(self): """ Exceptions raised by modules which L{namedAny} causes to be imported should pass through L{namedAny} to the caller. """ self.assertRaises( ZeroDivisionError, reflect.namedAny, "twisted.test.reflect_helper_ZDE") # Make sure that there is post-failed-import cleanup self.assertRaises( ZeroDivisionError, reflect.namedAny, "twisted.test.reflect_helper_ZDE") self.assertRaises( ValueError, reflect.namedAny, "twisted.test.reflect_helper_VE") # Modules which themselves raise ImportError when imported should # result in an ImportError self.assertRaises( ImportError, reflect.namedAny, "twisted.test.reflect_helper_IE") def test_attributeExceptions(self): """ If segments on the end of a fully-qualified Python name represents attributes which aren't actually present on the object represented by the earlier segments, L{namedAny} should raise an L{AttributeError}. """ self.assertRaises( AttributeError, reflect.namedAny, "twisted.nosuchmoduleintheworld") # ImportError behaves somewhat differently between "import # extant.nonextant" and "import extant.nonextant.nonextant", so test # the latter as well. self.assertRaises( AttributeError, reflect.namedAny, "twisted.nosuch.modulein.theworld") self.assertRaises( AttributeError, reflect.namedAny, "twisted.test.test_reflect.Summer.nosuchattribute") def test_invalidNames(self): """ Passing a name which isn't a fully-qualified Python name to L{namedAny} should result in one of the following exceptions: - L{InvalidName}: the name is not a dot-separated list of Python objects - L{ObjectNotFound}: the object doesn't exist - L{ModuleNotFound}: the object doesn't exist and there is only one component in the name """ err = self.assertRaises(reflect.ModuleNotFound, reflect.namedAny, 'nosuchmoduleintheworld') self.assertEqual(str(err), "No module named 'nosuchmoduleintheworld'") # This is a dot-separated list, but it isn't valid! err = self.assertRaises(reflect.ObjectNotFound, reflect.namedAny, "@#$@(#.!@(#!@#") self.assertEqual(str(err), "'@#$@(#.!@(#!@#' does not name an object") err = self.assertRaises(reflect.ObjectNotFound, reflect.namedAny, "tcelfer.nohtyp.detsiwt") self.assertEqual( str(err), "'tcelfer.nohtyp.detsiwt' does not name an object") err = self.assertRaises(reflect.InvalidName, reflect.namedAny, '') self.assertEqual(str(err), 'Empty module name') for invalidName in ['.twisted', 'twisted.', 'twisted..python']: err = self.assertRaises( reflect.InvalidName, reflect.namedAny, invalidName) self.assertEqual( str(err), "name must be a string giving a '.'-separated list of Python " "identifiers, not %r" % (invalidName,)) def test_requireModuleImportError(self): """ When module import fails with ImportError it returns the specified default value. """ for name in ['nosuchmtopodule', 'no.such.module']: default = object() result = reflect.requireModule(name, default=default) self.assertIs(result, default) def test_requireModuleDefaultNone(self): """ When module import fails it returns L{None} by default. """ result = reflect.requireModule('no.such.module') self.assertIsNone(result) def test_requireModuleRequestedImport(self): """ When module import succeed it returns the module and not the default value. """ from twisted.python import monkey default = object() self.assertIs( reflect.requireModule('twisted.python.monkey', default=default), monkey, ) class Breakable(object): breakRepr = False breakStr = False def __str__(self): if self.breakStr: raise RuntimeError("str!") else: return '' def __repr__(self): if self.breakRepr: raise RuntimeError("repr!") else: return 'Breakable()' class BrokenType(Breakable, type): breakName = False def get___name__(self): if self.breakName: raise RuntimeError("no name") return 'BrokenType' __name__ = property(get___name__) BTBase = BrokenType('BTBase', (Breakable,), {"breakRepr": True, "breakStr": True}) class NoClassAttr(Breakable): __class__ = property(lambda x: x.not_class) class SafeReprTests(TestCase): """ Tests for L{reflect.safe_repr} function. """ def test_workingRepr(self): """ L{reflect.safe_repr} produces the same output as C{repr} on a working object. """ xs = ([1, 2, 3], b'a') self.assertEqual(list(map(reflect.safe_repr, xs)), list(map(repr, xs))) def test_brokenRepr(self): """ L{reflect.safe_repr} returns a string with class name, address, and traceback when the repr call failed. """ b = Breakable() b.breakRepr = True bRepr = reflect.safe_repr(b) self.assertIn("Breakable instance at 0x", bRepr) # Check that the file is in the repr, but without the extension as it # can be .py/.pyc self.assertIn(os.path.splitext(__file__)[0], bRepr) self.assertIn("RuntimeError: repr!", bRepr) def test_brokenStr(self): """ L{reflect.safe_repr} isn't affected by a broken C{__str__} method. """ b = Breakable() b.breakStr = True self.assertEqual(reflect.safe_repr(b), repr(b)) def test_brokenClassRepr(self): class X(BTBase): breakRepr = True reflect.safe_repr(X) reflect.safe_repr(X()) def test_brokenReprIncludesID(self): """ C{id} is used to print the ID of the object in case of an error. L{safe_repr} includes a traceback after a newline, so we only check against the first line of the repr. """ class X(BTBase): breakRepr = True xRepr = reflect.safe_repr(X) xReprExpected = ('