From 101c47581ee8b2e541241ef1433205f770bd3dd2 Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 21 Nov 2017 21:51:13 -0400 Subject: [PATCH 1/5] Remove all sys.version_info checks, presuming Python 3.5+ --- tests/core/contracts/test_concise_contract.py | 10 +++---- tests/core/eth-module/test_accounts.py | 25 ++++------------- tests/core/eth-module/test_eth_contract.py | 4 +-- .../test_middleware_add_and_clear_api.py | 2 -- tests/core/middleware/test_stalecheck.py | 4 +-- tests/core/utilities/test_encoding.py | 15 ++--------- tests/core/utilities/test_validation.py | 3 +-- tests/core/web3-module/test_conversions.py | 27 +++---------------- tests/integration/test_ethereum_tester.py | 5 ---- tests/integration/test_ethtestrpc.py | 5 ---- tests/integration/test_goethereum.py | 5 ---- web3/__init__.py | 4 +-- web3/account.py | 9 +------ web3/utils/encoding.py | 14 +++------- web3/utils/formatters.py | 7 +---- web3/utils/signing.py | 14 +--------- web3/utils/six/__init__.py | 20 ++++---------- web3/utils/six/six.py | 8 ++++++ web3/utils/validation.py | 3 +-- 19 files changed, 42 insertions(+), 142 deletions(-) create mode 100644 web3/utils/six/six.py diff --git a/tests/core/contracts/test_concise_contract.py b/tests/core/contracts/test_concise_contract.py index 38d4c4eab4..de3d9136b6 100644 --- a/tests/core/contracts/test_concise_contract.py +++ b/tests/core/contracts/test_concise_contract.py @@ -13,7 +13,7 @@ ConciseMethod, ) -if sys.version_info >= (3, 3): +if sys.version_info >= (3, 5): from unittest.mock import Mock @@ -35,7 +35,7 @@ def zero_address_contract(web3, WithConstructorAddressArgumentsContract, EMPTY_A return ConciseContract(_address_contract) -@pytest.mark.skipif(sys.version_info < (3, 3), reason="needs Mock library from 3.3") +@pytest.mark.skipif(sys.version_info < (3, 5), reason="needs Mock library from 3.3") def test_concisecontract_call_default(): contract = Mock() sweet_method = ConciseMethod(contract, 'grail') @@ -44,7 +44,7 @@ def test_concisecontract_call_default(): contract.call().grail.assert_called_once_with(1, 2) -@pytest.mark.skipif(sys.version_info < (3, 3), reason="needs Mock library from 3.3") +@pytest.mark.skipif(sys.version_info < (3, 5), reason="needs Mock library from 3.3") def test_concisecontract_custom_transact(): contract = Mock() sweet_method = ConciseMethod(contract, 'grail') @@ -53,7 +53,7 @@ def test_concisecontract_custom_transact(): contract.transact().grail.assert_called_once_with(1, 2) -@pytest.mark.skipif(sys.version_info < (3, 3), reason="needs Mock library from 3.3") +@pytest.mark.skipif(sys.version_info < (3, 5), reason="needs Mock library from 3.3") def test_concisecontract_two_keywords_fail(): contract = Mock() sweet_method = ConciseMethod(contract, 'grail') @@ -61,7 +61,7 @@ def test_concisecontract_two_keywords_fail(): sweet_method(1, 2, transact={'holy': 3}, call={'count_to': 4}) -@pytest.mark.skipif(sys.version_info < (3, 3), reason="needs Mock library from 3.3") +@pytest.mark.skipif(sys.version_info < (3, 5), reason="needs Mock library from 3.3") def test_concisecontract_unknown_keyword_fails(): contract = Mock() sweet_method = ConciseMethod(contract, 'grail') diff --git a/tests/core/eth-module/test_accounts.py b/tests/core/eth-module/test_accounts.py index a48aa86b06..72c37bde9c 100644 --- a/tests/core/eth-module/test_accounts.py +++ b/tests/core/eth-module/test_accounts.py @@ -48,23 +48,15 @@ ] -def to_hex_if_py2(val): - if sys.version_info.major < 3: - return to_hex(val) - else: - return val - - @pytest.fixture def PRIVATE_BYTES(): - key = b'unicorns' * 4 - return to_hex_if_py2(key) + return b'unicorns' * 4 @pytest.fixture def PRIVATE_BYTES_ALT(PRIVATE_BYTES): - key = b'rainbows' * 4 - return to_hex_if_py2(key) + return b'rainbows' * 4 + @pytest.fixture @@ -130,10 +122,7 @@ def test_eth_account_create_properties(acct): assert callable(account.sign) assert callable(account.signTransaction) assert is_checksum_address(account.address) - if sys.version_info.major < 3: - assert is_hex(account.privateKey) and len(account.privateKey) == 66 - else: - assert isinstance(account.privateKey, bytes) and len(account.privateKey) == 32 + assert isinstance(account.privateKey, bytes) and len(account.privateKey) == 32 def test_eth_account_recover_transaction_example(acct): @@ -170,9 +159,7 @@ def test_eth_account_recover_message(acct): ) def test_eth_account_recover_signature_bytes(acct, signature_bytes): msg_hash = b'\xbb\r\x8a\xba\x9f\xf7\xa1= (3, 3): +if sys.version_info >= (3, 5): from unittest.mock import Mock @@ -33,7 +33,7 @@ def test_contract_address_validation(web3, args, kwargs, expected): web3.eth.contract(*args, **kwargs) -@pytest.mark.skipif(sys.version_info < (3, 3), reason="needs Mock library from 3.3") +@pytest.mark.skipif(sys.version_info < (3, 5), reason="needs Mock library from 3.5") def test_set_contract_factory(web3): factoryClass = Mock() web3.eth.setContractFactory(factoryClass) diff --git a/tests/core/manager/test_middleware_add_and_clear_api.py b/tests/core/manager/test_middleware_add_and_clear_api.py index 7b1c18a47c..9b581ea42c 100644 --- a/tests/core/manager/test_middleware_add_and_clear_api.py +++ b/tests/core/manager/test_middleware_add_and_clear_api.py @@ -1,5 +1,4 @@ import pytest -import sys from web3.manager import ( RequestManager, @@ -96,7 +95,6 @@ def test_replace_middleware(middleware_factory): assert tuple(manager.middleware_stack) == (mw1, mw3) -@pytest.mark.skipif(sys.version_info.major < 3, reason="replace requires Py 3") def test_replace_middleware_without_name(middleware_factory): mw1 = middleware_factory() mw2 = middleware_factory() diff --git a/tests/core/middleware/test_stalecheck.py b/tests/core/middleware/test_stalecheck.py index 55af4d8b56..cfa1304cb0 100644 --- a/tests/core/middleware/test_stalecheck.py +++ b/tests/core/middleware/test_stalecheck.py @@ -9,11 +9,11 @@ ) from web3.utils.datastructures import AttributeDict -if sys.version_info >= (3, 3): +if sys.version_info >= (3, 5): from unittest.mock import Mock, patch -pytestmark = pytest.mark.skipif(sys.version_info < (3, 3), reason="needs Mock library from 3.3") +pytestmark = pytest.mark.skipif(sys.version_info < (3, 5), reason="needs Mock library from 3.5") @pytest.fixture diff --git a/tests/core/utilities/test_encoding.py b/tests/core/utilities/test_encoding.py index b7de776ffb..cc57ac1e80 100644 --- a/tests/core/utilities/test_encoding.py +++ b/tests/core/utilities/test_encoding.py @@ -1,7 +1,6 @@ # encoding: utf-8 import pytest -import sys from unittest.mock import Mock from eth_utils import ( @@ -26,11 +25,6 @@ hexstr_strategy, ) -only_python3 = pytest.mark.skipif( - sys.version_info.major < 3, - reason="these test values only valid for py3" -) - @pytest.mark.parametrize( "value,expected", @@ -77,8 +71,8 @@ def test_bytes_that_start_with_0x(): "0x00360d2b7D240Ec0643B6D819ba81A09e40E5bCd", "0x00360d2b7D240Ec0643B6D819ba81A09e40E5bCd" ), - ("bytes2", b"T\x02", "0x5402" if sys.version_info[0] >= 3 else TypeError), - ("bytes3", b"T\x02", "0x5402" if sys.version_info[0] >= 3 else TypeError), + ("bytes2", b"T\x02", "0x5402"), + ("bytes3", b"T\x02", "0x5402"), ("bytes", '0x5402', "0x5402"), ("bytes", '5402', TypeError), ("string", "testing a string!", "0x74657374696e67206120737472696e6721"), @@ -99,7 +93,6 @@ def test_hex_encode_abi_type(abi_type, value, expected): assert actual == expected -@only_python3 @given(st.one_of(st.integers(), st.booleans(), st.binary())) @example(b'') def test_hexstr_if_str_passthrough(val): @@ -113,7 +106,6 @@ def test_hexstr_if_str_curried(): assert converter(255) == '0xff' -@only_python3 @given(hexstr_strategy()) @example('0x') @example('0') @@ -123,7 +115,6 @@ def test_hexstr_if_str_on_valid_hex(val): assert to_type.call_args == ((None, ), {'hexstr': val}) -@only_python3 @given(st.text()) def test_hexstr_if_str_on_invalid_hex(val): try: @@ -136,7 +127,6 @@ def test_hexstr_if_str_on_invalid_hex(val): hexstr_if_str(Mock(), val) -@only_python3 @given(st.one_of(st.integers(), st.booleans(), st.binary())) @example(b'') def test_text_if_str_passthrough(val): @@ -145,7 +135,6 @@ def test_text_if_str_passthrough(val): assert to_type.call_args == ((val, ), {'text': None}) -@only_python3 @given(st.text()) @example('0xa1') # valid hexadecimal is still interpreted as unicode characters def test_text_if_str_on_text(val): diff --git a/tests/core/utilities/test_validation.py b/tests/core/utilities/test_validation.py index ac0ebd5108..02b158bfd5 100644 --- a/tests/core/utilities/test_validation.py +++ b/tests/core/utilities/test_validation.py @@ -1,5 +1,4 @@ import pytest -import sys from web3.exceptions import ( InvalidAddress, @@ -83,7 +82,7 @@ def test_validation(param, validation, expected): ('bytes', True, TypeError), ('bytes', "0x5402", None), ('bytes', "5402", TypeError), - ('bytes', b'T\x02', None if sys.version_info[0] >= 3 else TypeError), + ('bytes', b'T\x02', None), ) ) def test_validate_abi_value(abi_type, value, expected): diff --git a/tests/core/web3-module/test_conversions.py b/tests/core/web3-module/test_conversions.py index d9992d858b..73476d0118 100644 --- a/tests/core/web3-module/test_conversions.py +++ b/tests/core/web3-module/test_conversions.py @@ -1,7 +1,6 @@ # coding=utf-8 import pytest -import sys from web3 import Web3 @@ -25,14 +24,6 @@ def test_to_bytes_primitive(val, expected): assert Web3.toBytes(val) == expected -@pytest.mark.skipif(sys.version_info.major > 2, reason="Python 3 doesn't have long type") -def test_to_bytes_long(): - minlong = sys.maxint + 1 - assert minlong > sys.maxint # are there any python interpreters that overflow? - valbytes = Web3.toBytes(minlong) - assert Web3.toInt(valbytes) == minlong - - @pytest.mark.parametrize( 'val, expected', ( @@ -63,11 +54,7 @@ def test_to_bytes_text(val, expected): def test_to_text_identity(): - if sys.version_info.major < 3: - with pytest.raises(NotImplementedError): - Web3.toText(text='') - else: - assert Web3.toText(text='pass-through') == 'pass-through' + assert Web3.toText(text='pass-through') == 'pass-through' @pytest.mark.parametrize( @@ -82,11 +69,7 @@ def test_to_text_identity(): ) ) def test_to_text(val, expected): - if sys.version_info.major < 3: - with pytest.raises(NotImplementedError): - Web3.toText(val) - else: - assert Web3.toText(val) == expected + assert Web3.toText(val) == expected @pytest.mark.parametrize( @@ -99,11 +82,7 @@ def test_to_text(val, expected): ) ) def test_to_text_hexstr(val, expected): - if sys.version_info.major < 3: - with pytest.raises(NotImplementedError): - Web3.toText(hexstr=val) - else: - assert Web3.toText(hexstr=val) == expected + assert Web3.toText(hexstr=val) == expected @pytest.mark.parametrize( diff --git a/tests/integration/test_ethereum_tester.py b/tests/integration/test_ethereum_tester.py index 962085c20f..6f8892640b 100644 --- a/tests/integration/test_ethereum_tester.py +++ b/tests/integration/test_ethereum_tester.py @@ -1,5 +1,4 @@ import functools -import sys import pytest @@ -173,10 +172,6 @@ def _check_web3_clientVersion(self, client_version): def not_implemented(method, exc_type=NotImplementedError): @functools.wraps(method) def inner(*args, **kwargs): - if sys.version_info.major == 2: - # pytest doesn't do the right thing with the fixture arguments in - # python2 so just don't run it. - return with pytest.raises(exc_type): method(*args, **kwargs) return inner diff --git a/tests/integration/test_ethtestrpc.py b/tests/integration/test_ethtestrpc.py index 467bba6eae..2ae030547d 100644 --- a/tests/integration/test_ethtestrpc.py +++ b/tests/integration/test_ethtestrpc.py @@ -1,5 +1,4 @@ import functools -import sys import pytest @@ -133,10 +132,6 @@ def _check_web3_clientVersion(self, client_version): def not_implemented(method, exc_type=AttributeError): @functools.wraps(method) def inner(*args, **kwargs): - if sys.version_info.major == 2: - # pytest doesn't do the right thing with the fixture arguments in - # python2 so just don't run it. - return with pytest.raises(exc_type): method(*args, **kwargs) return inner diff --git a/tests/integration/test_goethereum.py b/tests/integration/test_goethereum.py index c908a1fe49..6a7a2aaf79 100644 --- a/tests/integration/test_goethereum.py +++ b/tests/integration/test_goethereum.py @@ -2,7 +2,6 @@ import signal import socket import subprocess -import sys import shutil import time import tempfile @@ -26,10 +25,6 @@ ) -if sys.version_info.major == 2: - FileNotFoundError = OSError - - KEYFILE_PW = 'web3py-test' diff --git a/web3/__init__.py b/web3/__init__.py index 58d12a7b32..164fe13613 100644 --- a/web3/__init__.py +++ b/web3/__init__.py @@ -1,8 +1,8 @@ import pkg_resources import sys -if sys.version_info.major < 3: - raise EnvironmentError("Python 3 is required") +if sys.version_info < (3, 5): + raise EnvironmentError("Python 3.5 or above is required") from web3.account import Account # noqa: E402 from web3.main import Web3 # noqa: E402 diff --git a/web3/account.py b/web3/account.py index fb5d245fa5..a14552bfe1 100644 --- a/web3/account.py +++ b/web3/account.py @@ -4,7 +4,6 @@ ) import json import os -import sys from cytoolz import ( compose, @@ -40,7 +39,6 @@ text_if_str, to_bytes, to_int, - to_hex, ) from web3.utils.signing import ( LocalAccount, @@ -64,14 +62,11 @@ class Account(object): def create(self, extra_entropy=''): extra_key_bytes = text_if_str(to_bytes, extra_entropy) key_bytes = keccak(os.urandom(32) + extra_key_bytes) - if sys.version_info.major < 3: - key_bytes = to_hex(key_bytes) return self.privateKeyToAccount(key_bytes) @staticmethod def decrypt(keyfile_json, password): - if isinstance(keyfile_json, str) or ( - sys.version_info.major < 3 and isinstance(keyfile_json, unicode)): # noqa: 821 + if isinstance(keyfile_json, str): keyfile = json.loads(keyfile_json) elif is_dict(keyfile_json): keyfile = keyfile_json @@ -131,8 +126,6 @@ def recoverTransaction(self, serialized_transaction): txn_bytes = HexBytes(serialized_transaction) txn = Transaction.from_bytes(txn_bytes) msg_hash = hash_of_signed_transaction(txn) - if sys.version_info.major < 3: - msg_hash = to_hex(msg_hash) return self.recover(msg_hash, vrs=vrs_from(txn)) def setKeyBackend(self, backend): diff --git a/web3/utils/encoding.py b/web3/utils/encoding.py index 3b7bbe3aa0..ec5b2d89f1 100644 --- a/web3/utils/encoding.py +++ b/web3/utils/encoding.py @@ -1,7 +1,6 @@ # String encodings and numeric representations import json import re -import sys import rlp from rlp.sedes import big_endian_int @@ -73,7 +72,7 @@ def hex_encode_abi_type(abi_type, value, force_size=None): elif is_address_type(abi_type): return pad_hex(value, data_size) elif is_bytes_type(abi_type): - if sys.version_info.major >= 3 and is_bytes(value): + if is_bytes(value): return encode_hex(value) else: return value @@ -235,12 +234,7 @@ def text_if_str(to_type, text_or_primitive): In Python 2, only a unicode object will be interpreted as unicode text In Python 3, only a str object will be interpreted as interpreted as unicode text ''' - if sys.version_info.major < 3: - if isinstance(text_or_primitive, unicode): # noqa: F821 - (primitive, text) = (None, text_or_primitive) - else: - (primitive, text) = (text_or_primitive, None) - elif isinstance(text_or_primitive, str): + if isinstance(text_or_primitive, str): (primitive, text) = (None, text_or_primitive) else: (primitive, text) = (text_or_primitive, None) @@ -258,9 +252,7 @@ def hexstr_if_str(to_type, hexstr_or_primitive): In Python 2, a bytes, unicode or str object will be interpreted as hexstr In Python 3, only a str object will be interpreted as hexstr ''' - if isinstance(hexstr_or_primitive, str) or ( - sys.version_info.major < 3 and isinstance(hexstr_or_primitive, unicode) # noqa: F821 - ): + if isinstance(hexstr_or_primitive, str): (primitive, hexstr) = (None, hexstr_or_primitive) if remove_0x_prefix(hexstr) and not is_hex(hexstr): raise ValueError( diff --git a/web3/utils/formatters.py b/web3/utils/formatters.py index 1a9c844ce6..7ce83b0b92 100644 --- a/web3/utils/formatters.py +++ b/web3/utils/formatters.py @@ -2,7 +2,6 @@ Iterable, Mapping, ) -import sys from cytoolz.functoolz import ( curry, @@ -24,11 +23,7 @@ def hex_to_integer(value): return int(value, 16) -if sys.version_info.major == 2: - def integer_to_hex(value): - return hex(value).rstrip('L') -else: - integer_to_hex = hex +integer_to_hex = hex @curry diff --git a/web3/utils/signing.py b/web3/utils/signing.py index cd6bd5d126..8290a2373e 100644 --- a/web3/utils/signing.py +++ b/web3/utils/signing.py @@ -1,10 +1,7 @@ -import sys - from web3.utils.encoding import ( to_bytes, to_int, - to_hex, ) from web3.utils.transactions import ( @@ -40,7 +37,7 @@ def sign_transaction_dict(eth_key, transaction_dict): # serialize transaction with rlp encoded_transaction = encode_transaction(unsigned_transaction, vrs=(v, r, s)) - return (v, r, s, encoded_transaction) + return (v, r, s, transaction_hash, encoded_transaction) # watch here for updates to signature format: https://github.com/ethereum/EIPs/issues/191 @@ -144,8 +141,6 @@ def __init__(self, key, account): self.address = key.public_key.to_checksum_address() key_raw = key.to_bytes() - if sys.version_info.major < 3: - key_raw = to_hex(key_raw) self.privateKey = key_raw self._key_obj = key @@ -167,10 +162,3 @@ def signTransaction(self, transaction_dict): def __bytes__(self): return self.privateKey - - # Python 2 support - def __str__(self): - if sys.version_info.major < 3: - return self.privateKey - else: - return super().__str__() diff --git a/web3/utils/six/__init__.py b/web3/utils/six/__init__.py index 7513d4bcaf..6855eb18eb 100644 --- a/web3/utils/six/__init__.py +++ b/web3/utils/six/__init__.py @@ -1,15 +1,5 @@ -import sys - - -if sys.version_info.major == 2: - from .six_py2 import ( - urlparse, - urlunparse, - Generator, - ) -else: - from .six_py3 import ( # noqa: #401 - urlparse, - urlunparse, - Generator, - ) +from .six import ( # noqa: #401 + urlparse, + urlunparse, + Generator, +) diff --git a/web3/utils/six/six.py b/web3/utils/six/six.py new file mode 100644 index 0000000000..11777ce63d --- /dev/null +++ b/web3/utils/six/six.py @@ -0,0 +1,8 @@ +import collections + +from urllib.parse import ( # noqa: F401 + urlparse, + urlunparse, +) + +Generator = collections.Generator diff --git a/web3/utils/validation.py b/web3/utils/validation.py index 907056143f..7ff88334d9 100644 --- a/web3/utils/validation.py +++ b/web3/utils/validation.py @@ -1,5 +1,4 @@ import itertools -import sys from eth_utils import ( is_0x_prefixed, @@ -87,7 +86,7 @@ def validate_abi_value(abi_type, value): validate_address(value) return elif is_bytes_type(abi_type): - if sys.version_info.major >= 3 and is_bytes(value): + if is_bytes(value): return elif is_string(value): if is_0x_prefixed(value): From 24065ee4582ed8e91499a976f225b9ddcbd29714 Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 21 Nov 2017 21:52:45 -0400 Subject: [PATCH 2/5] Unify six versions to only python3 version --- web3/utils/six/six_py2.py | 5 ----- web3/utils/six/six_py3.py | 12 ------------ 2 files changed, 17 deletions(-) delete mode 100644 web3/utils/six/six_py2.py delete mode 100644 web3/utils/six/six_py3.py diff --git a/web3/utils/six/six_py2.py b/web3/utils/six/six_py2.py deleted file mode 100644 index d1c07950bc..0000000000 --- a/web3/utils/six/six_py2.py +++ /dev/null @@ -1,5 +0,0 @@ -from urlparse import ( # noqa: F401 - urlparse, - urlunparse, -) -Generator = type(_ for _ in tuple()) diff --git a/web3/utils/six/six_py3.py b/web3/utils/six/six_py3.py deleted file mode 100644 index 3363495792..0000000000 --- a/web3/utils/six/six_py3.py +++ /dev/null @@ -1,12 +0,0 @@ -import collections - -from urllib.parse import ( # noqa: F401 - urlparse, - urlunparse, -) - -try: - Generator = collections.Generator -except AttributeError: - # py34 - Generator = type(_ for _ in tuple()) From 5365d8f264e2b93315abdbfb5db49dcb46f6bfab Mon Sep 17 00:00:00 2001 From: Miguel Almonte Date: Tue, 21 Nov 2017 21:54:09 -0400 Subject: [PATCH 3/5] Remove unused imports and extra blank lines --- tests/core/eth-module/test_accounts.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/core/eth-module/test_accounts.py b/tests/core/eth-module/test_accounts.py index 72c37bde9c..282d191c65 100644 --- a/tests/core/eth-module/test_accounts.py +++ b/tests/core/eth-module/test_accounts.py @@ -1,11 +1,9 @@ # coding=utf-8 import pytest -import sys from eth_utils import ( is_checksum_address, - is_hex, ) from web3 import ( @@ -58,7 +56,6 @@ def PRIVATE_BYTES_ALT(PRIVATE_BYTES): return b'rainbows' * 4 - @pytest.fixture def web3js_key(): return '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318' From e0eaf009afacafc7f7de39e78d419dc88515b0ee Mon Sep 17 00:00:00 2001 From: Miguel Almonte Date: Wed, 22 Nov 2017 00:09:55 -0400 Subject: [PATCH 4/5] Remove transaction_hash from the returned tuple in sign_transaction_dict function --- web3/utils/signing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web3/utils/signing.py b/web3/utils/signing.py index 8290a2373e..274ec1c177 100644 --- a/web3/utils/signing.py +++ b/web3/utils/signing.py @@ -37,7 +37,7 @@ def sign_transaction_dict(eth_key, transaction_dict): # serialize transaction with rlp encoded_transaction = encode_transaction(unsigned_transaction, vrs=(v, r, s)) - return (v, r, s, transaction_hash, encoded_transaction) + return (v, r, s, encoded_transaction) # watch here for updates to signature format: https://github.com/ethereum/EIPs/issues/191 From 8b6bf464307d2c3d32b3f90e53e35f3c1920311c Mon Sep 17 00:00:00 2001 From: Miguel Almonte Date: Wed, 22 Nov 2017 00:19:07 -0400 Subject: [PATCH 5/5] Remove remaing sys.version_info from all tests --- tests/core/contracts/test_concise_contract.py | 10 +--------- tests/core/eth-module/test_eth_contract.py | 6 +----- tests/core/middleware/test_stalecheck.py | 7 +------ 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/tests/core/contracts/test_concise_contract.py b/tests/core/contracts/test_concise_contract.py index de3d9136b6..74cbf5dbaf 100644 --- a/tests/core/contracts/test_concise_contract.py +++ b/tests/core/contracts/test_concise_contract.py @@ -1,6 +1,3 @@ - -import sys - import pytest from eth_utils import ( @@ -13,8 +10,7 @@ ConciseMethod, ) -if sys.version_info >= (3, 5): - from unittest.mock import Mock +from unittest.mock import Mock @pytest.fixture() @@ -35,7 +31,6 @@ def zero_address_contract(web3, WithConstructorAddressArgumentsContract, EMPTY_A return ConciseContract(_address_contract) -@pytest.mark.skipif(sys.version_info < (3, 5), reason="needs Mock library from 3.3") def test_concisecontract_call_default(): contract = Mock() sweet_method = ConciseMethod(contract, 'grail') @@ -44,7 +39,6 @@ def test_concisecontract_call_default(): contract.call().grail.assert_called_once_with(1, 2) -@pytest.mark.skipif(sys.version_info < (3, 5), reason="needs Mock library from 3.3") def test_concisecontract_custom_transact(): contract = Mock() sweet_method = ConciseMethod(contract, 'grail') @@ -53,7 +47,6 @@ def test_concisecontract_custom_transact(): contract.transact().grail.assert_called_once_with(1, 2) -@pytest.mark.skipif(sys.version_info < (3, 5), reason="needs Mock library from 3.3") def test_concisecontract_two_keywords_fail(): contract = Mock() sweet_method = ConciseMethod(contract, 'grail') @@ -61,7 +54,6 @@ def test_concisecontract_two_keywords_fail(): sweet_method(1, 2, transact={'holy': 3}, call={'count_to': 4}) -@pytest.mark.skipif(sys.version_info < (3, 5), reason="needs Mock library from 3.3") def test_concisecontract_unknown_keyword_fails(): contract = Mock() sweet_method = ConciseMethod(contract, 'grail') diff --git a/tests/core/eth-module/test_eth_contract.py b/tests/core/eth-module/test_eth_contract.py index ba21a89db5..a934d5f6bc 100644 --- a/tests/core/eth-module/test_eth_contract.py +++ b/tests/core/eth-module/test_eth_contract.py @@ -1,9 +1,6 @@ -import sys - import pytest -if sys.version_info >= (3, 5): - from unittest.mock import Mock +from unittest.mock import Mock ABI = [{}] @@ -33,7 +30,6 @@ def test_contract_address_validation(web3, args, kwargs, expected): web3.eth.contract(*args, **kwargs) -@pytest.mark.skipif(sys.version_info < (3, 5), reason="needs Mock library from 3.5") def test_set_contract_factory(web3): factoryClass = Mock() web3.eth.setContractFactory(factoryClass) diff --git a/tests/core/middleware/test_stalecheck.py b/tests/core/middleware/test_stalecheck.py index cfa1304cb0..249d3ecf84 100644 --- a/tests/core/middleware/test_stalecheck.py +++ b/tests/core/middleware/test_stalecheck.py @@ -1,6 +1,5 @@ import pytest -import sys from web3.middleware import make_stalecheck_middleware from web3.middleware.stalecheck import ( @@ -9,11 +8,7 @@ ) from web3.utils.datastructures import AttributeDict -if sys.version_info >= (3, 5): - from unittest.mock import Mock, patch - - -pytestmark = pytest.mark.skipif(sys.version_info < (3, 5), reason="needs Mock library from 3.5") +from unittest.mock import Mock, patch @pytest.fixture