Merge pull request #2274 from corydolphin/failing-test
Adds failing test for socket.socketpair()
This commit is contained in:
commit
4e6eb25512
@ -268,10 +268,26 @@ class fakesock(object):
|
|||||||
_sent_data = []
|
_sent_data = []
|
||||||
|
|
||||||
def __init__(self, family=socket.AF_INET, type=socket.SOCK_STREAM,
|
def __init__(self, family=socket.AF_INET, type=socket.SOCK_STREAM,
|
||||||
protocol=0):
|
proto=0, fileno=None, _sock=None):
|
||||||
self.truesock = (old_socket(family, type, protocol)
|
"""
|
||||||
if httpretty.allow_net_connect
|
Matches both the Python 2 API:
|
||||||
else None)
|
def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None):
|
||||||
|
https://github.com/python/cpython/blob/2.7/Lib/socket.py
|
||||||
|
|
||||||
|
and the Python 3 API:
|
||||||
|
def __init__(self, family=-1, type=-1, proto=-1, fileno=None):
|
||||||
|
https://github.com/python/cpython/blob/3.5/Lib/socket.py
|
||||||
|
"""
|
||||||
|
if httpretty.allow_net_connect:
|
||||||
|
if PY3:
|
||||||
|
self.truesock = old_socket(family, type, proto, fileno)
|
||||||
|
else:
|
||||||
|
# If Python 2, if parameters are passed as arguments, instead of kwargs,
|
||||||
|
# the 4th argument `_sock` will be interpreted as the `fileno`.
|
||||||
|
# Check if _sock is none, and if so, pass fileno.
|
||||||
|
self.truesock = old_socket(family, type, proto, fileno or _sock)
|
||||||
|
else:
|
||||||
|
self.truesock = None
|
||||||
self._closed = True
|
self._closed = True
|
||||||
self.fd = FakeSockFile()
|
self.fd = FakeSockFile()
|
||||||
self.fd.socket = self
|
self.fd.socket = self
|
||||||
|
48
tests/test_core/test_socket.py
Normal file
48
tests/test_core/test_socket.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import unittest
|
||||||
|
from moto import mock_dynamodb2_deprecated, mock_dynamodb2
|
||||||
|
import socket
|
||||||
|
|
||||||
|
from six import PY3
|
||||||
|
|
||||||
|
|
||||||
|
class TestSocketPair(unittest.TestCase):
|
||||||
|
|
||||||
|
@mock_dynamodb2_deprecated
|
||||||
|
def test_asyncio_deprecated(self):
|
||||||
|
if PY3:
|
||||||
|
self.assertIn(
|
||||||
|
'moto.packages.httpretty.core.fakesock.socket',
|
||||||
|
str(socket.socket),
|
||||||
|
'Our mock should be present'
|
||||||
|
)
|
||||||
|
import asyncio
|
||||||
|
self.assertIsNotNone(asyncio.get_event_loop())
|
||||||
|
|
||||||
|
@mock_dynamodb2_deprecated
|
||||||
|
def test_socket_pair_deprecated(self):
|
||||||
|
|
||||||
|
# In Python2, the fakesocket is not set, for some reason.
|
||||||
|
if PY3:
|
||||||
|
self.assertIn(
|
||||||
|
'moto.packages.httpretty.core.fakesock.socket',
|
||||||
|
str(socket.socket),
|
||||||
|
'Our mock should be present'
|
||||||
|
)
|
||||||
|
a, b = socket.socketpair()
|
||||||
|
self.assertIsNotNone(a)
|
||||||
|
self.assertIsNotNone(b)
|
||||||
|
if a:
|
||||||
|
a.close()
|
||||||
|
if b:
|
||||||
|
b.close()
|
||||||
|
|
||||||
|
|
||||||
|
@mock_dynamodb2
|
||||||
|
def test_socket_pair(self):
|
||||||
|
a, b = socket.socketpair()
|
||||||
|
self.assertIsNotNone(a)
|
||||||
|
self.assertIsNotNone(b)
|
||||||
|
if a:
|
||||||
|
a.close()
|
||||||
|
if b:
|
||||||
|
b.close()
|
Loading…
Reference in New Issue
Block a user