code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
194
url
stringlengths
46
254
license
stringclasses
4 values
def flush(self): """ Do nothing. """
Do nothing.
flush
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/log.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/log.py
MIT
def close(self): """ Do nothing. """
Do nothing.
close
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/log.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/log.py
MIT
def discardLogs(): """ Discard messages logged via the global C{logfile} object. """ global logfile logfile = NullFile()
Discard messages logged via the global C{logfile} object.
discardLogs
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/log.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/log.py
MIT
def emit(self, eventDict): """ Emit an event dict. @param eventDict: an event dict @type eventDict: dict """ if eventDict["isError"]: text = textFromEventDict(eventDict) self.stderr.write(text) self.stderr.flush()
Emit an event dict. @param eventDict: an event dict @type eventDict: dict
emit
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/log.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/log.py
MIT
def sendmsg(socket, data, ancillary=[], flags=0): """ Send a message on a socket. @param socket: The socket to send the message on. @type socket: L{socket.socket} @param data: Bytes to write to the socket. @type data: bytes @param ancillary: Extra data to send over the socket outside of the normal datagram or stream mechanism. By default no ancillary data is sent. @type ancillary: C{list} of C{tuple} of C{int}, C{int}, and C{bytes}. @param flags: Flags to affect how the message is sent. See the C{MSG_} constants in the sendmsg(2) manual page. By default no flags are set. @type flags: C{int} @return: The return value of the underlying syscall, if it succeeds. """ if _PY3: return socket.sendmsg([data], ancillary, flags) else: return send1msg(socket.fileno(), data, flags, ancillary)
Send a message on a socket. @param socket: The socket to send the message on. @type socket: L{socket.socket} @param data: Bytes to write to the socket. @type data: bytes @param ancillary: Extra data to send over the socket outside of the normal datagram or stream mechanism. By default no ancillary data is sent. @type ancillary: C{list} of C{tuple} of C{int}, C{int}, and C{bytes}. @param flags: Flags to affect how the message is sent. See the C{MSG_} constants in the sendmsg(2) manual page. By default no flags are set. @type flags: C{int} @return: The return value of the underlying syscall, if it succeeds.
sendmsg
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/sendmsg.py
MIT
def recvmsg(socket, maxSize=8192, cmsgSize=4096, flags=0): """ Receive a message on a socket. @param socket: The socket to receive the message on. @type socket: L{socket.socket} @param maxSize: The maximum number of bytes to receive from the socket using the datagram or stream mechanism. The default maximum is 8192. @type maxSize: L{int} @param cmsgSize: The maximum number of bytes to receive from the socket outside of the normal datagram or stream mechanism. The default maximum is 4096. @type cmsgSize: L{int} @param flags: Flags to affect how the message is sent. See the C{MSG_} constants in the sendmsg(2) manual page. By default no flags are set. @type flags: L{int} @return: A named 3-tuple of the bytes received using the datagram/stream mechanism, a L{list} of L{tuple}s giving ancillary received data, and flags as an L{int} describing the data received. """ if _PY3: # In Twisted's sendmsg.c, the csmg_space is defined as: # int cmsg_size = 4096; # cmsg_space = CMSG_SPACE(cmsg_size); # Since the default in Python 3's socket is 0, we need to define our # own default of 4096. -hawkie data, ancillary, flags = socket.recvmsg( maxSize, CMSG_SPACE(cmsgSize), flags)[0:3] else: data, flags, ancillary = recv1msg( socket.fileno(), flags, maxSize, cmsgSize) return RecievedMessage(data=data, ancillary=ancillary, flags=flags)
Receive a message on a socket. @param socket: The socket to receive the message on. @type socket: L{socket.socket} @param maxSize: The maximum number of bytes to receive from the socket using the datagram or stream mechanism. The default maximum is 8192. @type maxSize: L{int} @param cmsgSize: The maximum number of bytes to receive from the socket outside of the normal datagram or stream mechanism. The default maximum is 4096. @type cmsgSize: L{int} @param flags: Flags to affect how the message is sent. See the C{MSG_} constants in the sendmsg(2) manual page. By default no flags are set. @type flags: L{int} @return: A named 3-tuple of the bytes received using the datagram/stream mechanism, a L{list} of L{tuple}s giving ancillary received data, and flags as an L{int} describing the data received.
recvmsg
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/sendmsg.py
MIT
def getSocketFamily(socket): """ Return the family of the given socket. @param socket: The socket to get the family of. @type socket: L{socket.socket} @rtype: L{int} """ if _PY3: return socket.family else: return getsockfam(socket.fileno())
Return the family of the given socket. @param socket: The socket to get the family of. @type socket: L{socket.socket} @rtype: L{int}
getSocketFamily
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/sendmsg.py
MIT
def test_exist(self): """ All modules listed in L{notPortedModules} exist on Py2. """ root = os.path.dirname(os.path.dirname(twisted.__file__)) for module in notPortedModules: segments = module.split(".") segments[-1] += ".py" path = os.path.join(root, *segments) alternateSegments = module.split(".") + ["__init__.py"] packagePath = os.path.join(root, *alternateSegments) self.assertTrue(os.path.exists(path) or os.path.exists(packagePath), "Module {0} does not exist".format(module))
All modules listed in L{notPortedModules} exist on Py2.
test_exist
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_dist3.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_dist3.py
MIT
def test_notexist(self): """ All modules listed in L{notPortedModules} do not exist on Py3. """ root = os.path.dirname(os.path.dirname(twisted.__file__)) for module in notPortedModules: segments = module.split(".") segments[-1] += ".py" path = os.path.join(root, *segments) alternateSegments = module.split(".") + ["__init__.py"] packagePath = os.path.join(root, *alternateSegments) self.assertFalse(os.path.exists(path) or os.path.exists(packagePath), "Module {0} exists".format(module))
All modules listed in L{notPortedModules} do not exist on Py3.
test_notexist
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_dist3.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_dist3.py
MIT
def replaceSysPath(self, sysPath): """ Replace sys.path, for the duration of the test, with the given value. """ originalSysPath = sys.path[:] def cleanUpSysPath(): sys.path[:] = originalSysPath self.addCleanup(cleanUpSysPath) sys.path[:] = sysPath
Replace sys.path, for the duration of the test, with the given value.
replaceSysPath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/modules_helpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/modules_helpers.py
MIT
def replaceSysModules(self, sysModules): """ Replace sys.modules, for the duration of the test, with the given value. """ originalSysModules = sys.modules.copy() def cleanUpSysModules(): sys.modules.clear() sys.modules.update(originalSysModules) self.addCleanup(cleanUpSysModules) sys.modules.clear() sys.modules.update(sysModules)
Replace sys.modules, for the duration of the test, with the given value.
replaceSysModules
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/modules_helpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/modules_helpers.py
MIT
def pathEntryWithOnePackage(self, pkgname="test_package"): """ Generate a L{FilePath} with one package, named C{pkgname}, on it, and return the L{FilePath} of the path entry. """ entry = FilePath(self.mktemp()) pkg = entry.child("test_package") pkg.makedirs() pkg.child("__init__.py").setContent(b"") return entry
Generate a L{FilePath} with one package, named C{pkgname}, on it, and return the L{FilePath} of the path entry.
pathEntryWithOnePackage
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/modules_helpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/modules_helpers.py
MIT
def test_shortPythonVersion(self): """ Verify if the Python version is returned correctly. """ ver = shortPythonVersion().split('.') for i in range(3): self.assertEqual(int(ver[i]), sys.version_info[i])
Verify if the Python version is returned correctly.
test_shortPythonVersion
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def test_isKnown(self): """ L{Platform.isKnown} returns a boolean indicating whether this is one of the L{runtime.knownPlatforms}. """ platform = Platform() self.assertTrue(platform.isKnown())
L{Platform.isKnown} returns a boolean indicating whether this is one of the L{runtime.knownPlatforms}.
test_isKnown
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def test_isVistaConsistency(self): """ Verify consistency of L{Platform.isVista}: it can only be C{True} if L{Platform.isWinNT} and L{Platform.isWindows} are C{True}. """ platform = Platform() if platform.isVista(): self.assertTrue(platform.isWinNT()) self.assertTrue(platform.isWindows()) self.assertFalse(platform.isMacOSX())
Verify consistency of L{Platform.isVista}: it can only be C{True} if L{Platform.isWinNT} and L{Platform.isWindows} are C{True}.
test_isVistaConsistency
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def test_isMacOSXConsistency(self): """ L{Platform.isMacOSX} can only return C{True} if L{Platform.getType} returns C{'posix'}. """ platform = Platform() if platform.isMacOSX(): self.assertEqual(platform.getType(), 'posix')
L{Platform.isMacOSX} can only return C{True} if L{Platform.getType} returns C{'posix'}.
test_isMacOSXConsistency
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def test_isLinuxConsistency(self): """ L{Platform.isLinux} can only return C{True} if L{Platform.getType} returns C{'posix'} and L{sys.platform} starts with C{"linux"}. """ platform = Platform() if platform.isLinux(): self.assertTrue(sys.platform.startswith("linux"))
L{Platform.isLinux} can only return C{True} if L{Platform.getType} returns C{'posix'} and L{sys.platform} starts with C{"linux"}.
test_isLinuxConsistency
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def test_isWinNT(self): """ L{Platform.isWinNT} can return only C{False} or C{True} and can not return C{True} if L{Platform.getType} is not C{"win32"}. """ platform = Platform() isWinNT = platform.isWinNT() self.assertIn(isWinNT, (False, True)) if platform.getType() != "win32": self.assertFalse(isWinNT)
L{Platform.isWinNT} can return only C{False} or C{True} and can not return C{True} if L{Platform.getType} is not C{"win32"}.
test_isWinNT
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def test_isWinNTDeprecated(self): """ L{Platform.isWinNT} is deprecated in favor of L{platform.isWindows}. """ platform = Platform() platform.isWinNT() warnings = self.flushWarnings([self.test_isWinNTDeprecated]) self.assertEqual(len(warnings), 1) self.assertEqual( warnings[0]['message'], self.isWinNTDeprecationMessage)
L{Platform.isWinNT} is deprecated in favor of L{platform.isWindows}.
test_isWinNTDeprecated
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def test_supportsThreads(self): """ L{Platform.supportsThreads} returns C{True} if threads can be created in this runtime, C{False} otherwise. """ # It's difficult to test both cases of this without faking the threading # module. Perhaps an adequate test is to just test the behavior with # the current runtime, whatever that happens to be. try: namedModule('threading') except ImportError: self.assertFalse(Platform().supportsThreads()) else: self.assertTrue(Platform().supportsThreads())
L{Platform.supportsThreads} returns C{True} if threads can be created in this runtime, C{False} otherwise.
test_supportsThreads
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def test_getType(self): """ If an operating system name is supplied to L{Platform}'s initializer, L{Platform.getType} returns the platform type which corresponds to that name. """ self.assertEqual(Platform('nt').getType(), 'win32') self.assertEqual(Platform('ce').getType(), 'win32') self.assertEqual(Platform('posix').getType(), 'posix') self.assertEqual(Platform('java').getType(), 'java')
If an operating system name is supplied to L{Platform}'s initializer, L{Platform.getType} returns the platform type which corresponds to that name.
test_getType
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def test_isMacOSX(self): """ If a system platform name is supplied to L{Platform}'s initializer, it is used to determine the result of L{Platform.isMacOSX}, which returns C{True} for C{"darwin"}, C{False} otherwise. """ self.assertTrue(Platform(None, 'darwin').isMacOSX()) self.assertFalse(Platform(None, 'linux2').isMacOSX()) self.assertFalse(Platform(None, 'win32').isMacOSX())
If a system platform name is supplied to L{Platform}'s initializer, it is used to determine the result of L{Platform.isMacOSX}, which returns C{True} for C{"darwin"}, C{False} otherwise.
test_isMacOSX
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def test_isLinux(self): """ If a system platform name is supplied to L{Platform}'s initializer, it is used to determine the result of L{Platform.isLinux}, which returns C{True} for values beginning with C{"linux"}, C{False} otherwise. """ self.assertFalse(Platform(None, 'darwin').isLinux()) self.assertTrue(Platform(None, 'linux').isLinux()) self.assertTrue(Platform(None, 'linux2').isLinux()) self.assertTrue(Platform(None, 'linux3').isLinux()) self.assertFalse(Platform(None, 'win32').isLinux())
If a system platform name is supplied to L{Platform}'s initializer, it is used to determine the result of L{Platform.isLinux}, which returns C{True} for values beginning with C{"linux"}, C{False} otherwise.
test_isLinux
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def test_noChecksOnLinux(self): """ If the platform is not Linux, C{isDocker()} always returns L{False}. """ platform = Platform(None, 'win32') self.assertFalse(platform.isDocker())
If the platform is not Linux, C{isDocker()} always returns L{False}.
test_noChecksOnLinux
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def test_noCGroups(self): """ If the platform is Linux, and the cgroups file in C{/proc} does not exist, C{isDocker()} returns L{False} """ platform = Platform(None, 'linux') self.assertFalse(platform.isDocker(_initCGroupLocation="fakepath"))
If the platform is Linux, and the cgroups file in C{/proc} does not exist, C{isDocker()} returns L{False}
test_noCGroups
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def test_cgroupsSuggestsDocker(self): """ If the platform is Linux, and the cgroups file (faked out here) exists, and one of the paths starts with C{/docker/}, C{isDocker()} returns C{True}. """ cgroupsFile = self.mktemp() with open(cgroupsFile, 'wb') as f: # real cgroups file from inside a Debian 7 docker container f.write(b"""10:debug:/ 9:net_prio:/ 8:perf_event:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f 7:net_cls:/ 6:freezer:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f 5:devices:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f 4:blkio:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f 3:cpuacct:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f 2:cpu:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f 1:cpuset:/docker/104155a6453cb67590027e397dc90fc25a06a7508403c797bc89ea43adf8d35f""") platform = Platform(None, 'linux') self.assertTrue(platform.isDocker(_initCGroupLocation=cgroupsFile))
If the platform is Linux, and the cgroups file (faked out here) exists, and one of the paths starts with C{/docker/}, C{isDocker()} returns C{True}.
test_cgroupsSuggestsDocker
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def test_cgroupsSuggestsRealSystem(self): """ If the platform is Linux, and the cgroups file (faked out here) exists, and none of the paths starts with C{/docker/}, C{isDocker()} returns C{False}. """ cgroupsFile = self.mktemp() with open(cgroupsFile, 'wb') as f: # real cgroups file from a Fedora 17 system f.write(b"""9:perf_event:/ 8:blkio:/ 7:net_cls:/ 6:freezer:/ 5:devices:/ 4:memory:/ 3:cpuacct,cpu:/ 2:cpuset:/ 1:name=systemd:/system""") platform = Platform(None, 'linux') self.assertFalse(platform.isDocker(_initCGroupLocation=cgroupsFile))
If the platform is Linux, and the cgroups file (faked out here) exists, and none of the paths starts with C{/docker/}, C{isDocker()} returns C{False}.
test_cgroupsSuggestsRealSystem
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_runtime.py
MIT
def get(self): """ Get a known value. """ return self.value
Get a known value.
get
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def _makeProxy(self, **attrs): """ Create a temporary module proxy object. @param **kw: Attributes to initialise on the temporary module object @rtype: L{twistd.python.deprecate._ModuleProxy} """ mod = types.ModuleType('foo') for key, value in attrs.items(): setattr(mod, key, value) return deprecate._ModuleProxy(mod)
Create a temporary module proxy object. @param **kw: Attributes to initialise on the temporary module object @rtype: L{twistd.python.deprecate._ModuleProxy}
_makeProxy
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_getattrPassthrough(self): """ Getting a normal attribute on a L{twisted.python.deprecate._ModuleProxy} retrieves the underlying attribute's value, and raises C{AttributeError} if a non-existent attribute is accessed. """ proxy = self._makeProxy(SOME_ATTRIBUTE='hello') self.assertIs(proxy.SOME_ATTRIBUTE, 'hello') self.assertRaises(AttributeError, getattr, proxy, 'DOES_NOT_EXIST')
Getting a normal attribute on a L{twisted.python.deprecate._ModuleProxy} retrieves the underlying attribute's value, and raises C{AttributeError} if a non-existent attribute is accessed.
test_getattrPassthrough
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_getattrIntercept(self): """ Getting an attribute marked as being deprecated on L{twisted.python.deprecate._ModuleProxy} results in calling the deprecated wrapper's C{get} method. """ proxy = self._makeProxy() _deprecatedAttributes = object.__getattribute__( proxy, '_deprecatedAttributes') _deprecatedAttributes['foo'] = _MockDeprecatedAttribute(42) self.assertEqual(proxy.foo, 42)
Getting an attribute marked as being deprecated on L{twisted.python.deprecate._ModuleProxy} results in calling the deprecated wrapper's C{get} method.
test_getattrIntercept
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_privateAttributes(self): """ Private attributes of L{twisted.python.deprecate._ModuleProxy} are inaccessible when regular attribute access is used. """ proxy = self._makeProxy() self.assertRaises(AttributeError, getattr, proxy, '_module') self.assertRaises( AttributeError, getattr, proxy, '_deprecatedAttributes')
Private attributes of L{twisted.python.deprecate._ModuleProxy} are inaccessible when regular attribute access is used.
test_privateAttributes
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_setattr(self): """ Setting attributes on L{twisted.python.deprecate._ModuleProxy} proxies them through to the wrapped module. """ proxy = self._makeProxy() proxy._module = 1 self.assertNotEqual(object.__getattribute__(proxy, '_module'), 1) self.assertEqual(proxy._module, 1)
Setting attributes on L{twisted.python.deprecate._ModuleProxy} proxies them through to the wrapped module.
test_setattr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_repr(self): """ L{twisted.python.deprecated._ModuleProxy.__repr__} produces a string containing the proxy type and a representation of the wrapped module object. """ proxy = self._makeProxy() realModule = object.__getattribute__(proxy, '_module') self.assertEqual( repr(proxy), '<%s module=%r>' % (type(proxy).__name__, realModule))
L{twisted.python.deprecated._ModuleProxy.__repr__} produces a string containing the proxy type and a representation of the wrapped module object.
test_repr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def _getWarningString(self, attr): """ Create the warning string used by deprecated attributes. """ return _getDeprecationWarningString( deprecatedattributes.__name__ + '.' + attr, deprecatedattributes.version, DEPRECATION_WARNING_FORMAT + ': ' + deprecatedattributes.message)
Create the warning string used by deprecated attributes.
_getWarningString
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_deprecatedAttributeHelper(self): """ L{twisted.python.deprecate._DeprecatedAttribute} correctly sets its __name__ to match that of the deprecated attribute and emits a warning when the original attribute value is accessed. """ name = 'ANOTHER_DEPRECATED_ATTRIBUTE' setattr(deprecatedattributes, name, 42) attr = deprecate._DeprecatedAttribute( deprecatedattributes, name, self.version, self.message) self.assertEqual(attr.__name__, name) # Since we're accessing the value getter directly, as opposed to via # the module proxy, we need to match the warning's stack level. def addStackLevel(): attr.get() # Access the deprecated attribute. addStackLevel() warningsShown = self.flushWarnings([ self.test_deprecatedAttributeHelper]) self.assertIs(warningsShown[0]['category'], DeprecationWarning) self.assertEqual( warningsShown[0]['message'], self._getWarningString(name)) self.assertEqual(len(warningsShown), 1)
L{twisted.python.deprecate._DeprecatedAttribute} correctly sets its __name__ to match that of the deprecated attribute and emits a warning when the original attribute value is accessed.
test_deprecatedAttributeHelper
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_deprecatedAttribute(self): """ L{twisted.python.deprecate.deprecatedModuleAttribute} wraps a module-level attribute in an object that emits a deprecation warning when it is accessed the first time only, while leaving other unrelated attributes alone. """ # Accessing non-deprecated attributes does not issue a warning. deprecatedattributes.ANOTHER_ATTRIBUTE warningsShown = self.flushWarnings([self.test_deprecatedAttribute]) self.assertEqual(len(warningsShown), 0) name = 'DEPRECATED_ATTRIBUTE' # Access the deprecated attribute. This uses getattr to avoid repeating # the attribute name. getattr(deprecatedattributes, name) warningsShown = self.flushWarnings([self.test_deprecatedAttribute]) self.assertEqual(len(warningsShown), 1) self.assertIs(warningsShown[0]['category'], DeprecationWarning) self.assertEqual( warningsShown[0]['message'], self._getWarningString(name))
L{twisted.python.deprecate.deprecatedModuleAttribute} wraps a module-level attribute in an object that emits a deprecation warning when it is accessed the first time only, while leaving other unrelated attributes alone.
test_deprecatedAttribute
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_wrappedModule(self): """ Deprecating an attribute in a module replaces and wraps that module instance, in C{sys.modules}, with a L{twisted.python.deprecate._ModuleProxy} instance but only if it hasn't already been wrapped. """ sys.modules[self._testModuleName] = mod = types.ModuleType('foo') self.addCleanup(sys.modules.pop, self._testModuleName) setattr(mod, 'first', 1) setattr(mod, 'second', 2) deprecate.deprecatedModuleAttribute( Version('Twisted', 8, 0, 0), 'message', self._testModuleName, 'first') proxy = sys.modules[self._testModuleName] self.assertNotEqual(proxy, mod) deprecate.deprecatedModuleAttribute( Version('Twisted', 8, 0, 0), 'message', self._testModuleName, 'second') self.assertIs(proxy, sys.modules[self._testModuleName])
Deprecating an attribute in a module replaces and wraps that module instance, in C{sys.modules}, with a L{twisted.python.deprecate._ModuleProxy} instance but only if it hasn't already been wrapped.
test_wrappedModule
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def pathEntryTree(self, tree): """ Create some files in a hierarchy, based on a dictionary describing those files. The resulting hierarchy will be placed onto sys.path for the duration of the test. @param tree: A dictionary representing a directory structure. Keys are strings, representing filenames, dictionary values represent directories, string values represent file contents. @return: another dictionary similar to the input, with file content strings replaced with L{FilePath} objects pointing at where those contents are now stored. """ def makeSomeFiles(pathobj, dirdict): pathdict = {} for (key, value) in dirdict.items(): child = pathobj.child(key) if isinstance(value, bytes): pathdict[key] = child child.setContent(value) elif isinstance(value, dict): child.createDirectory() pathdict[key] = makeSomeFiles(child, value) else: raise ValueError("only strings and dicts allowed as values") return pathdict base = FilePath(self.mktemp().encode("utf-8")) base.makedirs() result = makeSomeFiles(base, tree) # On Python 3, sys.path cannot include byte paths: self.replaceSysPath([base.path.decode("utf-8")] + sys.path) self.replaceSysModules(sys.modules.copy()) return result
Create some files in a hierarchy, based on a dictionary describing those files. The resulting hierarchy will be placed onto sys.path for the duration of the test. @param tree: A dictionary representing a directory structure. Keys are strings, representing filenames, dictionary values represent directories, string values represent file contents. @return: another dictionary similar to the input, with file content strings replaced with L{FilePath} objects pointing at where those contents are now stored.
pathEntryTree
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def simpleModuleEntry(self): """ Add a sample module and package to the path, returning a L{FilePath} pointing at the module which will be loadable as C{package.module}. """ paths = self.pathEntryTree( {b"package": {b"__init__.py": self._packageInit.encode("utf-8"), b"module.py": b""}}) return paths[b'package'][b'module.py']
Add a sample module and package to the path, returning a L{FilePath} pointing at the module which will be loadable as C{package.module}.
simpleModuleEntry
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def checkOneWarning(self, modulePath): """ Verification logic for L{test_deprecatedModule}. """ from package import module self.assertEqual(FilePath(module.__file__.encode("utf-8")), modulePath) emitted = self.flushWarnings([self.checkOneWarning]) self.assertEqual(len(emitted), 1) self.assertEqual(emitted[0]['message'], 'package.module was deprecated in Package 1.2.3: ' 'message') self.assertEqual(emitted[0]['category'], DeprecationWarning)
Verification logic for L{test_deprecatedModule}.
checkOneWarning
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_deprecatedModule(self): """ If L{deprecatedModuleAttribute} is used to deprecate a module attribute of a package, only one deprecation warning is emitted when the deprecated module is imported. """ self.checkOneWarning(self.simpleModuleEntry())
If L{deprecatedModuleAttribute} is used to deprecate a module attribute of a package, only one deprecation warning is emitted when the deprecated module is imported.
test_deprecatedModule
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_deprecatedModuleMultipleTimes(self): """ If L{deprecatedModuleAttribute} is used to deprecate a module attribute of a package, only one deprecation warning is emitted when the deprecated module is subsequently imported. """ mp = self.simpleModuleEntry() # The first time, the code needs to be loaded. self.checkOneWarning(mp) # The second time, things are slightly different; the object's already # in the namespace. self.checkOneWarning(mp) # The third and fourth times, things things should all be exactly the # same, but this is a sanity check to make sure the implementation isn't # special casing the second time. Also, putting these cases into a loop # means that the stack will be identical, to make sure that the # implementation doesn't rely too much on stack-crawling. for x in range(2): self.checkOneWarning(mp)
If L{deprecatedModuleAttribute} is used to deprecate a module attribute of a package, only one deprecation warning is emitted when the deprecated module is subsequently imported.
test_deprecatedModuleMultipleTimes
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def setUp(self): """ Create a file that will have known line numbers when emitting warnings. """ self.package = FilePath(self.mktemp().encode("utf-8") ).child(b'twisted_private_helper') self.package.makedirs() self.package.child(b'__init__.py').setContent(b'') self.package.child(b'module.py').setContent(b''' "A module string" from twisted.python import deprecate def testFunction(): "A doc string" a = 1 + 2 return a def callTestFunction(): b = testFunction() if b == 3: deprecate.warnAboutFunction(testFunction, "A Warning String") ''') # Python 3 doesn't accept bytes in sys.path: packagePath = self.package.parent().path.decode("utf-8") sys.path.insert(0, packagePath) self.addCleanup(sys.path.remove, packagePath) modules = sys.modules.copy() self.addCleanup( lambda: (sys.modules.clear(), sys.modules.update(modules))) # On Windows on Python 3, most FilePath interactions produce # DeprecationWarnings, so flush them here so that they don't interfere # with the tests. if platform.isWindows() and _PY3: self.flushWarnings()
Create a file that will have known line numbers when emitting warnings.
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_warning(self): """ L{deprecate.warnAboutFunction} emits a warning the file and line number of which point to the beginning of the implementation of the function passed to it. """ def aFunc(): pass deprecate.warnAboutFunction(aFunc, 'A Warning Message') warningsShown = self.flushWarnings() filename = __file__ if filename.lower().endswith('.pyc'): filename = filename[:-1] self.assertSamePath( FilePath(warningsShown[0]["filename"]), FilePath(filename)) self.assertEqual(warningsShown[0]["message"], "A Warning Message")
L{deprecate.warnAboutFunction} emits a warning the file and line number of which point to the beginning of the implementation of the function passed to it.
test_warning
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_warningLineNumber(self): """ L{deprecate.warnAboutFunction} emits a C{DeprecationWarning} with the number of a line within the implementation of the function passed to it. """ from twisted_private_helper import module module.callTestFunction() warningsShown = self.flushWarnings() self.assertSamePath( FilePath(warningsShown[0]["filename"].encode("utf-8")), self.package.sibling(b'twisted_private_helper').child(b'module.py')) # Line number 9 is the last line in the testFunction in the helper # module. self.assertEqual(warningsShown[0]["lineno"], 9) self.assertEqual(warningsShown[0]["message"], "A Warning String") self.assertEqual(len(warningsShown), 1)
L{deprecate.warnAboutFunction} emits a C{DeprecationWarning} with the number of a line within the implementation of the function passed to it.
test_warningLineNumber
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def assertSamePath(self, first, second): """ Assert that the two paths are the same, considering case normalization appropriate for the current platform. @type first: L{FilePath} @type second: L{FilePath} @raise C{self.failureType}: If the paths are not the same. """ self.assertTrue( normcase(first.path) == normcase(second.path), "%r != %r" % (first, second))
Assert that the two paths are the same, considering case normalization appropriate for the current platform. @type first: L{FilePath} @type second: L{FilePath} @raise C{self.failureType}: If the paths are not the same.
assertSamePath
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_renamedFile(self): """ Even if the implementation of a deprecated function is moved around on the filesystem, the line number in the warning emitted by L{deprecate.warnAboutFunction} points to a line in the implementation of the deprecated function. """ from twisted_private_helper import module # Clean up the state resulting from that import; we're not going to use # this module, so it should go away. del sys.modules['twisted_private_helper'] del sys.modules[module.__name__] # Rename the source directory self.package.moveTo(self.package.sibling(b'twisted_renamed_helper')) # Make sure importlib notices we've changed importable packages: if invalidate_caches: invalidate_caches() # Import the newly renamed version from twisted_renamed_helper import module self.addCleanup(sys.modules.pop, 'twisted_renamed_helper') self.addCleanup(sys.modules.pop, module.__name__) module.callTestFunction() warningsShown = self.flushWarnings([module.testFunction]) warnedPath = FilePath(warningsShown[0]["filename"].encode("utf-8")) expectedPath = self.package.sibling( b'twisted_renamed_helper').child(b'module.py') self.assertSamePath(warnedPath, expectedPath) self.assertEqual(warningsShown[0]["lineno"], 9) self.assertEqual(warningsShown[0]["message"], "A Warning String") self.assertEqual(len(warningsShown), 1)
Even if the implementation of a deprecated function is moved around on the filesystem, the line number in the warning emitted by L{deprecate.warnAboutFunction} points to a line in the implementation of the deprecated function.
test_renamedFile
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_filteredWarning(self): """ L{deprecate.warnAboutFunction} emits a warning that will be filtered if L{warnings.filterwarning} is called with the module name of the deprecated function. """ # Clean up anything *else* that might spuriously filter out the warning, # such as the "always" simplefilter set up by unittest._collectWarnings. # We'll also rely on trial to restore the original filters afterwards. del warnings.filters[:] warnings.filterwarnings( action="ignore", module="twisted_private_helper") from twisted_private_helper import module module.callTestFunction() warningsShown = self.flushWarnings() self.assertEqual(len(warningsShown), 0)
L{deprecate.warnAboutFunction} emits a warning that will be filtered if L{warnings.filterwarning} is called with the module name of the deprecated function.
test_filteredWarning
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_filteredOnceWarning(self): """ L{deprecate.warnAboutFunction} emits a warning that will be filtered once if L{warnings.filterwarning} is called with the module name of the deprecated function and an action of once. """ # Clean up anything *else* that might spuriously filter out the warning, # such as the "always" simplefilter set up by unittest._collectWarnings. # We'll also rely on trial to restore the original filters afterwards. del warnings.filters[:] warnings.filterwarnings( action="module", module="twisted_private_helper") from twisted_private_helper import module module.callTestFunction() module.callTestFunction() warningsShown = self.flushWarnings() self.assertEqual(len(warningsShown), 1) message = warningsShown[0]['message'] category = warningsShown[0]['category'] filename = warningsShown[0]['filename'] lineno = warningsShown[0]['lineno'] msg = warnings.formatwarning(message, category, filename, lineno) self.assertTrue( msg.endswith("module.py:9: DeprecationWarning: A Warning String\n" " return a\n"), "Unexpected warning string: %r" % (msg,))
L{deprecate.warnAboutFunction} emits a warning that will be filtered once if L{warnings.filterwarning} is called with the module name of the deprecated function and an action of once.
test_filteredOnceWarning
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def dummyCallable(): """ Do nothing. This is used to test the deprecation decorators. """
Do nothing. This is used to test the deprecation decorators.
dummyCallable
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def dummyReplacementMethod(): """ Do nothing. This is used to test the replacement parameter to L{deprecated}. """
Do nothing. This is used to test the replacement parameter to L{deprecated}.
dummyReplacementMethod
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_getDeprecationWarningString(self): """ L{getDeprecationWarningString} returns a string that tells us that a callable was deprecated at a certain released version of Twisted. """ version = Version('Twisted', 8, 0, 0) self.assertEqual( getDeprecationWarningString(self.test_getDeprecationWarningString, version), "%s.DeprecationWarningsTests.test_getDeprecationWarningString " "was deprecated in Twisted 8.0.0" % (__name__,))
L{getDeprecationWarningString} returns a string that tells us that a callable was deprecated at a certain released version of Twisted.
test_getDeprecationWarningString
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_getDeprecationWarningStringWithFormat(self): """ L{getDeprecationWarningString} returns a string that tells us that a callable was deprecated at a certain released version of Twisted, with a message containing additional information about the deprecation. """ version = Version('Twisted', 8, 0, 0) format = DEPRECATION_WARNING_FORMAT + ': This is a message' self.assertEqual( getDeprecationWarningString(self.test_getDeprecationWarningString, version, format), '%s.DeprecationWarningsTests.test_getDeprecationWarningString was ' 'deprecated in Twisted 8.0.0: This is a message' % (__name__,))
L{getDeprecationWarningString} returns a string that tells us that a callable was deprecated at a certain released version of Twisted, with a message containing additional information about the deprecation.
test_getDeprecationWarningStringWithFormat
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_deprecateEmitsWarning(self): """ Decorating a callable with L{deprecated} emits a warning. """ version = Version('Twisted', 8, 0, 0) dummy = deprecated(version)(dummyCallable) def addStackLevel(): dummy() with catch_warnings(record=True) as caught: simplefilter("always") addStackLevel() self.assertEqual(caught[0].category, DeprecationWarning) self.assertEqual(str(caught[0].message), getDeprecationWarningString(dummyCallable, version)) # rstrip in case .pyc/.pyo self.assertEqual(caught[0].filename.rstrip('co'), __file__.rstrip('co'))
Decorating a callable with L{deprecated} emits a warning.
test_deprecateEmitsWarning
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_deprecatedPreservesName(self): """ The decorated function has the same name as the original. """ version = Version('Twisted', 8, 0, 0) dummy = deprecated(version)(dummyCallable) self.assertEqual(dummyCallable.__name__, dummy.__name__) self.assertEqual(fullyQualifiedName(dummyCallable), fullyQualifiedName(dummy))
The decorated function has the same name as the original.
test_deprecatedPreservesName
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_getDeprecationDocstring(self): """ L{_getDeprecationDocstring} returns a note about the deprecation to go into a docstring. """ version = Version('Twisted', 8, 0, 0) self.assertEqual( "Deprecated in Twisted 8.0.0.", _getDeprecationDocstring(version, ''))
L{_getDeprecationDocstring} returns a note about the deprecation to go into a docstring.
test_getDeprecationDocstring
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def localDummyCallable(): """ Do nothing. This is used to test the deprecation decorators. """
Do nothing. This is used to test the deprecation decorators.
test_deprecatedUpdatesDocstring.localDummyCallable
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_deprecatedUpdatesDocstring(self): """ The docstring of the deprecated function is appended with information about the deprecation. """ def localDummyCallable(): """ Do nothing. This is used to test the deprecation decorators. """ version = Version('Twisted', 8, 0, 0) dummy = deprecated(version)(localDummyCallable) _appendToDocstring( localDummyCallable, _getDeprecationDocstring(version, '')) self.assertEqual(localDummyCallable.__doc__, dummy.__doc__)
The docstring of the deprecated function is appended with information about the deprecation.
test_deprecatedUpdatesDocstring
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_versionMetadata(self): """ Deprecating a function adds version information to the decorated version of that function. """ version = Version('Twisted', 8, 0, 0) dummy = deprecated(version)(dummyCallable) self.assertEqual(version, dummy.deprecatedVersion)
Deprecating a function adds version information to the decorated version of that function.
test_versionMetadata
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_getDeprecationWarningStringReplacement(self): """ L{getDeprecationWarningString} takes an additional replacement parameter that can be used to add information to the deprecation. If the replacement parameter is a string, it will be interpolated directly into the result. """ version = Version('Twisted', 8, 0, 0) warningString = getDeprecationWarningString( self.test_getDeprecationWarningString, version, replacement="something.foobar") self.assertEqual( warningString, "%s was deprecated in Twisted 8.0.0; please use something.foobar " "instead" % ( fullyQualifiedName(self.test_getDeprecationWarningString),))
L{getDeprecationWarningString} takes an additional replacement parameter that can be used to add information to the deprecation. If the replacement parameter is a string, it will be interpolated directly into the result.
test_getDeprecationWarningStringReplacement
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_getDeprecationWarningStringReplacementWithCallable(self): """ L{getDeprecationWarningString} takes an additional replacement parameter that can be used to add information to the deprecation. If the replacement parameter is a callable, its fully qualified name will be interpolated into the result. """ version = Version('Twisted', 8, 0, 0) warningString = getDeprecationWarningString( self.test_getDeprecationWarningString, version, replacement=dummyReplacementMethod) self.assertEqual( warningString, "%s was deprecated in Twisted 8.0.0; please use " "%s.dummyReplacementMethod instead" % ( fullyQualifiedName(self.test_getDeprecationWarningString), __name__))
L{getDeprecationWarningString} takes an additional replacement parameter that can be used to add information to the deprecation. If the replacement parameter is a callable, its fully qualified name will be interpolated into the result.
test_getDeprecationWarningStringReplacementWithCallable
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def someProperty(self): """ Getter docstring. @return: The property. """ return self._someProtectedValue
Getter docstring. @return: The property.
someProperty
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def someProperty(self, value): """ Setter docstring. """ self._someProtectedValue = value
Setter docstring.
someProperty
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def assertDocstring(self, target, expected): """ Check that C{target} object has the C{expected} docstring lines. @param target: Object which is checked. @type target: C{anything} @param expected: List of lines, ignoring empty lines or leading or trailing spaces. @type expected: L{list} or L{str} """ self.assertEqual( expected, [x.strip() for x in target.__doc__.splitlines() if x.strip()] )
Check that C{target} object has the C{expected} docstring lines. @param target: Object which is checked. @type target: C{anything} @param expected: List of lines, ignoring empty lines or leading or trailing spaces. @type expected: L{list} or L{str}
assertDocstring
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_propertyGetter(self): """ When L{deprecatedProperty} is used on a C{property}, accesses raise a L{DeprecationWarning} and getter docstring is updated to inform the version in which it was deprecated. C{deprecatedVersion} attribute is also set to inform the deprecation version. """ obj = ClassWithDeprecatedProperty() obj.someProperty self.assertDocstring( ClassWithDeprecatedProperty.someProperty, [ 'Getter docstring.', '@return: The property.', 'Deprecated in Twisted 1.2.3.', ], ) ClassWithDeprecatedProperty.someProperty.deprecatedVersion = Version( 'Twisted', 1, 2, 3) message = ( 'twisted.python.test.test_deprecate.ClassWithDeprecatedProperty.' 'someProperty was deprecated in Twisted 1.2.3' ) warnings = self.flushWarnings([self.test_propertyGetter]) self.assertEqual(1, len(warnings)) self.assertEqual(DeprecationWarning, warnings[0]['category']) self.assertEqual(message, warnings[0]['message'])
When L{deprecatedProperty} is used on a C{property}, accesses raise a L{DeprecationWarning} and getter docstring is updated to inform the version in which it was deprecated. C{deprecatedVersion} attribute is also set to inform the deprecation version.
test_propertyGetter
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_propertySetter(self): """ When L{deprecatedProperty} is used on a C{property}, setter accesses raise a L{DeprecationWarning}. """ newValue = object() obj = ClassWithDeprecatedProperty() obj.someProperty = newValue self.assertIs(newValue, obj._someProtectedValue) message = ( 'twisted.python.test.test_deprecate.ClassWithDeprecatedProperty.' 'someProperty was deprecated in Twisted 1.2.3' ) warnings = self.flushWarnings([self.test_propertySetter]) self.assertEqual(1, len(warnings)) self.assertEqual(DeprecationWarning, warnings[0]['category']) self.assertEqual(message, warnings[0]['message'])
When L{deprecatedProperty} is used on a C{property}, setter accesses raise a L{DeprecationWarning}.
test_propertySetter
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_class(self): """ When L{deprecated} is used on a class, instantiations raise a L{DeprecationWarning} and class's docstring is updated to inform the version in which it was deprecated. C{deprecatedVersion} attribute is also set to inform the deprecation version. """ DeprecatedClass() self.assertDocstring( DeprecatedClass, [('Class which is entirely deprecated without having a ' 'replacement.'), 'Deprecated in Twisted 1.2.3.'], ) DeprecatedClass.deprecatedVersion = Version('Twisted', 1, 2, 3) message = ( 'twisted.python.test.test_deprecate.DeprecatedClass ' 'was deprecated in Twisted 1.2.3' ) warnings = self.flushWarnings([self.test_class]) self.assertEqual(1, len(warnings)) self.assertEqual(DeprecationWarning, warnings[0]['category']) self.assertEqual(message, warnings[0]['message'])
When L{deprecated} is used on a class, instantiations raise a L{DeprecationWarning} and class's docstring is updated to inform the version in which it was deprecated. C{deprecatedVersion} attribute is also set to inform the deprecation version.
test_class
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_deprecatedReplacement(self): """ L{deprecated} takes an additional replacement parameter that can be used to indicate the new, non-deprecated method developers should use. If the replacement parameter is a string, it will be interpolated directly into the warning message. """ version = Version('Twisted', 8, 0, 0) dummy = deprecated(version, "something.foobar")(dummyCallable) self.assertEqual(dummy.__doc__, "\n" " Do nothing.\n\n" " This is used to test the deprecation decorators.\n\n" " Deprecated in Twisted 8.0.0; please use " "something.foobar" " instead.\n" " ")
L{deprecated} takes an additional replacement parameter that can be used to indicate the new, non-deprecated method developers should use. If the replacement parameter is a string, it will be interpolated directly into the warning message.
test_deprecatedReplacement
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_deprecatedReplacementWithCallable(self): """ L{deprecated} takes an additional replacement parameter that can be used to indicate the new, non-deprecated method developers should use. If the replacement parameter is a callable, its fully qualified name will be interpolated into the warning message. """ version = Version('Twisted', 8, 0, 0) decorator = deprecated(version, replacement=dummyReplacementMethod) dummy = decorator(dummyCallable) self.assertEqual(dummy.__doc__, "\n" " Do nothing.\n\n" " This is used to test the deprecation decorators.\n\n" " Deprecated in Twisted 8.0.0; please use " "%s.dummyReplacementMethod instead.\n" " " % (__name__,))
L{deprecated} takes an additional replacement parameter that can be used to indicate the new, non-deprecated method developers should use. If the replacement parameter is a callable, its fully qualified name will be interpolated into the warning message.
test_deprecatedReplacementWithCallable
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_appendToEmptyDocstring(self): """ Appending to an empty docstring simply replaces the docstring. """ def noDocstring(): pass _appendToDocstring(noDocstring, "Appended text.") self.assertEqual("Appended text.", noDocstring.__doc__)
Appending to an empty docstring simply replaces the docstring.
test_appendToEmptyDocstring
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def singleLineDocstring(): """This doesn't comply with standards, but is here for a test."""
This doesn't comply with standards, but is here for a test.
test_appendToSingleLineDocstring.singleLineDocstring
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_appendToSingleLineDocstring(self): """ Appending to a single line docstring places the message on a new line, with a blank line separating it from the rest of the docstring. The docstring ends with a newline, conforming to Twisted and PEP 8 standards. Unfortunately, the indentation is incorrect, since the existing docstring doesn't have enough info to help us indent properly. """ def singleLineDocstring(): """This doesn't comply with standards, but is here for a test.""" _appendToDocstring(singleLineDocstring, "Appended text.") self.assertEqual( ["This doesn't comply with standards, but is here for a test.", "", "Appended text."], singleLineDocstring.__doc__.splitlines()) self.assertTrue(singleLineDocstring.__doc__.endswith('\n'))
Appending to a single line docstring places the message on a new line, with a blank line separating it from the rest of the docstring. The docstring ends with a newline, conforming to Twisted and PEP 8 standards. Unfortunately, the indentation is incorrect, since the existing docstring doesn't have enough info to help us indent properly.
test_appendToSingleLineDocstring
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def multiLineDocstring(): """ This is a multi-line docstring. """
This is a multi-line docstring.
test_appendToMultilineDocstring.multiLineDocstring
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def expectedDocstring(): """ This is a multi-line docstring. Appended text. """
This is a multi-line docstring. Appended text.
test_appendToMultilineDocstring.expectedDocstring
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_appendToMultilineDocstring(self): """ Appending to a multi-line docstring places the messade on a new line, with a blank line separating it from the rest of the docstring. Because we have multiple lines, we have enough information to do indentation. """ def multiLineDocstring(): """ This is a multi-line docstring. """ def expectedDocstring(): """ This is a multi-line docstring. Appended text. """ _appendToDocstring(multiLineDocstring, "Appended text.") self.assertEqual( expectedDocstring.__doc__, multiLineDocstring.__doc__)
Appending to a multi-line docstring places the messade on a new line, with a blank line separating it from the rest of the docstring. Because we have multiple lines, we have enough information to do indentation.
test_appendToMultilineDocstring
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def checkPassed(self, func, *args, **kw): """ Test an invocation of L{passed} with the given function, arguments, and keyword arguments. @param func: A function whose argspec will be inspected. @type func: A callable. @param args: The arguments which could be passed to C{func}. @param kw: The keyword arguments which could be passed to C{func}. @return: L{_passedSignature} or L{_passedArgSpec}'s return value @rtype: L{dict} """ if getattr(inspect, "signature", None): # Python 3 return _passedSignature(inspect.signature(func), args, kw) else: # Python 2 return _passedArgSpec(inspect.getargspec(func), args, kw)
Test an invocation of L{passed} with the given function, arguments, and keyword arguments. @param func: A function whose argspec will be inspected. @type func: A callable. @param args: The arguments which could be passed to C{func}. @param kw: The keyword arguments which could be passed to C{func}. @return: L{_passedSignature} or L{_passedArgSpec}'s return value @rtype: L{dict}
checkPassed
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_passed_simplePositional(self): """ L{passed} identifies the arguments passed by a simple positional test. """ def func(a, b): pass self.assertEqual(self.checkPassed(func, 1, 2), dict(a=1, b=2))
L{passed} identifies the arguments passed by a simple positional test.
test_passed_simplePositional
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_passed_tooManyArgs(self): """ L{passed} raises a L{TypeError} if too many arguments are passed. """ def func(a, b): pass self.assertRaises(TypeError, self.checkPassed, func, 1, 2, 3)
L{passed} raises a L{TypeError} if too many arguments are passed.
test_passed_tooManyArgs
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_passed_doublePassKeyword(self): """ L{passed} raises a L{TypeError} if a argument is passed both positionally and by keyword. """ def func(a): pass self.assertRaises(TypeError, self.checkPassed, func, 1, a=2)
L{passed} raises a L{TypeError} if a argument is passed both positionally and by keyword.
test_passed_doublePassKeyword
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_passed_unspecifiedKeyword(self): """ L{passed} raises a L{TypeError} if a keyword argument not present in the function's declaration is passed. """ def func(a): pass self.assertRaises(TypeError, self.checkPassed, func, 1, z=2)
L{passed} raises a L{TypeError} if a keyword argument not present in the function's declaration is passed.
test_passed_unspecifiedKeyword
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_passed_star(self): """ L{passed} places additional positional arguments into a tuple under the name of the star argument. """ def func(a, *b): pass self.assertEqual(self.checkPassed(func, 1, 2, 3), dict(a=1, b=(2, 3)))
L{passed} places additional positional arguments into a tuple under the name of the star argument.
test_passed_star
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_passed_starStar(self): """ Additional keyword arguments are passed as a dict to the star star keyword argument. """ def func(a, **b): pass self.assertEqual(self.checkPassed(func, 1, x=2, y=3, z=4), dict(a=1, b=dict(x=2, y=3, z=4)))
Additional keyword arguments are passed as a dict to the star star keyword argument.
test_passed_starStar
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_passed_noDefaultValues(self): """ The results of L{passed} only include arguments explicitly passed, not default values. """ def func(a, b, c=1, d=2, e=3): pass self.assertEqual(self.checkPassed(func, 1, 2, e=7), dict(a=1, b=2, e=7))
The results of L{passed} only include arguments explicitly passed, not default values.
test_passed_noDefaultValues
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_mutualExclusionPrimeDirective(self): """ L{mutuallyExclusiveArguments} does not interfere in its decoratee's operation, either its receipt of arguments or its return value. """ @_mutuallyExclusiveArguments([('a', 'b')]) def func(x, y, a=3, b=4): return x + y + a + b self.assertEqual(func(1, 2), 10) self.assertEqual(func(1, 2, 7), 14) self.assertEqual(func(1, 2, b=7), 13)
L{mutuallyExclusiveArguments} does not interfere in its decoratee's operation, either its receipt of arguments or its return value.
test_mutualExclusionPrimeDirective
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_mutualExclusionExcludesByKeyword(self): """ L{mutuallyExclusiveArguments} raises a L{TypeError}n if its decoratee is passed a pair of mutually exclusive arguments. """ @_mutuallyExclusiveArguments([['a', 'b']]) def func(a=3, b=4): return a + b self.assertRaises(TypeError, func, a=3, b=4)
L{mutuallyExclusiveArguments} raises a L{TypeError}n if its decoratee is passed a pair of mutually exclusive arguments.
test_mutualExclusionExcludesByKeyword
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_invalidParameterType(self): """ Create a fake signature with an invalid parameter type to test error handling. The valid parameter types are specified in L{inspect.Parameter}. """ class FakeSignature: def __init__(self, parameters): self.parameters = parameters class FakeParameter: def __init__(self, name, kind): self.name = name self.kind = kind def func(a, b): pass func(1, 2) parameters = inspect.signature(func).parameters dummyParameters = parameters.copy() dummyParameters['c'] = FakeParameter("fake", "fake") fakeSig = FakeSignature(dummyParameters) self.assertRaises(TypeError, _passedSignature, fakeSig, (1, 2), {})
Create a fake signature with an invalid parameter type to test error handling. The valid parameter types are specified in L{inspect.Parameter}.
test_invalidParameterType
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def test_notAvailable(self): """ A skipped test to show that this was not ran because the Python is too old. """
A skipped test to show that this was not ran because the Python is too old.
test_notAvailable
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_deprecate.py
MIT
def mktemp(self): """ Make our own directory. """ newDir = tempfile.mkdtemp(dir=u"/tmp/") self.addCleanup(shutil.rmtree, newDir) return newDir
Make our own directory.
mktemp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
MIT
def _gitConfig(path): """ Set some config in the repo that Git requires to make commits. This isn't needed in real usage, just for tests. @param path: The path to the Git repository. @type path: L{FilePath} """ runCommand(["git", "config", "--file", path.child(".git").child("config").path, "user.name", '"someone"']) runCommand(["git", "config", "--file", path.child(".git").child("config").path, "user.email", '"[email protected]"'])
Set some config in the repo that Git requires to make commits. This isn't needed in real usage, just for tests. @param path: The path to the Git repository. @type path: L{FilePath}
_gitConfig
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
MIT
def _gitInit(path): """ Run a git init, and set some config that git requires. This isn't needed in real usage. @param path: The path to where the Git repo will be created. @type path: L{FilePath} """ runCommand(["git", "init", path.path]) _gitConfig(path)
Run a git init, and set some config that git requires. This isn't needed in real usage. @param path: The path to where the Git repo will be created. @type path: L{FilePath}
_gitInit
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
MIT
def genVersion(*args, **kwargs): """ A convenience for generating _version.py data. @param args: Arguments to pass to L{Version}. @param kwargs: Keyword arguments to pass to L{Version}. """ return (u"from incremental import Version\n__version__={!r}".format( Version(*args, **kwargs)))
A convenience for generating _version.py data. @param args: Arguments to pass to L{Version}. @param kwargs: Keyword arguments to pass to L{Version}.
genVersion
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
MIT
def createStructure(self, root, dirDict): """ Create a set of directories and files given a dict defining their structure. @param root: The directory in which to create the structure. It must already exist. @type root: L{FilePath} @param dirDict: The dict defining the structure. Keys should be strings naming files, values should be strings describing file contents OR dicts describing subdirectories. All files are written in binary mode. Any string values are assumed to describe text files and will have their newlines replaced with the platform-native newline convention. For example:: {"foofile": "foocontents", "bardir": {"barfile": "bar\ncontents"}} @type dirDict: C{dict} """ for x in dirDict: child = root.child(x) if isinstance(dirDict[x], dict): child.createDirectory() self.createStructure(child, dirDict[x]) else: child.setContent(dirDict[x].replace('\n', os.linesep).encode("utf-8"))
Create a set of directories and files given a dict defining their structure. @param root: The directory in which to create the structure. It must already exist. @type root: L{FilePath} @param dirDict: The dict defining the structure. Keys should be strings naming files, values should be strings describing file contents OR dicts describing subdirectories. All files are written in binary mode. Any string values are assumed to describe text files and will have their newlines replaced with the platform-native newline convention. For example:: {"foofile": "foocontents", "bardir": {"barfile": "bar\ncontents"}} @type dirDict: C{dict}
createStructure
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
MIT
def assertStructure(self, root, dirDict): """ Assert that a directory is equivalent to one described by a dict. @param root: The filesystem directory to compare. @type root: L{FilePath} @param dirDict: The dict that should describe the contents of the directory. It should be the same structure as the C{dirDict} parameter to L{createStructure}. @type dirDict: C{dict} """ children = [each.basename() for each in root.children()] for pathSegment, expectation in dirDict.items(): child = root.child(pathSegment) if callable(expectation): self.assertTrue(expectation(child)) elif isinstance(expectation, dict): self.assertTrue(child.isdir(), "{} is not a dir!".format( child.path)) self.assertStructure(child, expectation) else: actual = child.getContent().decode("utf-8").replace(os.linesep, u'\n') self.assertEqual(actual, expectation) children.remove(pathSegment) if children: self.fail("There were extra children in %s: %s" % (root.path, children))
Assert that a directory is equivalent to one described by a dict. @param root: The filesystem directory to compare. @type root: L{FilePath} @param dirDict: The dict that should describe the contents of the directory. It should be the same structure as the C{dirDict} parameter to L{createStructure}. @type dirDict: C{dict}
assertStructure
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
MIT
def assertProjectsEqual(self, observedProjects, expectedProjects): """ Assert that two lists of L{Project}s are equal. """ self.assertEqual(len(observedProjects), len(expectedProjects)) observedProjects = sorted(observedProjects, key=operator.attrgetter('directory')) expectedProjects = sorted(expectedProjects, key=operator.attrgetter('directory')) for observed, expected in zip(observedProjects, expectedProjects): self.assertEqual(observed.directory, expected.directory)
Assert that two lists of L{Project}s are equal.
assertProjectsEqual
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
MIT
def makeProject(self, version, baseDirectory=None): """ Make a Twisted-style project in the given base directory. @param baseDirectory: The directory to create files in (as a L{FilePath). @param version: The version information for the project. @return: L{Project} pointing to the created project. """ if baseDirectory is None: baseDirectory = FilePath(self.mktemp()) segments = version[0].split('.') directory = baseDirectory for segment in segments: directory = directory.child(segment) if not directory.exists(): directory.createDirectory() directory.child('__init__.py').setContent(b'') directory.child('newsfragments').createDirectory() directory.child('_version.py').setContent(genVersion(*version).encode("utf-8")) return Project(directory)
Make a Twisted-style project in the given base directory. @param baseDirectory: The directory to create files in (as a L{FilePath). @param version: The version information for the project. @return: L{Project} pointing to the created project.
makeProject
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
MIT
def makeProjects(self, *versions): """ Create a series of projects underneath a temporary base directory. @return: A L{FilePath} for the base directory. """ baseDirectory = FilePath(self.mktemp()) for version in versions: self.makeProject(version, baseDirectory) return baseDirectory
Create a series of projects underneath a temporary base directory. @return: A L{FilePath} for the base directory.
makeProjects
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
MIT
def test_getVersion(self): """ Project objects know their version. """ version = ('twisted', 2, 1, 0) project = self.makeProject(version) self.assertEqual(project.getVersion(), Version(*version))
Project objects know their version.
test_getVersion
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
MIT
def test_repr(self): """ The representation of a Project is Project(directory). """ foo = Project(FilePath('bar')) self.assertEqual( repr(foo), 'Project(%r)' % (foo.directory))
The representation of a Project is Project(directory).
test_repr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
MIT
def test_findTwistedStyleProjects(self): """ findTwistedStyleProjects finds all projects underneath a particular directory. A 'project' is defined by the existence of a 'newsfragments' directory and is returned as a Project object. """ baseDirectory = self.makeProjects( ('foo', 2, 3, 0), ('foo.bar', 0, 7, 4)) projects = findTwistedProjects(baseDirectory) self.assertProjectsEqual( projects, [Project(baseDirectory.child('foo')), Project(baseDirectory.child('foo').child('bar'))])
findTwistedStyleProjects finds all projects underneath a particular directory. A 'project' is defined by the existence of a 'newsfragments' directory and is returned as a Project object.
test_findTwistedStyleProjects
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_release.py
MIT