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 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)
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.
test_baseClass
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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)
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.
test_prefix
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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)
L{prefixedMethods} returns a list of the methods discovered on an object.
test_onlyObject
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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)
If a prefix is given, L{prefixedMethods} returns only methods named with that prefix.
test_prefix
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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_"))
L{prefixedMethodNames} returns a list including methods with the given prefix defined on the class passed to it.
test_method
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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_"))
L{prefixedMethodNames} returns a list included methods with the given prefix defined on base classes of the class passed to it.
test_inheritedMethod
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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)
If C{baseClass} is passed to L{addMethodNamesToDict}, only methods which are a subclass of C{baseClass} are added to the result dictionary.
test_baseClass
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def reallySet(self): """ Do something. """
Do something.
reallySet
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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)
L{namedClass} should return the class object for the name it is passed.
test_namedClassLookup
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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)
L{namedModule} should return the module object for the name it is passed.
test_namedModuleLookup
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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)
L{namedAny} should return the package object for the name it is passed.
test_namedAnyPackageLookup
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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)
L{namedAny} should return the module object for the name it is passed.
test_namedAnyModuleLookup
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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)
L{namedAny} should return the class object for the name it is passed.
test_namedAnyClassLookup
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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)
L{namedAny} should return the object an attribute of a non-module, non-package object is bound to for the name it is passed.
test_namedAnyAttributeLookup
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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__)
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.
test_namedAnySecondAttributeLookup
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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")
Exceptions raised by modules which L{namedAny} causes to be imported should pass through L{namedAny} to the caller.
test_importExceptions
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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")
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}.
test_attributeExceptions
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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,))
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
test_invalidNames
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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)
When module import fails with ImportError it returns the specified default value.
test_requireModuleImportError
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_requireModuleDefaultNone(self): """ When module import fails it returns L{None} by default. """ result = reflect.requireModule('no.such.module') self.assertIsNone(result)
When module import fails it returns L{None} by default.
test_requireModuleDefaultNone
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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, )
When module import succeed it returns the module and not the default value.
test_requireModuleRequestedImport
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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)))
L{reflect.safe_repr} produces the same output as C{repr} on a working object.
test_workingRepr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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)
L{reflect.safe_repr} returns a string with class name, address, and traceback when the repr call failed.
test_brokenRepr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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))
L{reflect.safe_repr} isn't affected by a broken C{__str__} method.
test_brokenStr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
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 = ('<BrokenType instance at 0x%x with repr error:' % (id(X),)) self.assertEqual(xReprExpected, xRepr.split('\n')[0])
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.
test_brokenReprIncludesID
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_brokenClassAttribute(self): """ If an object raises an exception when accessing its C{__class__} attribute, L{reflect.safe_repr} uses C{type} to retrieve the class object. """ b = NoClassAttr() b.breakRepr = True bRepr = reflect.safe_repr(b) self.assertIn("NoClassAttr instance at 0x", bRepr) self.assertIn(os.path.splitext(__file__)[0], bRepr) self.assertIn("RuntimeError: repr!", bRepr)
If an object raises an exception when accessing its C{__class__} attribute, L{reflect.safe_repr} uses C{type} to retrieve the class object.
test_brokenClassAttribute
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_brokenClassNameAttribute(self): """ If a class raises an exception when accessing its C{__name__} attribute B{and} when calling its C{__str__} implementation, L{reflect.safe_repr} returns 'BROKEN CLASS' instead of the class name. """ class X(BTBase): breakName = True xRepr = reflect.safe_repr(X()) self.assertIn("<BROKEN CLASS AT 0x", xRepr) self.assertIn(os.path.splitext(__file__)[0], xRepr) self.assertIn("RuntimeError: repr!", xRepr)
If a class raises an exception when accessing its C{__name__} attribute B{and} when calling its C{__str__} implementation, L{reflect.safe_repr} returns 'BROKEN CLASS' instead of the class name.
test_brokenClassNameAttribute
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_workingAscii(self): """ L{safe_str} for C{str} with ascii-only data should return the value unchanged. """ x = 'a' self.assertEqual(reflect.safe_str(x), 'a')
L{safe_str} for C{str} with ascii-only data should return the value unchanged.
test_workingAscii
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_workingUtf8_2(self): """ L{safe_str} for C{str} with utf-8 encoded data should return the value unchanged. """ x = b't\xc3\xbcst' self.assertEqual(reflect.safe_str(x), x)
L{safe_str} for C{str} with utf-8 encoded data should return the value unchanged.
test_workingUtf8_2
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_workingUtf8_3(self): """ L{safe_str} for C{bytes} with utf-8 encoded data should return the value decoded into C{str}. """ x = b't\xc3\xbcst' self.assertEqual(reflect.safe_str(x), x.decode('utf-8'))
L{safe_str} for C{bytes} with utf-8 encoded data should return the value decoded into C{str}.
test_workingUtf8_3
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_brokenUtf8(self): """ Use str() for non-utf8 bytes: "b'non-utf8'" """ x = b'\xff' xStr = reflect.safe_str(x) self.assertEqual(xStr, str(x))
Use str() for non-utf8 bytes: "b'non-utf8'"
test_brokenUtf8
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_brokenClassAttribute(self): """ If an object raises an exception when accessing its C{__class__} attribute, L{reflect.safe_str} uses C{type} to retrieve the class object. """ b = NoClassAttr() b.breakStr = True bStr = reflect.safe_str(b) self.assertIn("NoClassAttr instance at 0x", bStr) self.assertIn(os.path.splitext(__file__)[0], bStr) self.assertIn("RuntimeError: str!", bStr)
If an object raises an exception when accessing its C{__class__} attribute, L{reflect.safe_str} uses C{type} to retrieve the class object.
test_brokenClassAttribute
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_brokenClassNameAttribute(self): """ If a class raises an exception when accessing its C{__name__} attribute B{and} when calling its C{__str__} implementation, L{reflect.safe_str} returns 'BROKEN CLASS' instead of the class name. """ class X(BTBase): breakName = True xStr = reflect.safe_str(X()) self.assertIn("<BROKEN CLASS AT 0x", xStr) self.assertIn(os.path.splitext(__file__)[0], xStr) self.assertIn("RuntimeError: str!", xStr)
If a class raises an exception when accessing its C{__name__} attribute B{and} when calling its C{__str__} implementation, L{reflect.safe_str} returns 'BROKEN CLASS' instead of the class name.
test_brokenClassNameAttribute
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_directory(self): """ L{filenameToModuleName} returns the correct module (a package) given a directory. """ module = reflect.filenameToModuleName(self.path) self.assertEqual(module, 'fakepackage.test') module = reflect.filenameToModuleName(self.path + os.path.sep) self.assertEqual(module, 'fakepackage.test')
L{filenameToModuleName} returns the correct module (a package) given a directory.
test_directory
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_file(self): """ L{filenameToModuleName} returns the correct module given the path to its file. """ module = reflect.filenameToModuleName( os.path.join(self.path, 'test_reflect.py')) self.assertEqual(module, 'fakepackage.test.test_reflect')
L{filenameToModuleName} returns the correct module given the path to its file.
test_file
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_bytes(self): """ L{filenameToModuleName} returns the correct module given a C{bytes} path to its file. """ module = reflect.filenameToModuleName( os.path.join(self.path.encode("utf-8"), b'test_reflect.py')) # Module names are always native string: self.assertEqual(module, 'fakepackage.test.test_reflect')
L{filenameToModuleName} returns the correct module given a C{bytes} path to its file.
test_bytes
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def _checkFullyQualifiedName(self, obj, expected): """ Helper to check that fully qualified name of C{obj} results to C{expected}. """ self.assertEqual(fullyQualifiedName(obj), expected)
Helper to check that fully qualified name of C{obj} results to C{expected}.
_checkFullyQualifiedName
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_package(self): """ L{fullyQualifiedName} returns the full name of a package and a subpackage. """ import twisted self._checkFullyQualifiedName(twisted, 'twisted') import twisted.python self._checkFullyQualifiedName(twisted.python, 'twisted.python')
L{fullyQualifiedName} returns the full name of a package and a subpackage.
test_package
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_module(self): """ L{fullyQualifiedName} returns the name of a module inside a package. """ import twisted.python.compat self._checkFullyQualifiedName( twisted.python.compat, 'twisted.python.compat')
L{fullyQualifiedName} returns the name of a module inside a package.
test_module
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_class(self): """ L{fullyQualifiedName} returns the name of a class and its module. """ self._checkFullyQualifiedName( FullyQualifiedNameTests, '%s.FullyQualifiedNameTests' % (__name__,))
L{fullyQualifiedName} returns the name of a class and its module.
test_class
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_function(self): """ L{fullyQualifiedName} returns the name of a function inside its module. """ self._checkFullyQualifiedName( fullyQualifiedName, "twisted.python.reflect.fullyQualifiedName")
L{fullyQualifiedName} returns the name of a function inside its module.
test_function
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_boundMethod(self): """ L{fullyQualifiedName} returns the name of a bound method inside its class and its module. """ self._checkFullyQualifiedName( self.test_boundMethod, "%s.%s.test_boundMethod" % (__name__, self.__class__.__name__))
L{fullyQualifiedName} returns the name of a bound method inside its class and its module.
test_boundMethod
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_unboundMethod(self): """ L{fullyQualifiedName} returns the name of an unbound method inside its class and its module. """ self._checkFullyQualifiedName( self.__class__.test_unboundMethod, "%s.%s.test_unboundMethod" % (__name__, self.__class__.__name__))
L{fullyQualifiedName} returns the name of an unbound method inside its class and its module.
test_unboundMethod
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_dictionary(self): """ Test references search through a dictionary, as a key or as a value. """ o = object() d1 = {None: o} d2 = {o: None} self.assertIn("[None]", reflect.objgrep(d1, o, reflect.isSame)) self.assertIn("{None}", reflect.objgrep(d2, o, reflect.isSame))
Test references search through a dictionary, as a key or as a value.
test_dictionary
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_list(self): """ Test references search through a list. """ o = object() L = [None, o] self.assertIn("[1]", reflect.objgrep(L, o, reflect.isSame))
Test references search through a list.
test_list
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_tuple(self): """ Test references search through a tuple. """ o = object() T = (o, None) self.assertIn("[0]", reflect.objgrep(T, o, reflect.isSame))
Test references search through a tuple.
test_tuple
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_instance(self): """ Test references search through an object attribute. """ class Dummy: pass o = object() d = Dummy() d.o = o self.assertIn(".o", reflect.objgrep(d, o, reflect.isSame))
Test references search through an object attribute.
test_instance
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_weakref(self): """ Test references search through a weakref object. """ class Dummy: pass o = Dummy() w1 = weakref.ref(o) self.assertIn("()", reflect.objgrep(w1, o, reflect.isSame))
Test references search through a weakref object.
test_weakref
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_boundMethod(self): """ Test references search through method special attributes. """ class Dummy: def dummy(self): pass o = Dummy() m = o.dummy self.assertIn(".__self__", reflect.objgrep(m, m.__self__, reflect.isSame)) self.assertIn(".__self__.__class__", reflect.objgrep(m, m.__self__.__class__, reflect.isSame)) self.assertIn(".__func__", reflect.objgrep(m, m.__func__, reflect.isSame))
Test references search through method special attributes.
test_boundMethod
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_everything(self): """ Test references search using complex set of objects. """ class Dummy: def method(self): pass o = Dummy() D1 = {(): "baz", None: "Quux", o: "Foosh"} L = [None, (), D1, 3] T = (L, {}, Dummy()) D2 = {0: "foo", 1: "bar", 2: T} i = Dummy() i.attr = D2 m = i.method w = weakref.ref(m) self.assertIn("().__self__.attr[2][0][2]{'Foosh'}", reflect.objgrep(w, o, reflect.isSame))
Test references search using complex set of objects.
test_everything
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_depthLimit(self): """ Test the depth of references search. """ a = [] b = [a] c = [a, b] d = [a, c] self.assertEqual(['[0]'], reflect.objgrep(d, a, reflect.isSame, maxDepth=1)) self.assertEqual(['[0]', '[1][0]'], reflect.objgrep(d, a, reflect.isSame, maxDepth=2)) self.assertEqual(['[0]', '[1][0]', '[1][1][0]'], reflect.objgrep(d, a, reflect.isSame, maxDepth=3))
Test the depth of references search.
test_depthLimit
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def test_deque(self): """ Test references search through a deque object. """ o = object() D = deque() D.append(None) D.append(o) self.assertIn("[1]", reflect.objgrep(D, o, reflect.isSame))
Test references search through a deque object.
test_deque
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_reflect.py
MIT
def _check(self, source): """ The given random bytes source should return the number of bytes requested each time it is called and should probably not return the same bytes on two consecutive calls (although this is a perfectly legitimate occurrence and rejecting it may generate a spurious failure -- maybe we'll get lucky and the heat death with come first). """ for nbytes in range(17, 25): s = source(nbytes) self.assertEqual(len(s), nbytes) s2 = source(nbytes) self.assertEqual(len(s2), nbytes) # This is crude but hey self.assertNotEqual(s2, s)
The given random bytes source should return the number of bytes requested each time it is called and should probably not return the same bytes on two consecutive calls (although this is a perfectly legitimate occurrence and rejecting it may generate a spurious failure -- maybe we'll get lucky and the heat death with come first).
_check
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
MIT
def test_normal(self): """ L{randbytes.secureRandom} should return a string of the requested length and make some effort to make its result otherwise unpredictable. """ self._check(randbytes.secureRandom)
L{randbytes.secureRandom} should return a string of the requested length and make some effort to make its result otherwise unpredictable.
test_normal
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
MIT
def setUp(self): """ Create a L{randbytes.RandomFactory} to use in the tests. """ self.factory = randbytes.RandomFactory()
Create a L{randbytes.RandomFactory} to use in the tests.
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
MIT
def errorFactory(self, nbytes): """ A factory raising an error when a source is not available. """ raise randbytes.SourceNotAvailable()
A factory raising an error when a source is not available.
errorFactory
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
MIT
def test_osUrandom(self): """ L{RandomFactory._osUrandom} should work as a random source whenever L{os.urandom} is available. """ self._check(self.factory._osUrandom)
L{RandomFactory._osUrandom} should work as a random source whenever L{os.urandom} is available.
test_osUrandom
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
MIT
def test_withoutAnything(self): """ Remove all secure sources and assert it raises a failure. Then try the fallback parameter. """ self.factory._osUrandom = self.errorFactory self.assertRaises(randbytes.SecureRandomNotAvailable, self.factory.secureRandom, 18) def wrapper(): return self.factory.secureRandom(18, fallback=True) s = self.assertWarns( RuntimeWarning, "urandom unavailable - " "proceeding with non-cryptographically secure random source", __file__, wrapper) self.assertEqual(len(s), 18)
Remove all secure sources and assert it raises a failure. Then try the fallback parameter.
test_withoutAnything
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
MIT
def test_normal(self): """ Test basic case. """ self._check(randbytes.insecureRandom)
Test basic case.
test_normal
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
MIT
def test_withoutGetrandbits(self): """ Test C{insecureRandom} without C{random.getrandbits}. """ factory = randbytes.RandomFactory() factory.getrandbits = None self._check(factory.insecureRandom)
Test C{insecureRandom} without C{random.getrandbits}.
test_withoutGetrandbits
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_randbytes.py
MIT
def __init__(self, names): """ @type names: L{dict} containing L{str} keys and L{str} values. @param names: A hostname to IP address mapping. The IP addresses are stringified dotted quads. """ self.names = names
@type names: L{dict} containing L{str} keys and L{str} values. @param names: A hostname to IP address mapping. The IP addresses are stringified dotted quads.
__init__
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_socks.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_socks.py
MIT
def resolve(self, hostname): """ Resolve a hostname by looking it up in the C{names} dictionary. """ try: return defer.succeed(self.names[hostname]) except KeyError: return defer.fail( DNSLookupError("FakeResolverReactor couldn't find " + hostname.decode("utf-8")))
Resolve a hostname by looking it up in the C{names} dictionary.
resolve
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_socks.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_socks.py
MIT
def test_socks4aSuccessfulResolution(self): """ If the destination IP address has zeros for the first three octets and non-zero for the fourth octet, the client is attempting a v4a connection. A hostname is specified after the user ID string and the server connects to the address that hostname resolves to. @see: U{http://en.wikipedia.org/wiki/SOCKS#SOCKS_4a_protocol} """ # send the domain name "localhost" to be resolved clientRequest = ( struct.pack('!BBH', 4, 1, 34) + socket.inet_aton('0.0.0.1') + b'fooBAZ\0' + b'localhost\0') # Deliver the bytes one by one to exercise the protocol's buffering # logic. FakeResolverReactor's resolve method is invoked to "resolve" # the hostname. for byte in iterbytes(clientRequest): self.sock.dataReceived(byte) sent = self.sock.transport.value() self.sock.transport.clear() # Verify that the server responded with the address which will be # connected to. self.assertEqual( sent, struct.pack('!BBH', 0, 90, 34) + socket.inet_aton('127.0.0.1')) self.assertFalse(self.sock.transport.stringTCPTransport_closing) self.assertIsNotNone(self.sock.driver_outgoing) # Pass some data through and verify it is forwarded to the outgoing # connection. self.sock.dataReceived(b'hello, world') self.assertEqual( self.sock.driver_outgoing.transport.value(), b'hello, world') # Deliver some data from the output connection and verify it is # passed along to the incoming side. self.sock.driver_outgoing.dataReceived(b'hi there') self.assertEqual(self.sock.transport.value(), b'hi there') self.sock.connectionLost('fake reason')
If the destination IP address has zeros for the first three octets and non-zero for the fourth octet, the client is attempting a v4a connection. A hostname is specified after the user ID string and the server connects to the address that hostname resolves to. @see: U{http://en.wikipedia.org/wiki/SOCKS#SOCKS_4a_protocol}
test_socks4aSuccessfulResolution
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_socks.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_socks.py
MIT
def test_socks4aFailedResolution(self): """ Failed hostname resolution on a SOCKSv4a packet results in a 91 error response and the connection getting closed. """ # send the domain name "failinghost" to be resolved clientRequest = ( struct.pack('!BBH', 4, 1, 34) + socket.inet_aton('0.0.0.1') + b'fooBAZ\0' + b'failinghost\0') # Deliver the bytes one by one to exercise the protocol's buffering # logic. FakeResolverReactor's resolve method is invoked to "resolve" # the hostname. for byte in iterbytes(clientRequest): self.sock.dataReceived(byte) # Verify that the server responds with a 91 error. sent = self.sock.transport.value() self.assertEqual( sent, struct.pack('!BBH', 0, 91, 0) + socket.inet_aton('0.0.0.0')) # A failed resolution causes the transport to drop the connection. self.assertTrue(self.sock.transport.stringTCPTransport_closing) self.assertIsNone(self.sock.driver_outgoing)
Failed hostname resolution on a SOCKSv4a packet results in a 91 error response and the connection getting closed.
test_socks4aFailedResolution
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_socks.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_socks.py
MIT
def test_socks4a(self): """ If the destination IP address has zeros for the first three octets and non-zero for the fourth octet, the client is attempting a v4a connection. A hostname is specified after the user ID string and the server connects to the address that hostname resolves to. @see: U{http://en.wikipedia.org/wiki/SOCKS#SOCKS_4a_protocol} """ # send the domain name "localhost" to be resolved clientRequest = ( struct.pack('!BBH', 4, 2, 34) + socket.inet_aton('0.0.0.1') + b'fooBAZ\0' + b'localhost\0') # Deliver the bytes one by one to exercise the protocol's buffering # logic. FakeResolverReactor's resolve method is invoked to "resolve" # the hostname. for byte in iterbytes(clientRequest): self.sock.dataReceived(byte) sent = self.sock.transport.value() self.sock.transport.clear() # Verify that the server responded with the address which will be # connected to. self.assertEqual( sent, struct.pack('!BBH', 0, 90, 1234) + socket.inet_aton('6.7.8.9')) self.assertFalse(self.sock.transport.stringTCPTransport_closing) self.assertIsNotNone(self.sock.driver_listen) # connect incoming = self.sock.driver_listen.buildProtocol(('127.0.0.1', 5345)) self.assertIsNotNone(incoming) incoming.transport = StringTCPTransport() incoming.connectionMade() # now we should have the second reply packet sent = self.sock.transport.value() self.sock.transport.clear() self.assertEqual(sent, struct.pack('!BBH', 0, 90, 0) + socket.inet_aton('0.0.0.0')) self.assertIsNot( self.sock.transport.stringTCPTransport_closing, None) # Deliver some data from the output connection and verify it is # passed along to the incoming side. self.sock.dataReceived(b'hi there') self.assertEqual(incoming.transport.value(), b'hi there') # the other way around incoming.dataReceived(b'hi there') self.assertEqual(self.sock.transport.value(), b'hi there') self.sock.connectionLost('fake reason')
If the destination IP address has zeros for the first three octets and non-zero for the fourth octet, the client is attempting a v4a connection. A hostname is specified after the user ID string and the server connects to the address that hostname resolves to. @see: U{http://en.wikipedia.org/wiki/SOCKS#SOCKS_4a_protocol}
test_socks4a
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_socks.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_socks.py
MIT
def test_socks4aFailedResolution(self): """ Failed hostname resolution on a SOCKSv4a packet results in a 91 error response and the connection getting closed. """ # send the domain name "failinghost" to be resolved clientRequest = ( struct.pack('!BBH', 4, 2, 34) + socket.inet_aton('0.0.0.1') + b'fooBAZ\0' + b'failinghost\0') # Deliver the bytes one by one to exercise the protocol's buffering # logic. FakeResolverReactor's resolve method is invoked to "resolve" # the hostname. for byte in iterbytes(clientRequest): self.sock.dataReceived(byte) # Verify that the server responds with a 91 error. sent = self.sock.transport.value() self.assertEqual( sent, struct.pack('!BBH', 0, 91, 0) + socket.inet_aton('0.0.0.0')) # A failed resolution causes the transport to drop the connection. self.assertTrue(self.sock.transport.stringTCPTransport_closing) self.assertIsNone(self.sock.driver_outgoing)
Failed hostname resolution on a SOCKSv4a packet results in a 91 error response and the connection getting closed.
test_socks4aFailedResolution
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_socks.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_socks.py
MIT
def testSeconds(self): """ Test that the C{seconds} method of the fake clock returns fake time. """ c = task.Clock() self.assertEqual(c.seconds(), 0)
Test that the C{seconds} method of the fake clock returns fake time.
testSeconds
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def testCallLater(self): """ Test that calls can be scheduled for later with the fake clock and hands back an L{IDelayedCall}. """ c = task.Clock() call = c.callLater(1, lambda a, b: None, 1, b=2) self.assertTrue(interfaces.IDelayedCall.providedBy(call)) self.assertEqual(call.getTime(), 1) self.assertTrue(call.active())
Test that calls can be scheduled for later with the fake clock and hands back an L{IDelayedCall}.
testCallLater
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def testCallLaterCancelled(self): """ Test that calls can be cancelled. """ c = task.Clock() call = c.callLater(1, lambda a, b: None, 1, b=2) call.cancel() self.assertFalse(call.active())
Test that calls can be cancelled.
testCallLaterCancelled
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_callLaterOrdering(self): """ Test that the DelayedCall returned is not one previously created. """ c = task.Clock() call1 = c.callLater(10, lambda a, b: None, 1, b=2) call2 = c.callLater(1, lambda a, b: None, 3, b=4) self.assertFalse(call1 is call2)
Test that the DelayedCall returned is not one previously created.
test_callLaterOrdering
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def testAdvance(self): """ Test that advancing the clock will fire some calls. """ events = [] c = task.Clock() call = c.callLater(2, lambda: events.append(None)) c.advance(1) self.assertEqual(events, []) c.advance(1) self.assertEqual(events, [None]) self.assertFalse(call.active())
Test that advancing the clock will fire some calls.
testAdvance
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def testAdvanceCancel(self): """ Test attempting to cancel the call in a callback. AlreadyCalled should be raised, not for example a ValueError from removing the call from Clock.calls. This requires call.called to be set before the callback is called. """ c = task.Clock() def cb(): self.assertRaises(error.AlreadyCalled, call.cancel) call = c.callLater(1, cb) c.advance(1)
Test attempting to cancel the call in a callback. AlreadyCalled should be raised, not for example a ValueError from removing the call from Clock.calls. This requires call.called to be set before the callback is called.
testAdvanceCancel
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def testCallLaterDelayed(self): """ Test that calls can be delayed. """ events = [] c = task.Clock() call = c.callLater(1, lambda a, b: events.append((a, b)), 1, b=2) call.delay(1) self.assertEqual(call.getTime(), 2) c.advance(1.5) self.assertEqual(events, []) c.advance(1.0) self.assertEqual(events, [(1, 2)])
Test that calls can be delayed.
testCallLaterDelayed
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def testCallLaterResetLater(self): """ Test that calls can have their time reset to a later time. """ events = [] c = task.Clock() call = c.callLater(2, lambda a, b: events.append((a, b)), 1, b=2) c.advance(1) call.reset(3) self.assertEqual(call.getTime(), 4) c.advance(2) self.assertEqual(events, []) c.advance(1) self.assertEqual(events, [(1, 2)])
Test that calls can have their time reset to a later time.
testCallLaterResetLater
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def testCallLaterResetSooner(self): """ Test that calls can have their time reset to an earlier time. """ events = [] c = task.Clock() call = c.callLater(4, lambda a, b: events.append((a, b)), 1, b=2) call.reset(3) self.assertEqual(call.getTime(), 3) c.advance(3) self.assertEqual(events, [(1, 2)])
Test that calls can have their time reset to an earlier time.
testCallLaterResetSooner
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_getDelayedCalls(self): """ Test that we can get a list of all delayed calls """ c = task.Clock() call = c.callLater(1, lambda x: None) call2 = c.callLater(2, lambda x: None) calls = c.getDelayedCalls() self.assertEqual(set([call, call2]), set(calls))
Test that we can get a list of all delayed calls
test_getDelayedCalls
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_getDelayedCallsEmpty(self): """ Test that we get an empty list from getDelayedCalls on a newly constructed Clock. """ c = task.Clock() self.assertEqual(c.getDelayedCalls(), [])
Test that we get an empty list from getDelayedCalls on a newly constructed Clock.
test_getDelayedCallsEmpty
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_callLaterKeepsCallsOrdered(self): """ The order of calls scheduled by L{task.Clock.callLater} is honored when adding a new call via calling L{task.Clock.callLater} again. For example, if L{task.Clock.callLater} is invoked with a callable "A" and a time t0, and then the L{IDelayedCall} which results from that is C{reset} to a later time t2 which is greater than t0, and I{then} L{task.Clock.callLater} is invoked again with a callable "B", and time t1 which is less than t2 but greater than t0, "B" will be invoked before "A". """ result = [] expected = [('b', 2.0), ('a', 3.0)] clock = task.Clock() logtime = lambda n: result.append((n, clock.seconds())) call_a = clock.callLater(1.0, logtime, "a") call_a.reset(3.0) clock.callLater(2.0, logtime, "b") clock.pump([1]*3) self.assertEqual(result, expected)
The order of calls scheduled by L{task.Clock.callLater} is honored when adding a new call via calling L{task.Clock.callLater} again. For example, if L{task.Clock.callLater} is invoked with a callable "A" and a time t0, and then the L{IDelayedCall} which results from that is C{reset} to a later time t2 which is greater than t0, and I{then} L{task.Clock.callLater} is invoked again with a callable "B", and time t1 which is less than t2 but greater than t0, "B" will be invoked before "A".
test_callLaterKeepsCallsOrdered
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_callLaterResetKeepsCallsOrdered(self): """ The order of calls scheduled by L{task.Clock.callLater} is honored when re-scheduling an existing call via L{IDelayedCall.reset} on the result of a previous call to C{callLater}. For example, if L{task.Clock.callLater} is invoked with a callable "A" and a time t0, and then L{task.Clock.callLater} is invoked again with a callable "B", and time t1 greater than t0, and finally the L{IDelayedCall} for "A" is C{reset} to a later time, t2, which is greater than t1, "B" will be invoked before "A". """ result = [] expected = [('b', 2.0), ('a', 3.0)] clock = task.Clock() logtime = lambda n: result.append((n, clock.seconds())) call_a = clock.callLater(1.0, logtime, "a") clock.callLater(2.0, logtime, "b") call_a.reset(3.0) clock.pump([1]*3) self.assertEqual(result, expected)
The order of calls scheduled by L{task.Clock.callLater} is honored when re-scheduling an existing call via L{IDelayedCall.reset} on the result of a previous call to C{callLater}. For example, if L{task.Clock.callLater} is invoked with a callable "A" and a time t0, and then L{task.Clock.callLater} is invoked again with a callable "B", and time t1 greater than t0, and finally the L{IDelayedCall} for "A" is C{reset} to a later time, t2, which is greater than t1, "B" will be invoked before "A".
test_callLaterResetKeepsCallsOrdered
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_callLaterResetInsideCallKeepsCallsOrdered(self): """ The order of calls scheduled by L{task.Clock.callLater} is honored when re-scheduling an existing call via L{IDelayedCall.reset} on the result of a previous call to C{callLater}, even when that call to C{reset} occurs within the callable scheduled by C{callLater} itself. """ result = [] expected = [('c', 3.0), ('b', 4.0)] clock = task.Clock() logtime = lambda n: result.append((n, clock.seconds())) call_b = clock.callLater(2.0, logtime, "b") def a(): call_b.reset(3.0) clock.callLater(1.0, a) clock.callLater(3.0, logtime, "c") clock.pump([0.5] * 10) self.assertEqual(result, expected)
The order of calls scheduled by L{task.Clock.callLater} is honored when re-scheduling an existing call via L{IDelayedCall.reset} on the result of a previous call to C{callLater}, even when that call to C{reset} occurs within the callable scheduled by C{callLater} itself.
test_callLaterResetInsideCallKeepsCallsOrdered
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_defaultClock(self): """ L{LoopingCall}'s default clock should be the reactor. """ call = task.LoopingCall(lambda: None) self.assertEqual(call.clock, reactor)
L{LoopingCall}'s default clock should be the reactor.
test_defaultClock
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_callbackTimeSkips(self): """ When more time than the defined interval passes during the execution of a callback, L{LoopingCall} should schedule the next call for the next interval which is still in the future. """ times = [] callDuration = None clock = task.Clock() def aCallback(): times.append(clock.seconds()) clock.advance(callDuration) call = task.LoopingCall(aCallback) call.clock = clock # Start a LoopingCall with a 0.5 second increment, and immediately call # the callable. callDuration = 2 call.start(0.5) # Verify that the callable was called, and since it was immediate, with # no skips. self.assertEqual(times, [0]) # The callback should have advanced the clock by the callDuration. self.assertEqual(clock.seconds(), callDuration) # An iteration should have occurred at 2, but since 2 is the present # and not the future, it is skipped. clock.advance(0) self.assertEqual(times, [0]) # 2.5 is in the future, and is not skipped. callDuration = 1 clock.advance(0.5) self.assertEqual(times, [0, 2.5]) self.assertEqual(clock.seconds(), 3.5) # Another iteration should have occurred, but it is again the # present and not the future, so it is skipped as well. clock.advance(0) self.assertEqual(times, [0, 2.5]) # 4 is in the future, and is not skipped. callDuration = 0 clock.advance(0.5) self.assertEqual(times, [0, 2.5, 4]) self.assertEqual(clock.seconds(), 4)
When more time than the defined interval passes during the execution of a callback, L{LoopingCall} should schedule the next call for the next interval which is still in the future.
test_callbackTimeSkips
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_reactorTimeSkips(self): """ When more time than the defined interval passes between when L{LoopingCall} schedules itself to run again and when it actually runs again, it should schedule the next call for the next interval which is still in the future. """ times = [] clock = task.Clock() def aCallback(): times.append(clock.seconds()) # Start a LoopingCall that tracks the time passed, with a 0.5 second # increment. call = task.LoopingCall(aCallback) call.clock = clock call.start(0.5) # Initially, no time should have passed! self.assertEqual(times, [0]) # Advance the clock by 2 seconds (2 seconds should have passed) clock.advance(2) self.assertEqual(times, [0, 2]) # Advance the clock by 1 second (3 total should have passed) clock.advance(1) self.assertEqual(times, [0, 2, 3]) # Advance the clock by 0 seconds (this should have no effect!) clock.advance(0) self.assertEqual(times, [0, 2, 3])
When more time than the defined interval passes between when L{LoopingCall} schedules itself to run again and when it actually runs again, it should schedule the next call for the next interval which is still in the future.
test_reactorTimeSkips
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_reactorTimeCountSkips(self): """ When L{LoopingCall} schedules itself to run again, if more than the specified interval has passed, it should schedule the next call for the next interval which is still in the future. If it was created using L{LoopingCall.withCount}, a positional argument will be inserted at the beginning of the argument list, indicating the number of calls that should have been made. """ times = [] clock = task.Clock() def aCallback(numCalls): times.append((clock.seconds(), numCalls)) # Start a LoopingCall that tracks the time passed, and the number of # skips, with a 0.5 second increment. call = task.LoopingCall.withCount(aCallback) call.clock = clock INTERVAL = 0.5 REALISTIC_DELAY = 0.01 call.start(INTERVAL) # Initially, no seconds should have passed, and one calls should have # been made. self.assertEqual(times, [(0, 1)]) # After the interval (plus a small delay, to account for the time that # the reactor takes to wake up and process the LoopingCall), we should # still have only made one call. clock.advance(INTERVAL + REALISTIC_DELAY) self.assertEqual(times, [(0, 1), (INTERVAL + REALISTIC_DELAY, 1)]) # After advancing the clock by three intervals (plus a small delay to # account for the reactor), we should have skipped two calls; one less # than the number of intervals which have completely elapsed. Along # with the call we did actually make, the final number of calls is 3. clock.advance((3 * INTERVAL) + REALISTIC_DELAY) self.assertEqual(times, [(0, 1), (INTERVAL + REALISTIC_DELAY, 1), ((4 * INTERVAL) + (2 * REALISTIC_DELAY), 3)]) # Advancing the clock by 0 seconds should not cause any changes! clock.advance(0) self.assertEqual(times, [(0, 1), (INTERVAL + REALISTIC_DELAY, 1), ((4 * INTERVAL) + (2 * REALISTIC_DELAY), 3)])
When L{LoopingCall} schedules itself to run again, if more than the specified interval has passed, it should schedule the next call for the next interval which is still in the future. If it was created using L{LoopingCall.withCount}, a positional argument will be inserted at the beginning of the argument list, indicating the number of calls that should have been made.
test_reactorTimeCountSkips
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_countLengthyIntervalCounts(self): """ L{LoopingCall.withCount} counts only calls that were expected to be made. So, if more than one, but less than two intervals pass between invocations, it won't increase the count above 1. For example, a L{LoopingCall} with interval T expects to be invoked at T, 2T, 3T, etc. However, the reactor takes some time to get around to calling it, so in practice it will be called at T+something, 2T+something, 3T+something; and due to other things going on in the reactor, "something" is variable. It won't increase the count unless "something" is greater than T. So if the L{LoopingCall} is invoked at T, 2.75T, and 3T, the count has not increased, even though the distance between invocation 1 and invocation 2 is 1.75T. """ times = [] clock = task.Clock() def aCallback(count): times.append((clock.seconds(), count)) # Start a LoopingCall that tracks the time passed, and the number of # calls, with a 0.5 second increment. call = task.LoopingCall.withCount(aCallback) call.clock = clock INTERVAL = 0.5 REALISTIC_DELAY = 0.01 call.start(INTERVAL) self.assertEqual(times.pop(), (0, 1)) # About one interval... So far, so good clock.advance(INTERVAL + REALISTIC_DELAY) self.assertEqual(times.pop(), (INTERVAL + REALISTIC_DELAY, 1)) # Oh no, something delayed us for a while. clock.advance(INTERVAL * 1.75) self.assertEqual(times.pop(), ((2.75 * INTERVAL) + REALISTIC_DELAY, 1)) # Back on track! We got invoked when we expected this time. clock.advance(INTERVAL * 0.25) self.assertEqual(times.pop(), ((3.0 * INTERVAL) + REALISTIC_DELAY, 1))
L{LoopingCall.withCount} counts only calls that were expected to be made. So, if more than one, but less than two intervals pass between invocations, it won't increase the count above 1. For example, a L{LoopingCall} with interval T expects to be invoked at T, 2T, 3T, etc. However, the reactor takes some time to get around to calling it, so in practice it will be called at T+something, 2T+something, 3T+something; and due to other things going on in the reactor, "something" is variable. It won't increase the count unless "something" is greater than T. So if the L{LoopingCall} is invoked at T, 2.75T, and 3T, the count has not increased, even though the distance between invocation 1 and invocation 2 is 1.75T.
test_countLengthyIntervalCounts
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_withCountFloatingPointBoundary(self): """ L{task.LoopingCall.withCount} should never invoke its callable with a zero. Specifically, if a L{task.LoopingCall} created with C{withCount} has its L{start <task.LoopingCall.start>} method invoked with a floating-point number which introduces decimal inaccuracy when multiplied or divided, such as "0.1", L{task.LoopingCall} will never invoke its callable with 0. Also, the sum of all the values passed to its callable as the "count" will be an integer, the number of intervals that have elapsed. This is a regression test for a particularly tricky case to implement. """ clock = task.Clock() accumulator = [] call = task.LoopingCall.withCount(accumulator.append) call.clock = clock # 'count': the number of ticks within the time span, the number of # calls that should be made. this should be a value which causes # floating-point inaccuracy as the denominator for the timespan. count = 10 # 'timespan': the amount of virtual time that the test will take, in # seconds, as a floating point number timespan = 1.0 # 'interval': the amount of time for one actual call. interval = timespan / count call.start(interval, now=False) for x in range(count): clock.advance(interval) # There is still an epsilon of inaccuracy here; 0.1 is not quite # exactly 1/10 in binary, so we need to push our clock over the # threshold. epsilon = timespan - sum([interval] * count) clock.advance(epsilon) secondsValue = clock.seconds() # The following two assertions are here to ensure that if the values of # count, timespan, and interval are changed, that the test remains # valid. First, the "epsilon" value here measures the floating-point # inaccuracy in question, and so if it doesn't exist then we are not # triggering an interesting condition. self.assertTrue(abs(epsilon) > 0.0, "{0} should be greater than zero" .format(epsilon)) # Secondly, task.Clock should behave in such a way that once we have # advanced to this point, it has reached or exceeded the timespan. self.assertTrue(secondsValue >= timespan, "{0} should be greater than or equal to {1}" .format(secondsValue, timespan)) self.assertEqual(sum(accumulator), count) self.assertNotIn(0, accumulator)
L{task.LoopingCall.withCount} should never invoke its callable with a zero. Specifically, if a L{task.LoopingCall} created with C{withCount} has its L{start <task.LoopingCall.start>} method invoked with a floating-point number which introduces decimal inaccuracy when multiplied or divided, such as "0.1", L{task.LoopingCall} will never invoke its callable with 0. Also, the sum of all the values passed to its callable as the "count" will be an integer, the number of intervals that have elapsed. This is a regression test for a particularly tricky case to implement.
test_withCountFloatingPointBoundary
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_withCountIntervalZero(self): """ L{task.LoopingCall.withCount} with interval set to 0 will call the countCallable 1. """ clock = task.Clock() accumulator = [] def foo(cnt): accumulator.append(cnt) if len(accumulator) > 4: loop.stop() loop = task.LoopingCall.withCount(foo) loop.clock = clock deferred = loop.start(0, now=False) clock.advance(0) self.successResultOf(deferred) self.assertEqual([1, 1, 1, 1, 1], accumulator)
L{task.LoopingCall.withCount} with interval set to 0 will call the countCallable 1.
test_withCountIntervalZero
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_withCountIntervalZeroDelay(self): """ L{task.LoopingCall.withCount} with interval set to 0 and a delayed call during the loop run will still call the countCallable 1 as if no delay occurred. """ clock = task.Clock() deferred = defer.Deferred() accumulator = [] def foo(cnt): accumulator.append(cnt) if len(accumulator) == 2: return deferred if len(accumulator) > 4: loop.stop() loop = task.LoopingCall.withCount(foo) loop.clock = clock loop.start(0, now=False) clock.advance(0) # Loop will block at the third call. self.assertEqual([1, 1], accumulator) # Even if more time pass, the loops is not # advanced. clock.advance(2) self.assertEqual([1, 1], accumulator) # Once the waiting call got a result the loop continues without # observing any delay in countCallable. deferred.callback(None) clock.advance(0) self.assertEqual([1, 1, 1, 1, 1], accumulator)
L{task.LoopingCall.withCount} with interval set to 0 and a delayed call during the loop run will still call the countCallable 1 as if no delay occurred.
test_withCountIntervalZeroDelay
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_withCountIntervalZeroDelayThenNonZeroInterval(self): """ L{task.LoopingCall.withCount} with interval set to 0 will still keep the time when last called so when the interval is reset. """ clock = task.Clock() deferred = defer.Deferred() accumulator = [] def foo(cnt): accumulator.append(cnt) if len(accumulator) == 2: return deferred loop = task.LoopingCall.withCount(foo) loop.clock = clock loop.start(0, now=False) # Even if a lot of time pass, loop will block at the third call. clock.advance(10) self.assertEqual([1, 1], accumulator) # When a new interval is set, once the waiting call got a result the # loop continues with the new interval. loop.interval = 2 deferred.callback(None) # It will count skipped steps since the last loop call. clock.advance(7) self.assertEqual([1, 1, 3], accumulator) clock.advance(2) self.assertEqual([1, 1, 3, 1], accumulator) clock.advance(4) self.assertEqual([1, 1, 3, 1, 2], accumulator)
L{task.LoopingCall.withCount} with interval set to 0 will still keep the time when last called so when the interval is reset.
test_withCountIntervalZeroDelayThenNonZeroInterval
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_reset(self): """ Test that L{LoopingCall} can be reset. """ ran = [] def foo(): ran.append(None) c = task.Clock() lc = TestableLoopingCall(c, foo) lc.start(2, now=False) c.advance(1) lc.reset() c.advance(1) self.assertEqual(ran, []) c.advance(1) self.assertEqual(ran, [None])
Test that L{LoopingCall} can be reset.
test_reset
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_reprFunction(self): """ L{LoopingCall.__repr__} includes the wrapped function's name. """ self.assertEqual(repr(task.LoopingCall(installReactor, 1, key=2)), "LoopingCall<None>(installReactor, *(1,), **{'key': 2})")
L{LoopingCall.__repr__} includes the wrapped function's name.
test_reprFunction
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_reprMethod(self): """ L{LoopingCall.__repr__} includes the wrapped method's full name. """ self.assertEqual( repr(task.LoopingCall(TestableLoopingCall.__init__)), "LoopingCall<None>(TestableLoopingCall.__init__, *(), **{})")
L{LoopingCall.__repr__} includes the wrapped method's full name.
test_reprMethod
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_deferredDeprecation(self): """ L{LoopingCall.deferred} is deprecated. """ loop = task.LoopingCall(lambda: None) loop.deferred message = ( 'twisted.internet.task.LoopingCall.deferred was deprecated in ' 'Twisted 16.0.0; ' 'please use the deferred returned by start() instead' ) warnings = self.flushWarnings([self.test_deferredDeprecation]) self.assertEqual(1, len(warnings)) self.assertEqual(DeprecationWarning, warnings[0]['category']) self.assertEqual(message, warnings[0]['message'])
L{LoopingCall.deferred} is deprecated.
test_deferredDeprecation
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_deferredWithCount(self): """ In the case that the function passed to L{LoopingCall.withCount} returns a deferred, which does not fire before the next interval elapses, the function should not be run again. And if a function call is skipped in this fashion, the appropriate count should be provided. """ testClock = task.Clock() d = defer.Deferred() deferredCounts = [] def countTracker(possibleCount): # Keep a list of call counts deferredCounts.append(possibleCount) # Return a deferred, but only on the first request if len(deferredCounts) == 1: return d else: return None # Start a looping call for our countTracker function # Set the increment to 0.2, and do not call the function on startup. lc = task.LoopingCall.withCount(countTracker) lc.clock = testClock d = lc.start(0.2, now=False) # Confirm that nothing has happened yet. self.assertEqual(deferredCounts, []) # Advance the clock by 0.2 and then 0.4; testClock.pump([0.2, 0.4]) # We should now have exactly one count (of 1 call) self.assertEqual(len(deferredCounts), 1) # Fire the deferred, and advance the clock by another 0.2 d.callback(None) testClock.pump([0.2]) # We should now have exactly 2 counts... self.assertEqual(len(deferredCounts), 2) # The first count should be 1 (one call) # The second count should be 3 (calls were missed at about 0.6 and 0.8) self.assertEqual(deferredCounts, [1, 3])
In the case that the function passed to L{LoopingCall.withCount} returns a deferred, which does not fire before the next interval elapses, the function should not be run again. And if a function call is skipped in this fashion, the appropriate count should be provided.
test_deferredWithCount
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_callback(self): """ The L{Deferred} returned by L{task.deferLater} is called back after the specified delay with the result of the function passed in. """ results = [] flag = object() def callable(foo, bar): results.append((foo, bar)) return flag clock = task.Clock() d = task.deferLater(clock, 3, callable, 'foo', bar='bar') d.addCallback(self.assertIs, flag) clock.advance(2) self.assertEqual(results, []) clock.advance(1) self.assertEqual(results, [('foo', 'bar')]) return d
The L{Deferred} returned by L{task.deferLater} is called back after the specified delay with the result of the function passed in.
test_callback
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_errback(self): """ The L{Deferred} returned by L{task.deferLater} is errbacked if the supplied function raises an exception. """ def callable(): raise TestException() clock = task.Clock() d = task.deferLater(clock, 1, callable) clock.advance(1) return self.assertFailure(d, TestException)
The L{Deferred} returned by L{task.deferLater} is errbacked if the supplied function raises an exception.
test_errback
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_cancel(self): """ The L{Deferred} returned by L{task.deferLater} can be cancelled to prevent the call from actually being performed. """ called = [] clock = task.Clock() d = task.deferLater(clock, 1, called.append, None) d.cancel() def cbCancelled(ignored): # Make sure there are no calls outstanding. self.assertEqual([], clock.getDelayedCalls()) # And make sure the call didn't somehow happen already. self.assertFalse(called) self.assertFailure(d, defer.CancelledError) d.addCallback(cbCancelled) return d
The L{Deferred} returned by L{task.deferLater} can be cancelled to prevent the call from actually being performed.
test_cancel
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def test_noCallback(self): """ The L{Deferred} returned by L{task.deferLater} fires with C{None} when no callback function is passed. """ clock = task.Clock() d = task.deferLater(clock, 2.0) self.assertNoResult(d) clock.advance(2.0) self.assertIs(None, self.successResultOf(d))
The L{Deferred} returned by L{task.deferLater} fires with C{None} when no callback function is passed.
test_noCallback
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def run(self): """ Call timed events until there are no more or the reactor is stopped. @raise RuntimeError: When no timed events are left and the reactor is still running. """ self._running = True whenRunning = self._whenRunning self._whenRunning = None for callable, args, kwargs in whenRunning: callable(*args, **kwargs) while self._running: calls = self.getDelayedCalls() if not calls: raise RuntimeError("No DelayedCalls left") self._clock.advance(calls[0].getTime() - self.seconds()) shutdownTriggers = self._shutdownTriggers self._shutdownTriggers = None for (trigger, args) in shutdownTriggers['before'] + shutdownTriggers['during']: trigger(*args)
Call timed events until there are no more or the reactor is stopped. @raise RuntimeError: When no timed events are left and the reactor is still running.
run
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT
def stop(self): """ Stop the reactor. """ if not self._running: raise error.ReactorNotRunning() self._running = False
Stop the reactor.
stop
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_task.py
MIT