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 setUp(self): """ Create a pair of UNIX sockets. """ self.input, self.output = socketpair(AF_UNIX)
Create a pair of UNIX sockets.
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def tearDown(self): """ Close the sockets opened by setUp. """ self.input.close() self.output.close()
Close the sockets opened by setUp.
tearDown
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_sendmsgBadArguments(self): """ The argument types accepted by L{send1msg} are: 1. C{int} 2. read-only character buffer 3. C{int} 4. sequence The 3rd and 4th arguments are optional. If fewer than two arguments or more than four arguments are passed, or if any of the arguments passed are not compatible with these types, L{TypeError} is raised. """ # Exercise the wrong number of arguments cases self.assertRaises(TypeError, send1msg) self.assertRaises(TypeError, send1msg, 1) self.assertRaises(TypeError, send1msg, 1, "hello world", 2, [], object()) # Exercise the wrong type of arguments cases self.assertRaises(TypeError, send1msg, object(), "hello world", 2, []) self.assertRaises(TypeError, send1msg, 1, object(), 2, []) self.assertRaises(TypeError, send1msg, 1, "hello world", object(), []) self.assertRaises(TypeError, send1msg, 1, "hello world", 2, object())
The argument types accepted by L{send1msg} are: 1. C{int} 2. read-only character buffer 3. C{int} 4. sequence The 3rd and 4th arguments are optional. If fewer than two arguments or more than four arguments are passed, or if any of the arguments passed are not compatible with these types, L{TypeError} is raised.
test_sendmsgBadArguments
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_badAncillaryIter(self): """ If iteration over the ancillary data list fails (at the point of the C{__iter__} call), the exception with which it fails is propagated to the caller of L{send1msg}. """ badList = BadList() badList.append((1, 2, "hello world")) badList.iterate = False self.assertRaises(RuntimeError, send1msg, 1, "hello world", 2, badList) # Hit the second iteration badList.iterate = True self.assertRaises(RuntimeError, send1msg, 1, "hello world", 2, badList)
If iteration over the ancillary data list fails (at the point of the C{__iter__} call), the exception with which it fails is propagated to the caller of L{send1msg}.
test_badAncillaryIter
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_badAncillaryNext(self): """ If iteration over the ancillary data list fails (at the point of a C{next} call), the exception with which it fails is propagated to the caller of L{send1msg}. """ worseList = WorseList() self.assertRaises(RuntimeError, send1msg, 1, "hello world", 2,worseList)
If iteration over the ancillary data list fails (at the point of a C{next} call), the exception with which it fails is propagated to the caller of L{send1msg}.
test_badAncillaryNext
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_sendmsgBadAncillaryItem(self): """ The ancillary data list contains three-tuples with element types of: 1. C{int} 2. C{int} 3. read-only character buffer If a tuple in the ancillary data list does not elements of these types, L{TypeError} is raised. """ # Exercise the wrong number of arguments cases self.assertRaises(TypeError, send1msg, 1, "hello world", 2, [()]) self.assertRaises(TypeError, send1msg, 1, "hello world", 2, [(1,)]) self.assertRaises(TypeError, send1msg, 1, "hello world", 2, [(1, 2)]) self.assertRaises( TypeError, send1msg, 1, "hello world", 2, [(1, 2, "goodbye", object())]) # Exercise the wrong type of arguments cases exc = self.assertRaises( TypeError, send1msg, 1, "hello world", 2, [object()]) self.assertEqual( "send1msg argument 3 expected list of tuple, " "got list containing object", str(exc)) self.assertRaises( TypeError, send1msg, 1, "hello world", 2, [(object(), 1, "goodbye")]) self.assertRaises( TypeError, send1msg, 1, "hello world", 2, [(1, object(), "goodbye")]) self.assertRaises( TypeError, send1msg, 1, "hello world", 2, [(1, 1, object())])
The ancillary data list contains three-tuples with element types of: 1. C{int} 2. C{int} 3. read-only character buffer If a tuple in the ancillary data list does not elements of these types, L{TypeError} is raised.
test_sendmsgBadAncillaryItem
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_syscallError(self): """ If the underlying C{sendmsg} call fails, L{send1msg} raises L{socket.error} with its errno set to the underlying errno value. """ with open(devnull) as probe: fd = probe.fileno() exc = self.assertRaises(error, send1msg, fd, "hello, world") self.assertEqual(exc.args[0], errno.EBADF)
If the underlying C{sendmsg} call fails, L{send1msg} raises L{socket.error} with its errno set to the underlying errno value.
test_syscallError
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_syscallErrorWithControlMessage(self): """ The behavior when the underlying C{sendmsg} call fails is the same whether L{send1msg} is passed ancillary data or not. """ with open(devnull) as probe: fd = probe.fileno() exc = self.assertRaises( error, send1msg, fd, "hello, world", 0, [(0, 0, "0123")]) self.assertEqual(exc.args[0], errno.EBADF)
The behavior when the underlying C{sendmsg} call fails is the same whether L{send1msg} is passed ancillary data or not.
test_syscallErrorWithControlMessage
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_roundtrip(self): """ L{recv1msg} will retrieve a message sent via L{send1msg}. """ message = "hello, world!" self.assertEqual( len(message), send1msg(self.input.fileno(), message, 0)) result = recv1msg(fd=self.output.fileno()) self.assertEqual(result, (message, 0, []))
L{recv1msg} will retrieve a message sent via L{send1msg}.
test_roundtrip
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_roundtripEmptyAncillary(self): """ L{send1msg} treats an empty ancillary data list the same way it treats receiving no argument for the ancillary parameter at all. """ send1msg(self.input.fileno(), "hello, world!", 0, []) result = recv1msg(fd=self.output.fileno()) self.assertEqual(result, ("hello, world!", 0, []))
L{send1msg} treats an empty ancillary data list the same way it treats receiving no argument for the ancillary parameter at all.
test_roundtripEmptyAncillary
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_flags(self): """ The C{flags} argument to L{send1msg} is passed on to the underlying C{sendmsg} call, to affect it in whatever way is defined by those flags. """ # Just exercise one flag with simple, well-known behavior. MSG_DONTWAIT # makes the send a non-blocking call, even if the socket is in blocking # mode. See also test_flags in RecvmsgTests for i in range(8 * 1024): try: send1msg(self.input.fileno(), "x" * 1024, MSG_DONTWAIT) except error as e: self.assertEqual(e.args[0], errno.EAGAIN) break else: self.fail( "Failed to fill up the send buffer, " "or maybe send1msg blocked for a while")
The C{flags} argument to L{send1msg} is passed on to the underlying C{sendmsg} call, to affect it in whatever way is defined by those flags.
test_flags
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_wrongTypeAncillary(self): """ L{send1msg} will show a helpful exception message when given the wrong type of object for the 'ancillary' argument. """ error = self.assertRaises(TypeError, send1msg, self.input.fileno(), "hello, world!", 0, 4321) self.assertEqual(str(error), "send1msg argument 3 expected list, got int")
L{send1msg} will show a helpful exception message when given the wrong type of object for the 'ancillary' argument.
test_wrongTypeAncillary
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_sendSubProcessFD(self): """ Calling L{sendsmsg} with SOL_SOCKET, SCM_RIGHTS, and a platform-endian packed file descriptor number should send that file descriptor to a different process, where it can be retrieved by using L{recv1msg}. """ sspp = _spawn("cmodulepullpipe", self.output.fileno()) yield sspp.started pipeOut, pipeIn = _makePipe() self.addCleanup(pipeOut.close) self.addCleanup(pipeIn.close) with pipeIn: send1msg( self.input.fileno(), "blonk", 0, [(SOL_SOCKET, SCM_RIGHTS, pack("i", pipeIn.fileno()))]) yield sspp.stopped self.assertEqual(read(pipeOut.fileno(), 1024), "Test fixture data: blonk.\n") # Make sure that the pipe is actually closed now. self.assertEqual(read(pipeOut.fileno(), 1024), "")
Calling L{sendsmsg} with SOL_SOCKET, SCM_RIGHTS, and a platform-endian packed file descriptor number should send that file descriptor to a different process, where it can be retrieved by using L{recv1msg}.
test_sendSubProcessFD
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_sendmsgTwoAncillaryDoesNotSegfault(self): """ L{sendmsg} with two FDs in two separate ancillary entries does not segfault. """ ancillary = [ (SOL_SOCKET, SCM_RIGHTS, pack("i", self.input.fileno())), (SOL_SOCKET, SCM_RIGHTS, pack("i", self.output.fileno())), ] try: send1msg(self.input.fileno(), b"some data", 0, ancillary) except error: # Ok as long as it doesn't segfault. pass
L{sendmsg} with two FDs in two separate ancillary entries does not segfault.
test_sendmsgTwoAncillaryDoesNotSegfault
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_badArguments(self): """ The argument types accepted by L{recv1msg} are: 1. C{int} 2. C{int} 3. C{int} 4. C{int} The 2nd, 3rd, and 4th arguments are optional. If fewer than one argument or more than four arguments are passed, or if any of the arguments passed are not compatible with these types, L{TypeError} is raised. """ # Exercise the wrong number of arguments cases self.assertRaises(TypeError, recv1msg) self.assertRaises(TypeError, recv1msg, 1, 2, 3, 4, object()) # Exercise the wrong type of arguments cases self.assertRaises(TypeError, recv1msg, object(), 2, 3, 4) self.assertRaises(TypeError, recv1msg, 1, object(), 3, 4) self.assertRaises(TypeError, recv1msg, 1, 2, object(), 4) self.assertRaises(TypeError, recv1msg, 1, 2, 3, object())
The argument types accepted by L{recv1msg} are: 1. C{int} 2. C{int} 3. C{int} 4. C{int} The 2nd, 3rd, and 4th arguments are optional. If fewer than one argument or more than four arguments are passed, or if any of the arguments passed are not compatible with these types, L{TypeError} is raised.
test_badArguments
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_cmsgSpaceOverflow(self): """ L{recv1msg} raises L{OverflowError} if passed a value for the C{cmsg_size} argument which exceeds C{SOCKLEN_MAX}. """ self.assertRaises(OverflowError, recv1msg, 0, 0, 0, 0x7FFFFFFF)
L{recv1msg} raises L{OverflowError} if passed a value for the C{cmsg_size} argument which exceeds C{SOCKLEN_MAX}.
test_cmsgSpaceOverflow
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_syscallError(self): """ If the underlying C{recvmsg} call fails, L{recv1msg} raises L{socket.error} with its errno set to the underlying errno value. """ with open(devnull) as probe: fd = probe.fileno() exc = self.assertRaises(error, recv1msg, fd) self.assertEqual(exc.args[0], errno.EBADF)
If the underlying C{recvmsg} call fails, L{recv1msg} raises L{socket.error} with its errno set to the underlying errno value.
test_syscallError
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_flags(self): """ The C{flags} argument to L{recv1msg} is passed on to the underlying C{recvmsg} call, to affect it in whatever way is defined by those flags. """ # See test_flags in SendmsgTests reader, writer = socketpair(AF_UNIX) exc = self.assertRaises( error, recv1msg, reader.fileno(), MSG_DONTWAIT) self.assertEqual(exc.args[0], errno.EAGAIN)
The C{flags} argument to L{recv1msg} is passed on to the underlying C{recvmsg} call, to affect it in whatever way is defined by those flags.
test_flags
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def _socket(self, addressFamily): """ Create a new socket using the given address family and return that socket's file descriptor. The socket will automatically be closed when the test is torn down. """ s = socket(addressFamily) self.addCleanup(s.close) return s.fileno()
Create a new socket using the given address family and return that socket's file descriptor. The socket will automatically be closed when the test is torn down.
_socket
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_badArguments(self): """ L{getsockfam} accepts a single C{int} argument. If it is called in some other way, L{TypeError} is raised. """ self.assertRaises(TypeError, getsockfam) self.assertRaises(TypeError, getsockfam, 1, 2) self.assertRaises(TypeError, getsockfam, object())
L{getsockfam} accepts a single C{int} argument. If it is called in some other way, L{TypeError} is raised.
test_badArguments
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_syscallError(self): """ If the underlying C{getsockname} call fails, L{getsockfam} raises L{socket.error} with its errno set to the underlying errno value. """ with open(devnull) as probe: fd = probe.fileno() exc = self.assertRaises(error, getsockfam, fd) self.assertEqual(errno.EBADF, exc.args[0])
If the underlying C{getsockname} call fails, L{getsockfam} raises L{socket.error} with its errno set to the underlying errno value.
test_syscallError
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_inet(self): """ When passed the file descriptor of a socket created with the C{AF_INET} address family, L{getsockfam} returns C{AF_INET}. """ self.assertEqual(AF_INET, getsockfam(self._socket(AF_INET)))
When passed the file descriptor of a socket created with the C{AF_INET} address family, L{getsockfam} returns C{AF_INET}.
test_inet
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_inet6(self): """ When passed the file descriptor of a socket created with the C{AF_INET6} address family, L{getsockfam} returns C{AF_INET6}. """ self.assertEqual(AF_INET6, getsockfam(self._socket(AF_INET6)))
When passed the file descriptor of a socket created with the C{AF_INET6} address family, L{getsockfam} returns C{AF_INET6}.
test_inet6
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_unix(self): """ When passed the file descriptor of a socket created with the C{AF_UNIX} address family, L{getsockfam} returns C{AF_UNIX}. """ self.assertEqual(AF_UNIX, getsockfam(self._socket(AF_UNIX)))
When passed the file descriptor of a socket created with the C{AF_UNIX} address family, L{getsockfam} returns C{AF_UNIX}.
test_unix
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def setUp(self): """ Create a pair of UNIX sockets. """ self.input, self.output = socketpair(AF_UNIX)
Create a pair of UNIX sockets.
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def tearDown(self): """ Close the sockets opened by setUp. """ self.input.close() self.output.close()
Close the sockets opened by setUp.
tearDown
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_syscallError(self): """ If the underlying C{sendmsg} call fails, L{send1msg} raises L{socket.error} with its errno set to the underlying errno value. """ self.input.close() exc = self.assertRaises(error, sendmsg, self.input, b"hello, world") self.assertEqual(exc.args[0], errno.EBADF)
If the underlying C{sendmsg} call fails, L{send1msg} raises L{socket.error} with its errno set to the underlying errno value.
test_syscallError
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_syscallErrorWithControlMessage(self): """ The behavior when the underlying C{sendmsg} call fails is the same whether L{sendmsg} is passed ancillary data or not. """ self.input.close() exc = self.assertRaises( error, sendmsg, self.input, b"hello, world", [(0, 0, b"0123")], 0) self.assertEqual(exc.args[0], errno.EBADF)
The behavior when the underlying C{sendmsg} call fails is the same whether L{sendmsg} is passed ancillary data or not.
test_syscallErrorWithControlMessage
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_roundtrip(self): """ L{recvmsg} will retrieve a message sent via L{sendmsg}. """ message = b"hello, world!" self.assertEqual( len(message), sendmsg(self.input, message)) result = recvmsg(self.output) self.assertEqual(result.data, b"hello, world!") self.assertEqual(result.flags, 0) self.assertEqual(result.ancillary, [])
L{recvmsg} will retrieve a message sent via L{sendmsg}.
test_roundtrip
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_shortsend(self): """ L{sendmsg} returns the number of bytes which it was able to send. """ message = b"x" * 1024 * 1024 * 16 self.input.setblocking(False) sent = sendmsg(self.input, message) # Sanity check - make sure the amount of data we sent was less than the # message, but not the whole message, as we should have filled the send # buffer. This won't work if the send buffer is large enough for # message, though. self.assertTrue(sent < len(message)) received = recvmsg(self.output, len(message)) self.assertEqual(len(received[0]), sent)
L{sendmsg} returns the number of bytes which it was able to send.
test_shortsend
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_roundtripEmptyAncillary(self): """ L{sendmsg} treats an empty ancillary data list the same way it treats receiving no argument for the ancillary parameter at all. """ sendmsg(self.input, b"hello, world!", [], 0) result = recvmsg(self.output) self.assertEqual(result, (b"hello, world!", [], 0))
L{sendmsg} treats an empty ancillary data list the same way it treats receiving no argument for the ancillary parameter at all.
test_roundtripEmptyAncillary
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_flags(self): """ The C{flags} argument to L{sendmsg} is passed on to the underlying C{sendmsg} call, to affect it in whatever way is defined by those flags. """ # Just exercise one flag with simple, well-known behavior. MSG_DONTWAIT # makes the send a non-blocking call, even if the socket is in blocking # mode. See also test_flags in RecvmsgTests for i in range(8 * 1024): try: sendmsg(self.input, b"x" * 1024, flags=MSG_DONTWAIT) except error as e: self.assertEqual(e.args[0], errno.EAGAIN) break else: self.fail( "Failed to fill up the send buffer, " "or maybe send1msg blocked for a while")
The C{flags} argument to L{sendmsg} is passed on to the underlying C{sendmsg} call, to affect it in whatever way is defined by those flags.
test_flags
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_sendSubProcessFD(self): """ Calling L{sendmsg} with SOL_SOCKET, SCM_RIGHTS, and a platform-endian packed file descriptor number should send that file descriptor to a different process, where it can be retrieved by using L{recv1msg}. """ sspp = _spawn("pullpipe", self.output.fileno()) yield sspp.started pipeOut, pipeIn = _makePipe() self.addCleanup(pipeOut.close) self.addCleanup(pipeIn.close) with pipeIn: sendmsg( self.input, b"blonk", [(SOL_SOCKET, SCM_RIGHTS, pack("i", pipeIn.fileno()))]) yield sspp.stopped self.assertEqual(read(pipeOut.fileno(), 1024), b"Test fixture data: blonk.\n") # Make sure that the pipe is actually closed now. self.assertEqual(read(pipeOut.fileno(), 1024), b"")
Calling L{sendmsg} with SOL_SOCKET, SCM_RIGHTS, and a platform-endian packed file descriptor number should send that file descriptor to a different process, where it can be retrieved by using L{recv1msg}.
test_sendSubProcessFD
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def _socket(self, addressFamily): """ Create a new socket using the given address family and return that socket's file descriptor. The socket will automatically be closed when the test is torn down. """ s = socket(addressFamily) self.addCleanup(s.close) return s
Create a new socket using the given address family and return that socket's file descriptor. The socket will automatically be closed when the test is torn down.
_socket
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_inet(self): """ When passed the file descriptor of a socket created with the C{AF_INET} address family, L{getSocketFamily} returns C{AF_INET}. """ self.assertEqual(AF_INET, getSocketFamily(self._socket(AF_INET)))
When passed the file descriptor of a socket created with the C{AF_INET} address family, L{getSocketFamily} returns C{AF_INET}.
test_inet
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_inet6(self): """ When passed the file descriptor of a socket created with the C{AF_INET6} address family, L{getSocketFamily} returns C{AF_INET6}. """ self.assertEqual(AF_INET6, getSocketFamily(self._socket(AF_INET6)))
When passed the file descriptor of a socket created with the C{AF_INET6} address family, L{getSocketFamily} returns C{AF_INET6}.
test_inet6
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def test_unix(self): """ When passed the file descriptor of a socket created with the C{AF_UNIX} address family, L{getSocketFamily} returns C{AF_UNIX}. """ self.assertEqual(AF_UNIX, getSocketFamily(self._socket(AF_UNIX)))
When passed the file descriptor of a socket created with the C{AF_UNIX} address family, L{getSocketFamily} returns C{AF_UNIX}.
test_unix
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_sendmsg.py
MIT
def zipit(dirname, zfname): """ Create a zipfile on zfname, containing the contents of dirname' """ dirname = _coerceToFilesystemEncoding('', dirname) zfname = _coerceToFilesystemEncoding('', zfname) with zipfile.ZipFile(zfname, "w") as zf: for root, ignored, files, in os.walk(dirname): for fname in files: fspath = os.path.join(root, fname) arcpath = os.path.join(root, fname)[len(dirname)+1:] zf.write(fspath, arcpath)
Create a zipfile on zfname, containing the contents of dirname'
zipit
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_zippath.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_zippath.py
MIT
def test_zipPathRepr(self): """ Make sure that invoking ZipPath's repr prints the correct class name and an absolute path to the zip file. """ child = self.path.child("foo") pathRepr = "ZipPath(%r)" % ( os.path.abspath(self.nativecmn + ".zip" + os.sep + 'foo'),) # Check for an absolute path self.assertEqual(repr(child), pathRepr) # Create a path to the file rooted in the current working directory relativeCommon = self.nativecmn.replace(os.getcwd() + os.sep, "", 1) + ".zip" relpath = ZipArchive(relativeCommon) child = relpath.child("foo") # Check using a path without the cwd prepended self.assertEqual(repr(child), pathRepr)
Make sure that invoking ZipPath's repr prints the correct class name and an absolute path to the zip file.
test_zipPathRepr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_zippath.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_zippath.py
MIT
def test_zipPathReprParentDirSegment(self): """ The repr of a ZipPath with C{".."} in the internal part of its path includes the C{".."} rather than applying the usual parent directory meaning. """ child = self.path.child("foo").child("..").child("bar") pathRepr = "ZipPath(%r)" % ( self.nativecmn + ".zip" + os.sep.join(["", "foo", "..", "bar"])) self.assertEqual(repr(child), pathRepr)
The repr of a ZipPath with C{".."} in the internal part of its path includes the C{".."} rather than applying the usual parent directory meaning.
test_zipPathReprParentDirSegment
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_zippath.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_zippath.py
MIT
def test_zipArchiveRepr(self): """ Make sure that invoking ZipArchive's repr prints the correct class name and an absolute path to the zip file. """ path = ZipArchive(self.nativecmn + '.zip') pathRepr = 'ZipArchive(%r)' % (os.path.abspath( self.nativecmn + '.zip'),) # Check for an absolute path self.assertEqual(repr(path), pathRepr) # Create a path to the file rooted in the current working directory relativeCommon = self.nativecmn.replace(os.getcwd() + os.sep, "", 1) + ".zip" relpath = ZipArchive(relativeCommon) # Check using a path without the cwd prepended self.assertEqual(repr(relpath), pathRepr)
Make sure that invoking ZipArchive's repr prints the correct class name and an absolute path to the zip file.
test_zipArchiveRepr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_zippath.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_zippath.py
MIT
def test_uidFromNumericString(self): """ When L{uidFromString} is called with a base-ten string representation of an integer, it returns the integer. """ self.assertEqual(util.uidFromString("100"), 100)
When L{uidFromString} is called with a base-ten string representation of an integer, it returns the integer.
test_uidFromNumericString
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_uidFromUsernameString(self): """ When L{uidFromString} is called with a base-ten string representation of an integer, it returns the integer. """ pwent = pwd.getpwuid(os.getuid()) self.assertEqual(util.uidFromString(pwent.pw_name), pwent.pw_uid)
When L{uidFromString} is called with a base-ten string representation of an integer, it returns the integer.
test_uidFromUsernameString
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_gidFromNumericString(self): """ When L{gidFromString} is called with a base-ten string representation of an integer, it returns the integer. """ self.assertEqual(util.gidFromString("100"), 100)
When L{gidFromString} is called with a base-ten string representation of an integer, it returns the integer.
test_gidFromNumericString
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_gidFromGroupnameString(self): """ When L{gidFromString} is called with a base-ten string representation of an integer, it returns the integer. """ grent = grp.getgrgid(os.getgid()) self.assertEqual(util.gidFromString(grent.gr_name), grent.gr_gid)
When L{gidFromString} is called with a base-ten string representation of an integer, it returns the integer.
test_gidFromGroupnameString
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_nameToLabel(self): """ Test the various kinds of inputs L{nameToLabel} supports. """ nameData = [ ('f', 'F'), ('fo', 'Fo'), ('foo', 'Foo'), ('fooBar', 'Foo Bar'), ('fooBarBaz', 'Foo Bar Baz'), ] for inp, out in nameData: got = util.nameToLabel(inp) self.assertEqual( got, out, "nameToLabel(%r) == %r != %r" % (inp, got, out))
Test the various kinds of inputs L{nameToLabel} supports.
test_nameToLabel
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_uninterruptably(self): """ L{untilConcludes} calls the function passed to it until the function does not raise either L{OSError} or L{IOError} with C{errno} of C{EINTR}. It otherwise completes with the same result as the function passed to it. """ def f(a, b): self.calls += 1 exc = self.exceptions.pop() if exc is not None: raise exc(errno.EINTR, "Interrupted system call!") return a + b self.exceptions = [None] self.calls = 0 self.assertEqual(util.untilConcludes(f, 1, 2), 3) self.assertEqual(self.calls, 1) self.exceptions = [None, OSError, IOError] self.calls = 0 self.assertEqual(util.untilConcludes(f, 2, 3), 5) self.assertEqual(self.calls, 3)
L{untilConcludes} calls the function passed to it until the function does not raise either L{OSError} or L{IOError} with C{errno} of C{EINTR}. It otherwise completes with the same result as the function passed to it.
test_uninterruptably
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def initgroups(self, uid, gid): """ Save L{util.initgroups} calls in C{self.initgroupsCalls}. """ self.initgroupsCalls.append((uid, gid))
Save L{util.initgroups} calls in C{self.initgroupsCalls}.
initgroups
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_uid(self): """ L{util.switchUID} calls L{util.initgroups} and then C{os.setuid} with the given uid. """ util.switchUID(12000, None) self.assertEqual(self.initgroupsCalls, [(12000, None)]) self.assertEqual(self.mockos.actions, [("setuid", 12000)])
L{util.switchUID} calls L{util.initgroups} and then C{os.setuid} with the given uid.
test_uid
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_euid(self): """ L{util.switchUID} calls L{util.initgroups} and then C{os.seteuid} with the given uid if the C{euid} parameter is set to C{True}. """ util.switchUID(12000, None, True) self.assertEqual(self.initgroupsCalls, [(12000, None)]) self.assertEqual(self.mockos.seteuidCalls, [12000])
L{util.switchUID} calls L{util.initgroups} and then C{os.seteuid} with the given uid if the C{euid} parameter is set to C{True}.
test_euid
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_currentUID(self): """ If the current uid is the same as the uid passed to L{util.switchUID}, then initgroups does not get called, but a warning is issued. """ uid = self.mockos.getuid() util.switchUID(uid, None) self.assertEqual(self.initgroupsCalls, []) self.assertEqual(self.mockos.actions, []) currentWarnings = self.flushWarnings([util.switchUID]) self.assertEqual(len(currentWarnings), 1) self.assertIn('tried to drop privileges and setuid %i' % uid, currentWarnings[0]['message']) self.assertIn( 'but uid is already %i' % uid, currentWarnings[0]['message'])
If the current uid is the same as the uid passed to L{util.switchUID}, then initgroups does not get called, but a warning is issued.
test_currentUID
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_currentEUID(self): """ If the current euid is the same as the euid passed to L{util.switchUID}, then initgroups does not get called, but a warning is issued. """ euid = self.mockos.geteuid() util.switchUID(euid, None, True) self.assertEqual(self.initgroupsCalls, []) self.assertEqual(self.mockos.seteuidCalls, []) currentWarnings = self.flushWarnings([util.switchUID]) self.assertEqual(len(currentWarnings), 1) self.assertIn('tried to drop privileges and seteuid %i' % euid, currentWarnings[0]['message']) self.assertIn( 'but euid is already %i' % euid, currentWarnings[0]['message'])
If the current euid is the same as the euid passed to L{util.switchUID}, then initgroups does not get called, but a warning is issued.
test_currentEUID
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_mergedFunctionBehavesLikeMergeTarget(self): """ After merging C{foo}'s data into C{bar}, the returned function behaves as if it is C{bar}. """ foo_object = object() bar_object = object() def foo(): return foo_object def bar(x, y, ab, c=10, *d, **e): (a, b) = ab return bar_object baz = util.mergeFunctionMetadata(foo, bar) self.assertIs(baz(1, 2, (3, 4), quux=10), bar_object)
After merging C{foo}'s data into C{bar}, the returned function behaves as if it is C{bar}.
test_mergedFunctionBehavesLikeMergeTarget
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_moduleIsMerged(self): """ Merging C{foo} into C{bar} returns a function with C{foo}'s C{__module__}. """ def foo(): pass def bar(): pass bar.__module__ = 'somewhere.else' baz = util.mergeFunctionMetadata(foo, bar) self.assertEqual(baz.__module__, foo.__module__)
Merging C{foo} into C{bar} returns a function with C{foo}'s C{__module__}.
test_moduleIsMerged
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def foo(): """ This is foo. """
This is foo.
test_docstringIsMerged.foo
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def bar(): """ This is bar. """
This is bar.
test_docstringIsMerged.bar
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_docstringIsMerged(self): """ Merging C{foo} into C{bar} returns a function with C{foo}'s docstring. """ def foo(): """ This is foo. """ def bar(): """ This is bar. """ baz = util.mergeFunctionMetadata(foo, bar) self.assertEqual(baz.__doc__, foo.__doc__)
Merging C{foo} into C{bar} returns a function with C{foo}'s docstring.
test_docstringIsMerged
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_nameIsMerged(self): """ Merging C{foo} into C{bar} returns a function with C{foo}'s name. """ def foo(): pass def bar(): pass baz = util.mergeFunctionMetadata(foo, bar) self.assertEqual(baz.__name__, foo.__name__)
Merging C{foo} into C{bar} returns a function with C{foo}'s name.
test_nameIsMerged
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_instanceDictionaryIsMerged(self): """ Merging C{foo} into C{bar} returns a function with C{bar}'s dictionary, updated by C{foo}'s. """ def foo(): pass foo.a = 1 foo.b = 2 def bar(): pass bar.b = 3 bar.c = 4 baz = util.mergeFunctionMetadata(foo, bar) self.assertEqual(foo.a, baz.a) self.assertEqual(foo.b, baz.b) self.assertEqual(bar.c, baz.c)
Merging C{foo} into C{bar} returns a function with C{bar}'s dictionary, updated by C{foo}'s.
test_instanceDictionaryIsMerged
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_deprecated(self): """ L{util.OrderedDict} is deprecated. """ from twisted.python.util import OrderedDict OrderedDict # Shh pyflakes currentWarnings = self.flushWarnings(offendingFunctions=[ self.test_deprecated]) self.assertEqual( currentWarnings[0]['message'], "twisted.python.util.OrderedDict was deprecated in Twisted " "15.5.0: Use collections.OrderedDict instead.") self.assertEqual(currentWarnings[0]['category'], DeprecationWarning) self.assertEqual(len(currentWarnings), 1)
L{util.OrderedDict} is deprecated.
test_deprecated
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_preserve(self): """ L{util.InsensitiveDict} preserves the case of keys if constructed with C{preserve=True}. """ dct = util.InsensitiveDict({'Foo':'bar', 1:2, 'fnz':{1:2}}, preserve=1) self.assertEqual(dct['fnz'], {1:2}) self.assertEqual(dct['foo'], 'bar') self.assertEqual(dct.copy(), dct) self.assertEqual(dct['foo'], dct.get('Foo')) self.assertIn(1, dct) self.assertIn('foo', dct) result = eval(repr(dct), { 'dct': dct, 'InsensitiveDict': util.InsensitiveDict, }) self.assertEqual(result, dct) keys=['Foo', 'fnz', 1] for x in keys: self.assertIn(x, dct.keys()) self.assertIn((x, dct[x]), dct.items()) self.assertEqual(len(keys), len(dct)) del dct[1] del dct['foo'] self.assertEqual(dct.keys(), ['fnz'])
L{util.InsensitiveDict} preserves the case of keys if constructed with C{preserve=True}.
test_preserve
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_noPreserve(self): """ L{util.InsensitiveDict} does not preserves the case of keys if constructed with C{preserve=False}. """ dct = util.InsensitiveDict({'Foo':'bar', 1:2, 'fnz':{1:2}}, preserve=0) keys=['foo', 'fnz', 1] for x in keys: self.assertIn(x, dct.keys()) self.assertIn((x, dct[x]), dct.items()) self.assertEqual(len(keys), len(dct)) del dct[1] del dct['foo'] self.assertEqual(dct.keys(), ['fnz'])
L{util.InsensitiveDict} does not preserves the case of keys if constructed with C{preserve=False}.
test_noPreserve
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_unicode(self): """ Unicode keys are case insensitive. """ d = util.InsensitiveDict(preserve=False) d[u"Foo"] = 1 self.assertEqual(d[u"FOO"], 1) self.assertEqual(d.keys(), [u"foo"])
Unicode keys are case insensitive.
test_unicode
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_bytes(self): """ Bytes keys are case insensitive. """ d = util.InsensitiveDict(preserve=False) d[b"Foo"] = 1 self.assertEqual(d[b"FOO"], 1) self.assertEqual(d.keys(), [b"foo"])
Bytes keys are case insensitive.
test_bytes
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_stdin(self): """ Making sure getPassword accepts a password from standard input by running a child process which uses getPassword to read in a string which it then writes it out again. Write a string to the child process and then read one and make sure it is the right string. """ p = PasswordTestingProcessProtocol() p.finished = Deferred() reactor.spawnProcess( p, pyExe, [pyExe, b'-c', (b'import sys\n' b'from twisted.python.util import getPassword\n' b'sys.stdout.write(getPassword())\n' b'sys.stdout.flush()\n')], env={b'PYTHONPATH': os.pathsep.join(sys.path).encode("utf8")}) def processFinished(result): (reason, output) = result reason.trap(ProcessDone) self.assertIn((1, b'secret'), output) return p.finished.addCallback(processFinished)
Making sure getPassword accepts a password from standard input by running a child process which uses getPassword to read in a string which it then writes it out again. Write a string to the child process and then read one and make sure it is the right string.
test_stdin
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_identity(self): """ Instances of a class which mixes in L{FancyEqMixin} but which defines no comparison attributes compare by identity. """ class Empty(util.FancyEqMixin): pass self.assertFalse(Empty() == Empty()) self.assertTrue(Empty() != Empty()) empty = Empty() self.assertTrue(empty == empty) self.assertFalse(empty != empty)
Instances of a class which mixes in L{FancyEqMixin} but which defines no comparison attributes compare by identity.
test_identity
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_equality(self): """ Instances of a class which mixes in L{FancyEqMixin} should compare equal if all of their attributes compare equal. They should not compare equal if any of their attributes do not compare equal. """ self.assertTrue(Record(1, 2) == Record(1, 2)) self.assertFalse(Record(1, 2) == Record(1, 3)) self.assertFalse(Record(1, 2) == Record(2, 2)) self.assertFalse(Record(1, 2) == Record(3, 4))
Instances of a class which mixes in L{FancyEqMixin} should compare equal if all of their attributes compare equal. They should not compare equal if any of their attributes do not compare equal.
test_equality
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_unequality(self): """ Inequality between instances of a particular L{record} should be defined as the negation of equality. """ self.assertFalse(Record(1, 2) != Record(1, 2)) self.assertTrue(Record(1, 2) != Record(1, 3)) self.assertTrue(Record(1, 2) != Record(2, 2)) self.assertTrue(Record(1, 2) != Record(3, 4))
Inequality between instances of a particular L{record} should be defined as the negation of equality.
test_unequality
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_differentClassesEquality(self): """ Instances of different classes which mix in L{FancyEqMixin} should not compare equal. """ self.assertFalse(Record(1, 2) == DifferentRecord(1, 2))
Instances of different classes which mix in L{FancyEqMixin} should not compare equal.
test_differentClassesEquality
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_differentClassesInequality(self): """ Instances of different classes which mix in L{FancyEqMixin} should compare unequal. """ self.assertTrue(Record(1, 2) != DifferentRecord(1, 2))
Instances of different classes which mix in L{FancyEqMixin} should compare unequal.
test_differentClassesInequality
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_inheritedClassesEquality(self): """ An instance of a class which derives from a class which mixes in L{FancyEqMixin} should compare equal to an instance of the base class if and only if all of their attributes compare equal. """ self.assertTrue(Record(1, 2) == DerivedRecord(1, 2)) self.assertFalse(Record(1, 2) == DerivedRecord(1, 3)) self.assertFalse(Record(1, 2) == DerivedRecord(2, 2)) self.assertFalse(Record(1, 2) == DerivedRecord(3, 4))
An instance of a class which derives from a class which mixes in L{FancyEqMixin} should compare equal to an instance of the base class if and only if all of their attributes compare equal.
test_inheritedClassesEquality
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_inheritedClassesInequality(self): """ An instance of a class which derives from a class which mixes in L{FancyEqMixin} should compare unequal to an instance of the base class if any of their attributes compare unequal. """ self.assertFalse(Record(1, 2) != DerivedRecord(1, 2)) self.assertTrue(Record(1, 2) != DerivedRecord(1, 3)) self.assertTrue(Record(1, 2) != DerivedRecord(2, 2)) self.assertTrue(Record(1, 2) != DerivedRecord(3, 4))
An instance of a class which derives from a class which mixes in L{FancyEqMixin} should compare unequal to an instance of the base class if any of their attributes compare unequal.
test_inheritedClassesInequality
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_rightHandArgumentImplementsEquality(self): """ The right-hand argument to the equality operator is given a chance to determine the result of the operation if it is of a type unrelated to the L{FancyEqMixin}-based instance on the left-hand side. """ self.assertTrue(Record(1, 2) == EqualToEverything()) self.assertFalse(Record(1, 2) == EqualToNothing())
The right-hand argument to the equality operator is given a chance to determine the result of the operation if it is of a type unrelated to the L{FancyEqMixin}-based instance on the left-hand side.
test_rightHandArgumentImplementsEquality
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_rightHandArgumentImplementsUnequality(self): """ The right-hand argument to the non-equality operator is given a chance to determine the result of the operation if it is of a type unrelated to the L{FancyEqMixin}-based instance on the left-hand side. """ self.assertFalse(Record(1, 2) != EqualToEverything()) self.assertTrue(Record(1, 2) != EqualToNothing())
The right-hand argument to the non-equality operator is given a chance to determine the result of the operation if it is of a type unrelated to the L{FancyEqMixin}-based instance on the left-hand side.
test_rightHandArgumentImplementsUnequality
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def _securedFunction(self, startUID, startGID, wantUID, wantGID): """ Check if wanted UID/GID matched start or saved ones. """ self.assertTrue(wantUID == startUID or wantUID == self.mockos.seteuidCalls[-1]) self.assertTrue(wantGID == startGID or wantGID == self.mockos.setegidCalls[-1])
Check if wanted UID/GID matched start or saved ones.
_securedFunction
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_forwardResult(self): """ L{util.runAsEffectiveUser} forwards the result obtained by calling the given function """ result = util.runAsEffectiveUser(0, 0, lambda: 1) self.assertEqual(result, 1)
L{util.runAsEffectiveUser} forwards the result obtained by calling the given function
test_forwardResult
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_takeParameters(self): """ L{util.runAsEffectiveUser} pass the given parameters to the given function. """ result = util.runAsEffectiveUser(0, 0, lambda x: 2*x, 3) self.assertEqual(result, 6)
L{util.runAsEffectiveUser} pass the given parameters to the given function.
test_takeParameters
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_takesKeyworkArguments(self): """ L{util.runAsEffectiveUser} pass the keyword parameters to the given function. """ result = util.runAsEffectiveUser(0, 0, lambda x, y=1, z=1: x*y*z, 2, z=3) self.assertEqual(result, 6)
L{util.runAsEffectiveUser} pass the keyword parameters to the given function.
test_takesKeyworkArguments
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def _testUIDGIDSwitch(self, startUID, startGID, wantUID, wantGID, expectedUIDSwitches, expectedGIDSwitches): """ Helper method checking the calls to C{os.seteuid} and C{os.setegid} made by L{util.runAsEffectiveUser}, when switching from startUID to wantUID and from startGID to wantGID. """ self.mockos.euid = startUID self.mockos.egid = startGID util.runAsEffectiveUser( wantUID, wantGID, self._securedFunction, startUID, startGID, wantUID, wantGID) self.assertEqual(self.mockos.seteuidCalls, expectedUIDSwitches) self.assertEqual(self.mockos.setegidCalls, expectedGIDSwitches) self.mockos.seteuidCalls = [] self.mockos.setegidCalls = []
Helper method checking the calls to C{os.seteuid} and C{os.setegid} made by L{util.runAsEffectiveUser}, when switching from startUID to wantUID and from startGID to wantGID.
_testUIDGIDSwitch
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_root(self): """ Check UID/GID switches when current effective UID is root. """ self._testUIDGIDSwitch(0, 0, 0, 0, [], []) self._testUIDGIDSwitch(0, 0, 1, 0, [1, 0], []) self._testUIDGIDSwitch(0, 0, 0, 1, [], [1, 0]) self._testUIDGIDSwitch(0, 0, 1, 1, [1, 0], [1, 0])
Check UID/GID switches when current effective UID is root.
test_root
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_UID(self): """ Check UID/GID switches when current effective UID is non-root. """ self._testUIDGIDSwitch(1, 0, 0, 0, [0, 1], []) self._testUIDGIDSwitch(1, 0, 1, 0, [], []) self._testUIDGIDSwitch(1, 0, 1, 1, [0, 1, 0, 1], [1, 0]) self._testUIDGIDSwitch(1, 0, 2, 1, [0, 2, 0, 1], [1, 0])
Check UID/GID switches when current effective UID is non-root.
test_UID
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_GID(self): """ Check UID/GID switches when current effective GID is non-root. """ self._testUIDGIDSwitch(0, 1, 0, 0, [], [0, 1]) self._testUIDGIDSwitch(0, 1, 0, 1, [], []) self._testUIDGIDSwitch(0, 1, 1, 1, [1, 0], []) self._testUIDGIDSwitch(0, 1, 1, 2, [1, 0], [2, 1])
Check UID/GID switches when current effective GID is non-root.
test_GID
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_UIDGID(self): """ Check UID/GID switches when current effective UID/GID is non-root. """ self._testUIDGIDSwitch(1, 1, 0, 0, [0, 1], [0, 1]) self._testUIDGIDSwitch(1, 1, 0, 1, [0, 1], []) self._testUIDGIDSwitch(1, 1, 1, 0, [0, 1, 0, 1], [0, 1]) self._testUIDGIDSwitch(1, 1, 1, 1, [], []) self._testUIDGIDSwitch(1, 1, 2, 1, [0, 2, 0, 1], []) self._testUIDGIDSwitch(1, 1, 1, 2, [0, 1, 0, 1], [2, 1]) self._testUIDGIDSwitch(1, 1, 2, 2, [0, 2, 0, 1], [2, 1])
Check UID/GID switches when current effective UID/GID is non-root.
test_UIDGID
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_initgroupsInStdlib(self): """ Calling L{util.initgroups} will call the underlying stdlib implmentation. """ calls = [] def mockInitgroups(x, y): calls.append((x, y)) self.patch(util, "_initgroups", mockInitgroups) setgroupsCalls = [] self.patch(util, "setgroups", setgroupsCalls.append) util.initgroups(os.getuid(), 4) self.assertEqual(calls, [(pwd.getpwuid(os.getuid()).pw_name, 4)]) self.assertFalse(setgroupsCalls)
Calling L{util.initgroups} will call the underlying stdlib implmentation.
test_initgroupsInStdlib
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_initgroupsNoneGid(self): """ Calling L{util.initgroups} with None for gid gives an error. """ self.assertRaises(TypeError, util.initgroups, os.getuid(), None)
Calling L{util.initgroups} with None for gid gives an error.
test_initgroupsNoneGid
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_getPluginDirs(self): """ L{util.getPluginDirs} is deprecated. """ util.getPluginDirs() currentWarnings = self.flushWarnings(offendingFunctions=[ self.test_getPluginDirs]) self.assertEqual( currentWarnings[0]['message'], "twisted.python.util.getPluginDirs is deprecated since Twisted " "12.2.") self.assertEqual(currentWarnings[0]['category'], DeprecationWarning) self.assertEqual(len(currentWarnings), 1)
L{util.getPluginDirs} is deprecated.
test_getPluginDirs
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_addPluginDir(self): """ L{util.addPluginDir} is deprecated. """ util.addPluginDir() currentWarnings = self.flushWarnings(offendingFunctions=[ self.test_addPluginDir]) self.assertEqual( currentWarnings[0]['message'], "twisted.python.util.addPluginDir is deprecated since Twisted " "12.2.") self.assertEqual(currentWarnings[0]['category'], DeprecationWarning) self.assertEqual(len(currentWarnings), 1)
L{util.addPluginDir} is deprecated.
test_addPluginDir
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_runWithWarningsSuppressedFiltered(self): """ Warnings from the function called by C{runWithWarningsSuppressed} are suppressed if they match the passed in filter. """ filters = [(("ignore", ".*foo.*"), {}), (("ignore", ".*bar.*"), {})] self.runWithWarningsSuppressed(filters, warnings.warn, "ignore foo") self.runWithWarningsSuppressed(filters, warnings.warn, "ignore bar") self.assertEqual([], self.flushWarnings())
Warnings from the function called by C{runWithWarningsSuppressed} are suppressed if they match the passed in filter.
test_runWithWarningsSuppressedFiltered
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_runWithWarningsSuppressedUnfiltered(self): """ Warnings from the function called by C{runWithWarningsSuppressed} are not suppressed if they do not match the passed in filter. """ filters = [(("ignore", ".*foo.*"), {}), (("ignore", ".*bar.*"), {})] self.runWithWarningsSuppressed(filters, warnings.warn, "don't ignore") self.assertEqual( ["don't ignore"], [w['message'] for w in self.flushWarnings()])
Warnings from the function called by C{runWithWarningsSuppressed} are not suppressed if they do not match the passed in filter.
test_runWithWarningsSuppressedUnfiltered
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_passThrough(self): """ C{runWithWarningsSuppressed} returns the result of the function it called. """ self.assertEqual(self.runWithWarningsSuppressed([], lambda: 4), 4)
C{runWithWarningsSuppressed} returns the result of the function it called.
test_passThrough
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_noSideEffects(self): """ Once C{runWithWarningsSuppressed} has returned, it no longer suppresses warnings. """ filters = [(("ignore", ".*foo.*"), {}), (("ignore", ".*bar.*"), {})] self.runWithWarningsSuppressed(filters, lambda: None) warnings.warn("ignore foo") self.assertEqual( ["ignore foo"], [w['message'] for w in self.flushWarnings()])
Once C{runWithWarningsSuppressed} has returned, it no longer suppresses warnings.
test_noSideEffects
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_sequenceOfStrings(self): """ If C{showAttributes} is set to a sequence of strings, C{__str__} renders using those by looking them up as attributes on the object. """ class Foo(util.FancyStrMixin): showAttributes = ("first", "second") first = 1 second = "hello" self.assertEqual(str(Foo()), "<Foo first=1 second='hello'>")
If C{showAttributes} is set to a sequence of strings, C{__str__} renders using those by looking them up as attributes on the object.
test_sequenceOfStrings
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_formatter(self): """ If C{showAttributes} has an item that is a 2-tuple, C{__str__} renders the first item in the tuple as a key and the result of calling the second item with the value of the attribute named by the first item as the value. """ class Foo(util.FancyStrMixin): showAttributes = ( "first", ("second", lambda value: repr(value[::-1]))) first = "hello" second = "world" self.assertEqual("<Foo first='hello' second='dlrow'>", str(Foo()))
If C{showAttributes} has an item that is a 2-tuple, C{__str__} renders the first item in the tuple as a key and the result of calling the second item with the value of the attribute named by the first item as the value.
test_formatter
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_override(self): """ If C{showAttributes} has an item that is a 3-tuple, C{__str__} renders the second item in the tuple as a key, and the contents of the attribute named in the first item are rendered as the value. The value is formatted using the third item in the tuple. """ class Foo(util.FancyStrMixin): showAttributes = ("first", ("second", "2nd", "%.1f")) first = 1 second = 2.111 self.assertEqual(str(Foo()), "<Foo first=1 2nd=2.1>")
If C{showAttributes} has an item that is a 3-tuple, C{__str__} renders the second item in the tuple as a key, and the contents of the attribute named in the first item are rendered as the value. The value is formatted using the third item in the tuple.
test_override
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_fancybasename(self): """ If C{fancybasename} is present, C{__str__} uses it instead of the class name. """ class Foo(util.FancyStrMixin): fancybasename = "Bar" self.assertEqual(str(Foo()), "<Bar>")
If C{fancybasename} is present, C{__str__} uses it instead of the class name.
test_fancybasename
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_repr(self): """ C{__repr__} outputs the same content as C{__str__}. """ class Foo(util.FancyStrMixin): showAttributes = ("first", "second") first = 1 second = "hello" obj = Foo() self.assertEqual(str(obj), repr(obj))
C{__repr__} outputs the same content as C{__str__}.
test_repr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_default(self): """ L{None} values can be added to a list to cause it to have a certain length. """ padded = util.padTo(3, []) self.assertEqual([None] * 3, padded)
L{None} values can be added to a list to cause it to have a certain length.
test_default
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_specificDefaultValue(self): """ A specific value can be added to a list to cause it to have a certain length. """ padded = util.padTo(4, [], "x") self.assertEqual(["x"] * 4, padded)
A specific value can be added to a list to cause it to have a certain length.
test_specificDefaultValue
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_padNonEmptyList(self): """ A list which already has some items has the padding value added after those items. """ padded = util.padTo(3, [1, 2], "z") self.assertEqual([1, 2, "z"], padded)
A list which already has some items has the padding value added after those items.
test_padNonEmptyList
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT
def test_padToSmallerSize(self): """ L{util.padTo} can't pad a list if the size requested is smaller than the size of the list to pad. """ self.assertRaises(ValueError, util.padTo, 1, [1, 2])
L{util.padTo} can't pad a list if the size requested is smaller than the size of the list to pad.
test_padToSmallerSize
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/python/test/test_util.py
MIT