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
182
| url
stringlengths 46
251
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
def test_copyReg(self):
"""
L{aot.jellyToSource} and L{aot.unjellyFromSource} honor functions
registered in the pickle copy registry.
"""
uj = aot.unjellyFromSource(aot.jellyToSource(CopyRegistered()))
self.assertIsInstance(uj, CopyRegisteredLoaded) | L{aot.jellyToSource} and L{aot.unjellyFromSource} honor functions
registered in the pickle copy registry. | test_copyReg | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_persisted.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_persisted.py | MIT |
def test_circularTuple(self):
"""
L{aot.jellyToAOT} can persist circular references through tuples.
"""
l = []
t = (l, 4321)
l.append(t)
j1 = aot.jellyToAOT(l)
oj = aot.unjellyFromAOT(j1)
self.assertIsInstance(oj[0], tuple)
self.assertIs(oj[0][0], oj)
self.assertEqual(oj[0][1], 4321) | L{aot.jellyToAOT} can persist circular references through tuples. | test_circularTuple | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_persisted.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_persisted.py | MIT |
def test_dictUnknownKey(self):
"""
L{crefutil._DictKeyAndValue} only support keys C{0} and C{1}.
"""
d = crefutil._DictKeyAndValue({})
self.assertRaises(RuntimeError, d.__setitem__, 2, 3) | L{crefutil._DictKeyAndValue} only support keys C{0} and C{1}. | test_dictUnknownKey | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_persisted.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_persisted.py | MIT |
def test_deferSetMultipleTimes(self):
"""
L{crefutil._Defer} can be assigned a key only one time.
"""
d = crefutil._Defer()
d[0] = 1
self.assertRaises(RuntimeError, d.__setitem__, 0, 1) | L{crefutil._Defer} can be assigned a key only one time. | test_deferSetMultipleTimes | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_persisted.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_persisted.py | MIT |
def test_containerWhereAllElementsAreKnown(self):
"""
A L{crefutil._Container} where all of its elements are known at
construction time is nonsensical and will result in errors in any call
to addDependant.
"""
container = crefutil._Container([1, 2, 3], list)
self.assertRaises(AssertionError,
container.addDependant, {}, "ignore-me") | A L{crefutil._Container} where all of its elements are known at
construction time is nonsensical and will result in errors in any call
to addDependant. | test_containerWhereAllElementsAreKnown | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_persisted.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_persisted.py | MIT |
def test_dontPutCircularReferencesInDictionaryKeys(self):
"""
If a dictionary key contains a circular reference (which is probably a
bad practice anyway) it will be resolved by a
L{crefutil._DictKeyAndValue}, not by placing a L{crefutil.NotKnown}
into a dictionary key.
"""
self.assertRaises(AssertionError,
dict().__setitem__, crefutil.NotKnown(), "value") | If a dictionary key contains a circular reference (which is probably a
bad practice anyway) it will be resolved by a
L{crefutil._DictKeyAndValue}, not by placing a L{crefutil.NotKnown}
into a dictionary key. | test_dontPutCircularReferencesInDictionaryKeys | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_persisted.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_persisted.py | MIT |
def test_dontCallInstanceMethodsThatArentReady(self):
"""
L{crefutil._InstanceMethod} raises L{AssertionError} to indicate it
should not be called. This should not be possible with any of its API
clients, but is provided for helping to debug.
"""
self.assertRaises(AssertionError,
crefutil._InstanceMethod(
"no_name", crefutil.NotKnown(), type)) | L{crefutil._InstanceMethod} raises L{AssertionError} to indicate it
should not be called. This should not be possible with any of its API
clients, but is provided for helping to debug. | test_dontCallInstanceMethodsThatArentReady | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_persisted.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_persisted.py | MIT |
def test_3StringIO(self):
"""
An L{io.StringIO} accepts and returns text.
"""
self.assertEqual(ioType(io.StringIO()), unicodeCompat) | An L{io.StringIO} accepts and returns text. | test_3StringIO | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_3BytesIO(self):
"""
An L{io.BytesIO} accepts and returns bytes.
"""
self.assertEqual(ioType(io.BytesIO()), bytes) | An L{io.BytesIO} accepts and returns bytes. | test_3BytesIO | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_3openTextMode(self):
"""
A file opened via 'io.open' in text mode accepts and returns text.
"""
with io.open(self.mktemp(), "w") as f:
self.assertEqual(ioType(f), unicodeCompat) | A file opened via 'io.open' in text mode accepts and returns text. | test_3openTextMode | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_3openBinaryMode(self):
"""
A file opened via 'io.open' in binary mode accepts and returns bytes.
"""
with io.open(self.mktemp(), "wb") as f:
self.assertEqual(ioType(f), bytes) | A file opened via 'io.open' in binary mode accepts and returns bytes. | test_3openBinaryMode | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_2openTextMode(self):
"""
The special built-in console file in Python 2 which has an 'encoding'
attribute should qualify as a special type, since it accepts both bytes
and text faithfully.
"""
class VerySpecificLie(file):
"""
In their infinite wisdom, the CPython developers saw fit not to
allow us a writable 'encoding' attribute on the built-in 'file'
type in Python 2, despite making it writable in C with
PyFile_SetEncoding.
Pretend they did not do that.
"""
encoding = 'utf-8'
self.assertEqual(ioType(VerySpecificLie(self.mktemp(), "wb")),
basestring) | The special built-in console file in Python 2 which has an 'encoding'
attribute should qualify as a special type, since it accepts both bytes
and text faithfully. | test_2openTextMode | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_2StringIO(self):
"""
Python 2's L{StringIO} and L{cStringIO} modules are both binary I/O.
"""
from cStringIO import StringIO as cStringIO
from StringIO import StringIO
self.assertEqual(ioType(StringIO()), bytes)
self.assertEqual(ioType(cStringIO()), bytes) | Python 2's L{StringIO} and L{cStringIO} modules are both binary I/O. | test_2StringIO | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_2openBinaryMode(self):
"""
The normal 'open' builtin in Python 2 will always result in bytes I/O.
"""
with open(self.mktemp(), "w") as f:
self.assertEqual(ioType(f), bytes) | The normal 'open' builtin in Python 2 will always result in bytes I/O. | test_2openBinaryMode | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_codecsOpenBytes(self):
"""
The L{codecs} module, oddly, returns a file-like object which returns
bytes when not passed an 'encoding' argument.
"""
with codecs.open(self.mktemp(), 'wb') as f:
self.assertEqual(ioType(f), bytes) | The L{codecs} module, oddly, returns a file-like object which returns
bytes when not passed an 'encoding' argument. | test_codecsOpenBytes | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_codecsOpenText(self):
"""
When passed an encoding, however, the L{codecs} module returns unicode.
"""
with codecs.open(self.mktemp(), 'wb', encoding='utf-8') as f:
self.assertEqual(ioType(f), unicodeCompat) | When passed an encoding, however, the L{codecs} module returns unicode. | test_codecsOpenText | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_defaultToText(self):
"""
When passed an object about which no sensible decision can be made, err
on the side of unicode.
"""
self.assertEqual(ioType(object()), unicodeCompat) | When passed an object about which no sensible decision can be made, err
on the side of unicode. | test_defaultToText | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_set(self):
"""
L{set} should behave like the expected set interface.
"""
a = set()
a.add('b')
a.add('c')
a.add('a')
b = list(a)
b.sort()
self.assertEqual(b, ['a', 'b', 'c'])
a.remove('b')
b = list(a)
b.sort()
self.assertEqual(b, ['a', 'c'])
a.discard('d')
b = set(['r', 's'])
d = a.union(b)
b = list(d)
b.sort()
self.assertEqual(b, ['a', 'c', 'r', 's']) | L{set} should behave like the expected set interface. | test_set | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_frozenset(self):
"""
L{frozenset} should behave like the expected frozenset interface.
"""
a = frozenset(['a', 'b'])
self.assertRaises(AttributeError, getattr, a, "add")
self.assertEqual(sorted(a), ['a', 'b'])
b = frozenset(['r', 's'])
d = a.union(b)
b = list(d)
b.sort()
self.assertEqual(b, ['a', 'b', 'r', 's']) | L{frozenset} should behave like the expected frozenset interface. | test_frozenset | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_reduce(self):
"""
L{reduce} should behave like the builtin reduce.
"""
self.assertEqual(15, reduce(lambda x, y: x + y, [1, 2, 3, 4, 5]))
self.assertEqual(16, reduce(lambda x, y: x + y, [1, 2, 3, 4, 5], 1)) | L{reduce} should behave like the builtin reduce. | test_reduce | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def testPToN(self):
"""
L{twisted.python.compat.inet_pton} parses IPv4 and IPv6 addresses in a
manner similar to that of L{socket.inet_pton}.
"""
from twisted.python.compat import inet_pton
f = lambda a: inet_pton(socket.AF_INET6, a)
g = lambda a: inet_pton(socket.AF_INET, a)
self.assertEqual('\x00\x00\x00\x00', g('0.0.0.0'))
self.assertEqual('\xff\x00\xff\x00', g('255.0.255.0'))
self.assertEqual('\xaa\xaa\xaa\xaa', g('170.170.170.170'))
self.assertEqual('\x00' * 16, f('::'))
self.assertEqual('\x00' * 16, f('0::0'))
self.assertEqual('\x00\x01' + '\x00' * 14, f('1::'))
self.assertEqual(
'\x45\xef\x76\xcb\x00\x1a\x56\xef\xaf\xeb\x0b\xac\x19\x24\xae\xae',
f('45ef:76cb:1a:56ef:afeb:bac:1924:aeae'))
# Scope ID doesn't affect the binary representation.
self.assertEqual(
'\x45\xef\x76\xcb\x00\x1a\x56\xef\xaf\xeb\x0b\xac\x19\x24\xae\xae',
f('45ef:76cb:1a:56ef:afeb:bac:1924:aeae%en0'))
self.assertEqual('\x00' * 14 + '\x00\x01', f('::1'))
self.assertEqual('\x00' * 12 + '\x01\x02\x03\x04', f('::1.2.3.4'))
self.assertEqual(
'\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x01\x02\x03\xff',
f('1:2:3:4:5:6:1.2.3.255'))
for badaddr in ['1:2:3:4:5:6:7:8:', ':1:2:3:4:5:6:7:8', '1::2::3',
'1:::3', ':::', '1:2', '::1.2', '1.2.3.4::',
'abcd:1.2.3.4:abcd:abcd:abcd:abcd:abcd',
'1234:1.2.3.4:1234:1234:1234:1234:1234:1234',
'1.2.3.4', '', '%eth0']:
self.assertRaises(ValueError, f, badaddr) | L{twisted.python.compat.inet_pton} parses IPv4 and IPv6 addresses in a
manner similar to that of L{socket.inet_pton}. | testPToN | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def writeScript(self, content):
"""
Write L{content} to a new temporary file, returning the L{FilePath}
for the new file.
"""
path = self.mktemp()
with open(path, "wb") as f:
f.write(content.encode("ascii"))
return FilePath(path.encode("utf-8")) | Write L{content} to a new temporary file, returning the L{FilePath}
for the new file. | writeScript | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_execfileGlobals(self):
"""
L{execfile} executes the specified file in the given global namespace.
"""
script = self.writeScript(u"foo += 1\n")
globalNamespace = {"foo": 1}
execfile(script.path, globalNamespace)
self.assertEqual(2, globalNamespace["foo"]) | L{execfile} executes the specified file in the given global namespace. | test_execfileGlobals | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_execfileGlobalsAndLocals(self):
"""
L{execfile} executes the specified file in the given global and local
namespaces.
"""
script = self.writeScript(u"foo += 1\n")
globalNamespace = {"foo": 10}
localNamespace = {"foo": 20}
execfile(script.path, globalNamespace, localNamespace)
self.assertEqual(10, globalNamespace["foo"])
self.assertEqual(21, localNamespace["foo"]) | L{execfile} executes the specified file in the given global and local
namespaces. | test_execfileGlobalsAndLocals | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_execfileUniversalNewlines(self):
"""
L{execfile} reads in the specified file using universal newlines so
that scripts written on one platform will work on another.
"""
for lineEnding in u"\n", u"\r", u"\r\n":
script = self.writeScript(u"foo = 'okay'" + lineEnding)
globalNamespace = {"foo": None}
execfile(script.path, globalNamespace)
self.assertEqual("okay", globalNamespace["foo"]) | L{execfile} reads in the specified file using universal newlines so
that scripts written on one platform will work on another. | test_execfileUniversalNewlines | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_python2(self):
"""
On Python 2, C{_PY3} is False.
"""
if sys.version.startswith("2."):
self.assertFalse(_PY3) | On Python 2, C{_PY3} is False. | test_python2 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_python3(self):
"""
On Python 3, C{_PY3} is True.
"""
if sys.version.startswith("3."):
self.assertTrue(_PY3) | On Python 3, C{_PY3} is True. | test_python3 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_PYPY(self):
"""
On PyPy, L{_PYPY} is True.
"""
if 'PyPy' in sys.version:
self.assertTrue(_PYPY)
else:
self.assertFalse(_PYPY) | On PyPy, L{_PYPY} is True. | test_PYPY | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_equality(self):
"""
Instances of a class that is decorated by C{comparable} support
equality comparisons.
"""
# Make explicitly sure we're using ==:
self.assertTrue(Comparable(1) == Comparable(1))
self.assertFalse(Comparable(2) == Comparable(1)) | Instances of a class that is decorated by C{comparable} support
equality comparisons. | test_equality | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_nonEquality(self):
"""
Instances of a class that is decorated by C{comparable} support
inequality comparisons.
"""
# Make explicitly sure we're using !=:
self.assertFalse(Comparable(1) != Comparable(1))
self.assertTrue(Comparable(2) != Comparable(1)) | Instances of a class that is decorated by C{comparable} support
inequality comparisons. | test_nonEquality | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_greaterThan(self):
"""
Instances of a class that is decorated by C{comparable} support
greater-than comparisons.
"""
self.assertTrue(Comparable(2) > Comparable(1))
self.assertFalse(Comparable(0) > Comparable(3)) | Instances of a class that is decorated by C{comparable} support
greater-than comparisons. | test_greaterThan | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_greaterThanOrEqual(self):
"""
Instances of a class that is decorated by C{comparable} support
greater-than-or-equal comparisons.
"""
self.assertTrue(Comparable(1) >= Comparable(1))
self.assertTrue(Comparable(2) >= Comparable(1))
self.assertFalse(Comparable(0) >= Comparable(3)) | Instances of a class that is decorated by C{comparable} support
greater-than-or-equal comparisons. | test_greaterThanOrEqual | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_lessThan(self):
"""
Instances of a class that is decorated by C{comparable} support
less-than comparisons.
"""
self.assertTrue(Comparable(0) < Comparable(3))
self.assertFalse(Comparable(2) < Comparable(0)) | Instances of a class that is decorated by C{comparable} support
less-than comparisons. | test_lessThan | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_lessThanOrEqual(self):
"""
Instances of a class that is decorated by C{comparable} support
less-than-or-equal comparisons.
"""
self.assertTrue(Comparable(3) <= Comparable(3))
self.assertTrue(Comparable(0) <= Comparable(3))
self.assertFalse(Comparable(2) <= Comparable(0)) | Instances of a class that is decorated by C{comparable} support
less-than-or-equal comparisons. | test_lessThanOrEqual | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_notImplementedEquals(self):
"""
Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__eq__} if it is returned by the
underlying C{__cmp__} call.
"""
self.assertEqual(Comparable(1).__eq__(object()), NotImplemented) | Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__eq__} if it is returned by the
underlying C{__cmp__} call. | test_notImplementedEquals | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_notImplementedNotEquals(self):
"""
Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__ne__} if it is returned by the
underlying C{__cmp__} call.
"""
self.assertEqual(Comparable(1).__ne__(object()), NotImplemented) | Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__ne__} if it is returned by the
underlying C{__cmp__} call. | test_notImplementedNotEquals | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_notImplementedGreaterThan(self):
"""
Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__gt__} if it is returned by the
underlying C{__cmp__} call.
"""
self.assertEqual(Comparable(1).__gt__(object()), NotImplemented) | Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__gt__} if it is returned by the
underlying C{__cmp__} call. | test_notImplementedGreaterThan | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_notImplementedLessThan(self):
"""
Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__lt__} if it is returned by the
underlying C{__cmp__} call.
"""
self.assertEqual(Comparable(1).__lt__(object()), NotImplemented) | Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__lt__} if it is returned by the
underlying C{__cmp__} call. | test_notImplementedLessThan | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_notImplementedGreaterThanEquals(self):
"""
Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__ge__} if it is returned by the
underlying C{__cmp__} call.
"""
self.assertEqual(Comparable(1).__ge__(object()), NotImplemented) | Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__ge__} if it is returned by the
underlying C{__cmp__} call. | test_notImplementedGreaterThanEquals | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_notImplementedLessThanEquals(self):
"""
Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__le__} if it is returned by the
underlying C{__cmp__} call.
"""
self.assertEqual(Comparable(1).__le__(object()), NotImplemented) | Instances of a class that is decorated by C{comparable} support
returning C{NotImplemented} from C{__le__} if it is returned by the
underlying C{__cmp__} call. | test_notImplementedLessThanEquals | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_equals(self):
"""
L{cmp} returns 0 for equal objects.
"""
self.assertEqual(cmp(u"a", u"a"), 0)
self.assertEqual(cmp(1, 1), 0)
self.assertEqual(cmp([1], [1]), 0) | L{cmp} returns 0 for equal objects. | test_equals | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_greaterThan(self):
"""
L{cmp} returns 1 if its first argument is bigger than its second.
"""
self.assertEqual(cmp(4, 0), 1)
self.assertEqual(cmp(b"z", b"a"), 1) | L{cmp} returns 1 if its first argument is bigger than its second. | test_greaterThan | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_lessThan(self):
"""
L{cmp} returns -1 if its first argument is smaller than its second.
"""
self.assertEqual(cmp(0.1, 2.3), -1)
self.assertEqual(cmp(b"a", b"d"), -1) | L{cmp} returns -1 if its first argument is smaller than its second. | test_lessThan | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def assertNativeString(self, original, expected):
"""
Raise an exception indicating a failed test if the output of
C{nativeString(original)} is unequal to the expected string, or is not
a native string.
"""
self.assertEqual(nativeString(original), expected)
self.assertIsInstance(nativeString(original), str) | Raise an exception indicating a failed test if the output of
C{nativeString(original)} is unequal to the expected string, or is not
a native string. | assertNativeString | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_nonASCIIBytesToString(self):
"""
C{nativeString} raises a C{UnicodeError} if input bytes are not ASCII
decodable.
"""
self.assertRaises(UnicodeError, nativeString, b"\xFF") | C{nativeString} raises a C{UnicodeError} if input bytes are not ASCII
decodable. | test_nonASCIIBytesToString | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_nonASCIIUnicodeToString(self):
"""
C{nativeString} raises a C{UnicodeError} if input Unicode is not ASCII
encodable.
"""
self.assertRaises(UnicodeError, nativeString, u"\u1234") | C{nativeString} raises a C{UnicodeError} if input Unicode is not ASCII
encodable. | test_nonASCIIUnicodeToString | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_bytesToString(self):
"""
C{nativeString} converts bytes to the native string format, assuming
an ASCII encoding if applicable.
"""
self.assertNativeString(b"hello", "hello") | C{nativeString} converts bytes to the native string format, assuming
an ASCII encoding if applicable. | test_bytesToString | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_unicodeToString(self):
"""
C{nativeString} converts unicode to the native string format, assuming
an ASCII encoding if applicable.
"""
self.assertNativeString(u"Good day", "Good day") | C{nativeString} converts unicode to the native string format, assuming
an ASCII encoding if applicable. | test_unicodeToString | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_stringToString(self):
"""
C{nativeString} leaves native strings as native strings.
"""
self.assertNativeString("Hello!", "Hello!") | C{nativeString} leaves native strings as native strings. | test_stringToString | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_unexpectedType(self):
"""
C{nativeString} raises a C{TypeError} if given an object that is not a
string of some sort.
"""
self.assertRaises(TypeError, nativeString, 1) | C{nativeString} raises a C{TypeError} if given an object that is not a
string of some sort. | test_unexpectedType | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_unicode(self):
"""
C{compat.unicode} is C{str} on Python 3, C{unicode} on Python 2.
"""
if _PY3:
expected = str
else:
expected = unicode
self.assertIs(unicodeCompat, expected) | C{compat.unicode} is C{str} on Python 3, C{unicode} on Python 2. | test_unicode | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_nativeStringIO(self):
"""
L{NativeStringIO} is a file-like object that stores native strings in
memory.
"""
f = NativeStringIO()
f.write("hello")
f.write(" there")
self.assertEqual(f.getvalue(), "hello there") | L{NativeStringIO} is a file-like object that stores native strings in
memory. | test_nativeStringIO | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_bytes(self):
"""
L{networkString} returns a C{bytes} object passed to it unmodified.
"""
self.assertEqual(b"foo", networkString(b"foo")) | L{networkString} returns a C{bytes} object passed to it unmodified. | test_bytes | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_bytesOutOfRange(self):
"""
L{networkString} raises C{UnicodeError} if passed a C{bytes} instance
containing bytes not used by ASCII.
"""
self.assertRaises(
UnicodeError, networkString, u"\N{SNOWMAN}".encode('utf-8')) | L{networkString} raises C{UnicodeError} if passed a C{bytes} instance
containing bytes not used by ASCII. | test_bytesOutOfRange | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_unicode(self):
"""
L{networkString} returns a C{unicode} object passed to it encoded into
a C{bytes} instance.
"""
self.assertEqual(b"foo", networkString(u"foo")) | L{networkString} returns a C{unicode} object passed to it encoded into
a C{bytes} instance. | test_unicode | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_unicodeOutOfRange(self):
"""
L{networkString} raises L{UnicodeError} if passed a C{unicode} instance
containing characters not encodable in ASCII.
"""
self.assertRaises(
UnicodeError, networkString, u"\N{SNOWMAN}") | L{networkString} raises L{UnicodeError} if passed a C{unicode} instance
containing characters not encodable in ASCII. | test_unicodeOutOfRange | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_nonString(self):
"""
L{networkString} raises L{TypeError} if passed a non-string object or
the wrong type of string object.
"""
self.assertRaises(TypeError, networkString, object())
if _PY3:
self.assertRaises(TypeError, networkString, b"bytes")
else:
self.assertRaises(TypeError, networkString, u"text") | L{networkString} raises L{TypeError} if passed a non-string object or
the wrong type of string object. | test_nonString | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_reraiseWithNone(self):
"""
Calling L{reraise} with an exception instance and a traceback of
L{None} re-raises it with a new traceback.
"""
try:
1/0
except:
typ, value, tb = sys.exc_info()
try:
reraise(value, None)
except:
typ2, value2, tb2 = sys.exc_info()
self.assertEqual(typ2, ZeroDivisionError)
self.assertIs(value, value2)
self.assertNotEqual(traceback.format_tb(tb)[-1],
traceback.format_tb(tb2)[-1])
else:
self.fail("The exception was not raised.") | Calling L{reraise} with an exception instance and a traceback of
L{None} re-raises it with a new traceback. | test_reraiseWithNone | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_reraiseWithTraceback(self):
"""
Calling L{reraise} with an exception instance and a traceback
re-raises the exception with the given traceback.
"""
try:
1/0
except:
typ, value, tb = sys.exc_info()
try:
reraise(value, tb)
except:
typ2, value2, tb2 = sys.exc_info()
self.assertEqual(typ2, ZeroDivisionError)
self.assertIs(value, value2)
self.assertEqual(traceback.format_tb(tb)[-1],
traceback.format_tb(tb2)[-1])
else:
self.fail("The exception was not raised.") | Calling L{reraise} with an exception instance and a traceback
re-raises the exception with the given traceback. | test_reraiseWithTraceback | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_iteration(self):
"""
When L{iterbytes} is called with a bytestring, the returned object
can be iterated over, resulting in the individual bytes of the
bytestring.
"""
input = b"abcd"
result = list(iterbytes(input))
self.assertEqual(result, [b'a', b'b', b'c', b'd']) | When L{iterbytes} is called with a bytestring, the returned object
can be iterated over, resulting in the individual bytes of the
bytestring. | test_iteration | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_intToBytes(self):
"""
When L{intToBytes} is called with an integer, the result is an
ASCII-encoded string representation of the number.
"""
self.assertEqual(intToBytes(213), b"213") | When L{intToBytes} is called with an integer, the result is an
ASCII-encoded string representation of the number. | test_intToBytes | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_lazyByteSliceNoOffset(self):
"""
L{lazyByteSlice} called with some bytes returns a semantically equal
version of these bytes.
"""
data = b'123XYZ'
self.assertEqual(bytes(lazyByteSlice(data)), data) | L{lazyByteSlice} called with some bytes returns a semantically equal
version of these bytes. | test_lazyByteSliceNoOffset | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_lazyByteSliceOffset(self):
"""
L{lazyByteSlice} called with some bytes and an offset returns a
semantically equal version of these bytes starting at the given offset.
"""
data = b'123XYZ'
self.assertEqual(bytes(lazyByteSlice(data, 2)), data[2:]) | L{lazyByteSlice} called with some bytes and an offset returns a
semantically equal version of these bytes starting at the given offset. | test_lazyByteSliceOffset | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_lazyByteSliceOffsetAndLength(self):
"""
L{lazyByteSlice} called with some bytes, an offset and a length returns
a semantically equal version of these bytes starting at the given
offset, up to the given length.
"""
data = b'123XYZ'
self.assertEqual(bytes(lazyByteSlice(data, 2, 3)), data[2:5]) | L{lazyByteSlice} called with some bytes, an offset and a length returns
a semantically equal version of these bytes starting at the given
offset, up to the given length. | test_lazyByteSliceOffsetAndLength | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_alwaysBytes(self):
"""
The output of L{BytesEnviron} should always be a L{dict} with L{bytes}
values and L{bytes} keys.
"""
result = bytesEnviron()
types = set()
for key, val in iteritems(result):
types.add(type(key))
types.add(type(val))
self.assertEqual(list(types), [bytes]) | The output of L{BytesEnviron} should always be a L{dict} with L{bytes}
values and L{bytes} keys. | test_alwaysBytes | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_unicodeASCII(self):
"""
Unicode strings with ASCII code points are unchanged.
"""
result = _coercedUnicode(u'text')
self.assertEqual(result, u'text')
self.assertIsInstance(result, unicodeCompat) | Unicode strings with ASCII code points are unchanged. | test_unicodeASCII | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_unicodeNonASCII(self):
"""
Unicode strings with non-ASCII code points are unchanged.
"""
result = _coercedUnicode(u'\N{SNOWMAN}')
self.assertEqual(result, u'\N{SNOWMAN}')
self.assertIsInstance(result, unicodeCompat) | Unicode strings with non-ASCII code points are unchanged. | test_unicodeNonASCII | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_nativeASCII(self):
"""
Native strings with ASCII code points are unchanged.
On Python 2, this verifies that ASCII-only byte strings are accepted,
whereas for Python 3 it is identical to L{test_unicodeASCII}.
"""
result = _coercedUnicode('text')
self.assertEqual(result, u'text')
self.assertIsInstance(result, unicodeCompat) | Native strings with ASCII code points are unchanged.
On Python 2, this verifies that ASCII-only byte strings are accepted,
whereas for Python 3 it is identical to L{test_unicodeASCII}. | test_nativeASCII | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_bytesPy3(self):
"""
Byte strings are not accceptable in Python 3.
"""
exc = self.assertRaises(TypeError, _coercedUnicode, b'bytes')
self.assertEqual(str(exc), "Expected str not b'bytes' (bytes)") | Byte strings are not accceptable in Python 3. | test_bytesPy3 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_bytesNonASCII(self):
"""
Byte strings with non-ASCII code points raise an exception.
"""
self.assertRaises(UnicodeError, _coercedUnicode, b'\xe2\x98\x83') | Byte strings with non-ASCII code points raise an exception. | test_bytesNonASCII | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_unichr(self):
"""
unichar exists and returns a unicode string with the given code point.
"""
self.assertEqual(unichr(0x2603), u"\N{SNOWMAN}") | unichar exists and returns a unicode string with the given code point. | test_unichr | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_raw_input(self):
"""
L{twisted.python.compat.raw_input}
"""
class FakeStdin:
def readline(self):
return "User input\n"
class FakeStdout:
data = ""
def write(self, data):
self.data += data
self.patch(sys, "stdin", FakeStdin())
stdout = FakeStdout()
self.patch(sys, "stdout", stdout)
self.assertEqual(raw_input("Prompt"), "User input")
self.assertEqual(stdout.data, "Prompt") | L{twisted.python.compat.raw_input} | test_raw_input | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_bytesReprNotBytes(self):
"""
L{twisted.python.compat._bytesRepr} raises a
L{TypeError} when called any object that is not an instance of
L{bytes}.
"""
exc = self.assertRaises(TypeError, _bytesRepr, ["not bytes"])
self.assertEquals(str(exc), "Expected bytes not ['not bytes']") | L{twisted.python.compat._bytesRepr} raises a
L{TypeError} when called any object that is not an instance of
L{bytes}. | test_bytesReprNotBytes | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_bytesReprPrefix(self):
"""
L{twisted.python.compat._bytesRepr} always prepends
``b`` to the returned repr on both Python 2 and 3.
"""
self.assertEqual(_bytesRepr(b'\x00'), "b'\\x00'") | L{twisted.python.compat._bytesRepr} always prepends
``b`` to the returned repr on both Python 2 and 3. | test_bytesReprPrefix | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_get_async_param(self):
"""
L{twisted.python.compat._get_async_param} uses isAsync by default,
or deprecated async keyword argument if isAsync is None.
"""
self.assertEqual(_get_async_param(isAsync=False), False)
self.assertEqual(_get_async_param(isAsync=True), True)
self.assertEqual(
_get_async_param(isAsync=None, **{'async': False}), False)
self.assertEqual(
_get_async_param(isAsync=None, **{'async': True}), True)
self.assertRaises(TypeError, _get_async_param, False, {'async': False}) | L{twisted.python.compat._get_async_param} uses isAsync by default,
or deprecated async keyword argument if isAsync is None. | test_get_async_param | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def test_get_async_param_deprecation(self):
"""
L{twisted.python.compat._get_async_param} raises a deprecation
warning if async keyword argument is passed.
"""
self.assertEqual(
_get_async_param(isAsync=None, **{'async': False}), False)
currentWarnings = self.flushWarnings(
offendingFunctions=[self.test_get_async_param_deprecation])
self.assertEqual(
currentWarnings[0]['message'],
"'async' keyword argument is deprecated, please use isAsync") | L{twisted.python.compat._get_async_param} raises a deprecation
warning if async keyword argument is passed. | test_get_async_param_deprecation | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_compat.py | MIT |
def patchUserDatabase(patch, user, uid, group, gid):
"""
Patch L{pwd.getpwnam} so that it behaves as though only one user exists
and patch L{grp.getgrnam} so that it behaves as though only one group
exists.
@param patch: A function like L{TestCase.patch} which will be used to
install the fake implementations.
@type user: C{str}
@param user: The name of the single user which will exist.
@type uid: C{int}
@param uid: The UID of the single user which will exist.
@type group: C{str}
@param group: The name of the single user which will exist.
@type gid: C{int}
@param gid: The GID of the single group which will exist.
"""
# Try not to be an unverified fake, but try not to depend on quirks of
# the system either (eg, run as a process with a uid and gid which
# equal each other, and so doesn't reliably test that uid is used where
# uid should be used and gid is used where gid should be used). -exarkun
pwent = pwd.getpwuid(os.getuid())
grent = grp.getgrgid(os.getgid())
database = UserDatabase()
database.addUser(
user, pwent.pw_passwd, uid, gid,
pwent.pw_gecos, pwent.pw_dir, pwent.pw_shell)
def getgrnam(name):
result = list(grent)
result[result.index(grent.gr_name)] = group
result[result.index(grent.gr_gid)] = gid
result = tuple(result)
return {group: result}[name]
patch(pwd, "getpwnam", database.getpwnam)
patch(grp, "getgrnam", getgrnam)
patch(pwd, "getpwuid", database.getpwuid) | Patch L{pwd.getpwnam} so that it behaves as though only one user exists
and patch L{grp.getgrnam} so that it behaves as though only one group
exists.
@param patch: A function like L{TestCase.patch} which will be used to
install the fake implementations.
@type user: C{str}
@param user: The name of the single user which will exist.
@type uid: C{int}
@param uid: The UID of the single user which will exist.
@type group: C{str}
@param group: The name of the single user which will exist.
@type gid: C{int}
@param gid: The GID of the single group which will exist. | patchUserDatabase | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def makeService(self, options):
"""
Take a L{usage.Options} instance and return a
L{service.IService} provider.
"""
self.options = options
self.service = service.Service()
return self.service | Take a L{usage.Options} instance and return a
L{service.IService} provider. | makeService | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_subCommands(self):
"""
subCommands is built from IServiceMaker plugins, and is sorted
alphabetically.
"""
class FakePlugin(object):
def __init__(self, name):
self.tapname = name
self._options = 'options for ' + name
self.description = 'description of ' + name
def options(self):
return self._options
apple = FakePlugin('apple')
banana = FakePlugin('banana')
coconut = FakePlugin('coconut')
donut = FakePlugin('donut')
def getPlugins(interface):
self.assertEqual(interface, IServiceMaker)
yield coconut
yield banana
yield donut
yield apple
config = twistd.ServerOptions()
self.assertEqual(config._getPlugins, plugin.getPlugins)
config._getPlugins = getPlugins
# "subCommands is a list of 4-tuples of (command name, command
# shortcut, parser class, documentation)."
subCommands = config.subCommands
expectedOrder = [apple, banana, coconut, donut]
for subCommand, expectedCommand in zip(subCommands, expectedOrder):
name, shortcut, parserClass, documentation = subCommand
self.assertEqual(name, expectedCommand.tapname)
self.assertIsNone(shortcut)
self.assertEqual(parserClass(), expectedCommand._options),
self.assertEqual(documentation, expectedCommand.description) | subCommands is built from IServiceMaker plugins, and is sorted
alphabetically. | test_subCommands | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_sortedReactorHelp(self):
"""
Reactor names are listed alphabetically by I{--help-reactors}.
"""
class FakeReactorInstaller(object):
def __init__(self, name):
self.shortName = 'name of ' + name
self.description = 'description of ' + name
self.moduleName = 'twisted.internet.default'
apple = FakeReactorInstaller('apple')
banana = FakeReactorInstaller('banana')
coconut = FakeReactorInstaller('coconut')
donut = FakeReactorInstaller('donut')
def getReactorTypes():
yield coconut
yield banana
yield donut
yield apple
config = twistd.ServerOptions()
self.assertEqual(config._getReactorTypes, reactors.getReactorTypes)
config._getReactorTypes = getReactorTypes
config.messageOutput = NativeStringIO()
self.assertRaises(SystemExit, config.parseOptions, ['--help-reactors'])
helpOutput = config.messageOutput.getvalue()
indexes = []
for reactor in apple, banana, coconut, donut:
def getIndex(s):
self.assertIn(s, helpOutput)
indexes.append(helpOutput.index(s))
getIndex(reactor.shortName)
getIndex(reactor.description)
self.assertEqual(
indexes, sorted(indexes),
'reactor descriptions were not in alphabetical order: %r' % (
helpOutput,)) | Reactor names are listed alphabetically by I{--help-reactors}. | test_sortedReactorHelp | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_postOptionsSubCommandCausesNoSave(self):
"""
postOptions should set no_save to True when a subcommand is used.
"""
config = twistd.ServerOptions()
config.subCommand = 'ueoa'
config.postOptions()
self.assertTrue(config['no_save']) | postOptions should set no_save to True when a subcommand is used. | test_postOptionsSubCommandCausesNoSave | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_postOptionsNoSubCommandSavesAsUsual(self):
"""
If no sub command is used, postOptions should not touch no_save.
"""
config = twistd.ServerOptions()
config.postOptions()
self.assertFalse(config['no_save']) | If no sub command is used, postOptions should not touch no_save. | test_postOptionsNoSubCommandSavesAsUsual | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_listAllProfilers(self):
"""
All the profilers that can be used in L{app.AppProfiler} are listed in
the help output.
"""
config = twistd.ServerOptions()
helpOutput = str(config)
for profiler in app.AppProfiler.profilers:
self.assertIn(profiler, helpOutput) | All the profilers that can be used in L{app.AppProfiler} are listed in
the help output. | test_listAllProfilers | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_defaultUmask(self):
"""
The default value for the C{umask} option is L{None}.
"""
config = twistd.ServerOptions()
self.assertIsNone(config['umask']) | The default value for the C{umask} option is L{None}. | test_defaultUmask | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_umask(self):
"""
The value given for the C{umask} option is parsed as an octal integer
literal.
"""
config = twistd.ServerOptions()
config.parseOptions(['--umask', '123'])
self.assertEqual(config['umask'], 83)
config.parseOptions(['--umask', '0123'])
self.assertEqual(config['umask'], 83) | The value given for the C{umask} option is parsed as an octal integer
literal. | test_umask | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_invalidUmask(self):
"""
If a value is given for the C{umask} option which cannot be parsed as
an integer, L{UsageError} is raised by L{ServerOptions.parseOptions}.
"""
config = twistd.ServerOptions()
self.assertRaises(UsageError, config.parseOptions,
['--umask', 'abcdef']) | If a value is given for the C{umask} option which cannot be parsed as
an integer, L{UsageError} is raised by L{ServerOptions.parseOptions}. | test_invalidUmask | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_unimportableConfiguredLogObserver(self):
"""
C{--logger} with an unimportable module raises a L{UsageError}.
"""
config = twistd.ServerOptions()
e = self.assertRaises(
UsageError, config.parseOptions,
['--logger', 'no.such.module.I.hope'])
self.assertTrue(
e.args[0].startswith(
"Logger 'no.such.module.I.hope' could not be imported: "
"'no.such.module.I.hope' does not name an object"))
self.assertNotIn('\n', e.args[0]) | C{--logger} with an unimportable module raises a L{UsageError}. | test_unimportableConfiguredLogObserver | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_badAttributeWithConfiguredLogObserver(self):
"""
C{--logger} with a non-existent object raises a L{UsageError}.
"""
config = twistd.ServerOptions()
e = self.assertRaises(UsageError, config.parseOptions,
["--logger", "twisted.test.test_twistd.FOOBAR"])
if sys.version_info <= (3, 5):
self.assertTrue(
e.args[0].startswith(
"Logger 'twisted.test.test_twistd.FOOBAR' could not be "
"imported: 'module' object has no attribute 'FOOBAR'"))
else:
self.assertTrue(
e.args[0].startswith(
"Logger 'twisted.test.test_twistd.FOOBAR' could not be "
"imported: module 'twisted.test.test_twistd' "
"has no attribute 'FOOBAR'"))
self.assertNotIn('\n', e.args[0]) | C{--logger} with a non-existent object raises a L{UsageError}. | test_badAttributeWithConfiguredLogObserver | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_version(self):
"""
C{--version} prints the version.
"""
from twisted import copyright
if platformType == "win32":
name = "(the Twisted Windows runner)"
else:
name = "(the Twisted daemon)"
expectedOutput = ('twistd {} {}\n{}\n'.format(
name, copyright.version, copyright.copyright))
stdout = NativeStringIO()
config = twistd.ServerOptions(stdout=stdout)
e = self.assertRaises(SystemExit, config.parseOptions, ['--version'])
self.assertIs(e.code, None)
self.assertEqual(stdout.getvalue(), expectedOutput) | C{--version} prints the version. | test_version | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_notExists(self):
"""
Nonexistent PID file is not an error.
"""
self.patch(os.path, "exists", lambda _: False)
checkPID("non-existent PID file") | Nonexistent PID file is not an error. | test_notExists | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_nonNumeric(self):
"""
Non-numeric content in a PID file causes a system exit.
"""
pidfile = self.mktemp()
with open(pidfile, "w") as f:
f.write("non-numeric")
e = self.assertRaises(SystemExit, checkPID, pidfile)
self.assertIn("non-numeric value", e.code) | Non-numeric content in a PID file causes a system exit. | test_nonNumeric | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_anotherRunning(self):
"""
Another running twistd server causes a system exit.
"""
pidfile = self.mktemp()
with open(pidfile, "w") as f:
f.write("42")
def kill(pid, sig):
pass
self.patch(os, "kill", kill)
e = self.assertRaises(SystemExit, checkPID, pidfile)
self.assertIn("Another twistd server", e.code) | Another running twistd server causes a system exit. | test_anotherRunning | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_stale(self):
"""
Stale PID file is removed without causing a system exit.
"""
pidfile = self.mktemp()
with open(pidfile, "w") as f:
f.write(str(os.getpid() + 1))
def kill(pid, sig):
raise OSError(errno.ESRCH, "fake")
self.patch(os, "kill", kill)
checkPID(pidfile)
self.assertFalse(os.path.exists(pidfile)) | Stale PID file is removed without causing a system exit. | test_stale | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_unexpectedOSError(self):
"""
An unexpected L{OSError} when checking the validity of a
PID in a C{pidfile} terminates the process via L{SystemExit}.
"""
pidfile = self.mktemp()
with open(pidfile, "w") as f:
f.write("3581")
def kill(pid, sig):
raise OSError(errno.EBADF, "fake")
self.patch(os, "kill", kill)
e = self.assertRaises(SystemExit, checkPID, pidfile)
self.assertIsNot(e.code, None)
self.assertTrue(e.args[0].startswith("Can't check status of PID")) | An unexpected L{OSError} when checking the validity of a
PID in a C{pidfile} terminates the process via L{SystemExit}. | test_unexpectedOSError | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def setUp(self):
"""
Create a trivial Application and put it in a tap file on disk.
"""
self.tapfile = self.mktemp()
with open(self.tapfile, 'wb') as f:
pickle.dump(service.Application("Hi!"), f) | Create a trivial Application and put it in a tap file on disk. | setUp | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_createOrGetApplicationWithTapFile(self):
"""
Ensure that the createOrGetApplication call that 'twistd -f foo.tap'
makes will load the Application out of foo.tap.
"""
config = twistd.ServerOptions()
config.parseOptions(['-f', self.tapfile])
application = CrippledApplicationRunner(
config).createOrGetApplication()
self.assertEqual(service.IService(application).name, 'Hi!') | Ensure that the createOrGetApplication call that 'twistd -f foo.tap'
makes will load the Application out of foo.tap. | test_createOrGetApplicationWithTapFile | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def start(self, application):
"""
Save the logging start on the C{runner} instance.
"""
self.runner.order.append("log")
self.runner.hadApplicationLogObserver = hasattr(self.runner,
'application') | Save the logging start on the C{runner} instance. | start | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def stop(self):
"""
Don't log anything.
""" | Don't log anything. | stop | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_applicationRunnerGetsCorrectApplication(self):
"""
Ensure that a twistd plugin gets used in appropriate ways: it
is passed its Options instance, and the service it returns is
added to the application.
"""
arunner = CrippledApplicationRunner(self.config)
arunner.run()
self.assertIs(
self.serviceMaker.options, self.config.subOptions,
"ServiceMaker.makeService needs to be passed the correct "
"sub Command object.")
self.assertIs(
self.serviceMaker.service,
service.IService(arunner.application).services[0],
"ServiceMaker.makeService's result needs to be set as a child "
"of the Application.") | Ensure that a twistd plugin gets used in appropriate ways: it
is passed its Options instance, and the service it returns is
added to the application. | test_applicationRunnerGetsCorrectApplication | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
def test_preAndPostApplication(self):
"""
Test thet preApplication and postApplication methods are
called by ApplicationRunner.run() when appropriate.
"""
s = TestApplicationRunner(self.config)
s.run()
self.assertFalse(s.hadApplicationPreApplication)
self.assertTrue(s.hadApplicationPostApplication)
self.assertTrue(s.hadApplicationLogObserver)
self.assertEqual(s.order, ["pre", "log", "post"]) | Test thet preApplication and postApplication methods are
called by ApplicationRunner.run() when appropriate. | test_preAndPostApplication | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.