From bc2f929a6433bdf9b5510997ec5819485c8b4506 Mon Sep 17 00:00:00 2001 From: Giorgio Salluzzo Date: Sun, 3 Jan 2021 17:18:58 +0100 Subject: [PATCH 1/2] Yet another refactor. --- mocket/compat.py | 14 +++----------- mocket/mocket.py | 4 +--- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/mocket/compat.py b/mocket/compat.py index 5b5f017e..8165d7c2 100644 --- a/mocket/compat.py +++ b/mocket/compat.py @@ -2,28 +2,20 @@ import os import shlex -encoding = os.getenv("MOCKET_ENCODING", "utf-8") +ENCODING = os.getenv("MOCKET_ENCODING", "utf-8") text_type = str byte_type = bytes basestring = (str,) -FileNotFoundError = FileNotFoundError -BlockingIOError = BlockingIOError -try: - from json.decoder import JSONDecodeError -except ImportError: - JSONDecodeError = ValueError - - -def encode_to_bytes(s, encoding=encoding): +def encode_to_bytes(s, encoding=ENCODING): if isinstance(s, text_type): s = s.encode(encoding) return byte_type(s) -def decode_from_bytes(s, encoding=encoding): +def decode_from_bytes(s, encoding=ENCODING): if isinstance(s, byte_type): s = codecs.decode(s, encoding, "ignore") return text_type(s) diff --git a/mocket/mocket.py b/mocket/mocket.py index c4e3cafe..d8b1ab93 100644 --- a/mocket/mocket.py +++ b/mocket/mocket.py @@ -9,6 +9,7 @@ import socket import ssl from datetime import datetime, timedelta +from json.decoder import JSONDecodeError import decorator import urllib3 @@ -16,9 +17,6 @@ from urllib3.util.ssl_ import wrap_socket as urllib3_wrap_socket from .compat import ( - BlockingIOError, - FileNotFoundError, - JSONDecodeError, basestring, byte_type, decode_from_bytes, From e8add51e2e0a0ad8c200f43f8426be4a6fbbe331 Mon Sep 17 00:00:00 2001 From: Giorgio Salluzzo Date: Sun, 3 Jan 2021 17:36:28 +0100 Subject: [PATCH 2/2] Another refactor. --- Pipfile | 3 +++ run_tests.py | 17 +---------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/Pipfile b/Pipfile index deeedbff..f98fcf46 100644 --- a/Pipfile +++ b/Pipfile @@ -24,6 +24,9 @@ twine = "*" anaconda-client = "*" pipfile = "*" wheel = "*" +xxhash = "*" +aiohttp = "*" +async-timeout = "*" [requires] python_version = "3.8" diff --git a/run_tests.py b/run_tests.py index 8cfcfd64..61420451 100644 --- a/run_tests.py +++ b/run_tests.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -import os import sys @@ -11,24 +10,10 @@ def main(args=None): major, minor = sys.version_info[:2] - python35 = False - - extras = ["xxhash"] - - # aiohttp available on Python >=3.5 - if major == 3 and minor >= 5: - python35 = True - - extras += ["aiohttp", "async_timeout"] - - os.system("pipenv run pip install {}".format(" ".join(extras))) - if not any(a for a in args[1:] if not a.startswith("-")): args.append("tests/main") args.append("mocket") - - if python35: - args.append("tests/tests35") + args.append("tests/tests35") if major == 3 and minor >= 8: args.append("tests/tests38")