Skip to content

Commit 54ed553

Browse files
authored
Testing out Python 3.10 (#156)
* Adding support for Python 3.10
1 parent 68de289 commit 54ed553

File tree

8 files changed

+29
-31
lines changed

8 files changed

+29
-31
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: [3.5, 3.6, 3.7, 3.8, 3.9, pypy3]
11+
python-version: ["3.5", "3.6", "3.7", "3.8", "3.9", "3.10.0-rc.2", "pypy3"]
1212

1313
steps:
1414
- uses: actions/checkout@v2

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/make -f
22

3-
VERSION := $(shell python -c 'import mocket; print(mocket.__version__)')
4-
53
install-dev-requirements:
64
pip install pipenv==2020.11.15
75

@@ -11,7 +9,7 @@ install-test-requirements:
119

1210
test-python:
1311
@echo "Running Python tests"
14-
pipenv run python setup.py -q test || exit 1
12+
pipenv run python run_tests.py || exit 1
1513
@echo ""
1614

1715
lint-python:
@@ -30,6 +28,7 @@ safetest:
3028
export SKIP_TRUE_REDIS=1; export SKIP_TRUE_HTTP=1; make test
3129

3230
publish: install-test-requirements
31+
VERSION := $(shell python -c 'import mocket; print(mocket.__version__)')
3332
pipenv run python -m build --sdist .
3433
pipenv run twine upload dist/mocket-$(VERSION).tar.gz
3534
pipenv run anaconda upload dist/mocket-$(VERSION).tar.gz

conftest.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

mocket/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__all__ = ("mocketize", "Mocket", "MocketEntry", "Mocketizer")
44

5-
__version__ = "3.9.44"
5+
__version__ = "3.10.0"

mocket/async_mocket.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import decorator
2-
31
from mocket import Mocketizer
2+
from mocket.utils import get_mocketize
43

54

65
async def wrapper(test, cls=Mocketizer, truesocket_recording_dir=None, *args, **kwargs):
@@ -22,10 +21,7 @@ async def wrapper(test, cls=Mocketizer, truesocket_recording_dir=None, *args, **
2221
return await test(*args, **kwargs)
2322

2423

25-
if decorator.__version__ < "5":
26-
async_mocketize = decorator.decorator(wrapper)
27-
else:
28-
async_mocketize = decorator.decorator(wrapper, kwsyntax=True)
24+
async_mocketize = get_mocketize(wrapper_=wrapper)
2925

3026

3127
__all__ = ("async_mocketize",)

mocket/mocket.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
from datetime import datetime, timedelta
1313
from json.decoder import JSONDecodeError
1414

15-
import decorator
1615
import urllib3
1716
from urllib3.connection import match_hostname as urllib3_match_hostname
1817
from urllib3.util.ssl_ import ssl_wrap_socket as urllib3_ssl_wrap_socket
1918
from urllib3.util.ssl_ import wrap_socket as urllib3_wrap_socket
2019

2120
from .compat import basestring, byte_type, decode_from_bytes, encode_to_bytes, text_type
22-
from .utils import SSL_PROTOCOL, MocketSocketCore, hexdump, hexload
21+
from .utils import SSL_PROTOCOL, MocketSocketCore, get_mocketize, hexdump, hexload
2322

2423
xxh32 = None
2524
try:
@@ -65,6 +64,11 @@ def __set__(self, *args):
6564

6665

6766
class FakeSSLContext(SuperFakeSSLContext):
67+
DUMMY_METHODS = (
68+
"load_default_certs",
69+
"load_verify_locations",
70+
"set_alpn_protocols",
71+
)
6872
sock = None
6973
post_handshake_auth = None
7074
_check_hostname = False
@@ -78,6 +82,8 @@ def check_hostname(self, *args):
7882
self._check_hostname = False
7983

8084
def __init__(self, sock=None, server_hostname=None, _context=None, *args, **kwargs):
85+
self._set_dummy_methods()
86+
8187
if isinstance(sock, MocketSocket):
8288
self.sock = sock
8389
self.sock._host = server_hostname
@@ -89,13 +95,12 @@ def __init__(self, sock=None, server_hostname=None, _context=None, *args, **kwar
8995
elif isinstance(sock, int) and true_ssl_context:
9096
self.context = true_ssl_context(sock)
9197

92-
@staticmethod
93-
def load_default_certs(*args, **kwargs):
94-
pass
98+
def _set_dummy_methods(self):
99+
def dummy_method(*args, **kwargs):
100+
pass
95101

96-
@staticmethod
97-
def load_verify_locations(*args, **kwargs):
98-
pass
102+
for m in self.DUMMY_METHODS:
103+
setattr(self, m, dummy_method)
99104

100105
@staticmethod
101106
def wrap_socket(sock=sock, *args, **kwargs):
@@ -640,7 +645,4 @@ def wrapper(test, cls=Mocketizer, truesocket_recording_dir=None, *args, **kwargs
640645
return test(*args, **kwargs)
641646

642647

643-
if decorator.__version__ < "5":
644-
mocketize = decorator.decorator(wrapper)
645-
else:
646-
mocketize = decorator.decorator(wrapper, kwsyntax=True)
648+
mocketize = get_mocketize(wrapper_=wrapper)

mocket/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,12 @@ def hexload(string):
3434
"""
3535
string_no_spaces = "".join(string.split())
3636
return encode_to_bytes(binascii.unhexlify(string_no_spaces))
37+
38+
39+
def get_mocketize(wrapper_):
40+
import decorator
41+
42+
if decorator.__version__ < "5":
43+
return decorator.decorator(wrapper_)
44+
else:
45+
return decorator.decorator(wrapper_, kwsyntax=True)

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def read_version(package):
4949
"dev": [],
5050
"pook": pook_requires, # plugins version supporting mocket.plugins.pook.MocketEngine
5151
},
52-
test_suite="run_tests.main",
5352
license="BSD",
5453
classifiers=[
5554
"Development Status :: 6 - Mature",

0 commit comments

Comments
 (0)