Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all sys.version_info checks, presuming Python 3.5+ (Second try) #456

Merged
merged 5 commits into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions tests/core/contracts/test_concise_contract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

import sys

import pytest

from eth_utils import (
Expand All @@ -13,8 +10,7 @@
ConciseMethod,
)

if sys.version_info >= (3, 3):
from unittest.mock import Mock
from unittest.mock import Mock


@pytest.fixture()
Expand All @@ -35,7 +31,6 @@ 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")
def test_concisecontract_call_default():
contract = Mock()
sweet_method = ConciseMethod(contract, 'grail')
Expand All @@ -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, 3), reason="needs Mock library from 3.3")
def test_concisecontract_custom_transact():
contract = Mock()
sweet_method = ConciseMethod(contract, 'grail')
Expand All @@ -53,15 +47,13 @@ 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")
def test_concisecontract_two_keywords_fail():
contract = Mock()
sweet_method = ConciseMethod(contract, 'grail')
with pytest.raises(TypeError):
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")
def test_concisecontract_unknown_keyword_fails():
contract = Mock()
sweet_method = ConciseMethod(contract, 'grail')
Expand Down
26 changes: 4 additions & 22 deletions tests/core/eth-module/test_accounts.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# coding=utf-8

import pytest
import sys

from eth_utils import (
is_checksum_address,
is_hex,
)

from web3 import (
Expand Down Expand Up @@ -48,23 +46,14 @@
]


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
Expand Down Expand Up @@ -130,10 +119,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):
Expand Down Expand Up @@ -170,9 +156,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<N,s{i\x81\x86r\x83{\xba\x9f\xe2\x1d\xaa\xdd\xb3\xd6\x01\xda\x00\xb7)\xa1' # noqa: E501
msg_hash = to_hex_if_py2(msg_hash)
signature = to_hex_if_py2(signature_bytes)
from_account = acct.recover(msg_hash, signature=signature)
from_account = acct.recover(msg_hash, signature=signature_bytes)
assert from_account == '0xFeC2079e80465cc8C687fFF9EE6386ca447aFec4'


Expand All @@ -183,7 +167,6 @@ def test_eth_account_recover_vrs(acct):
15655399131600894366408541311673616702363115109327707006109616887384920764603,
)
msg_hash = b'\xbb\r\x8a\xba\x9f\xf7\xa1<N,s{i\x81\x86r\x83{\xba\x9f\xe2\x1d\xaa\xdd\xb3\xd6\x01\xda\x00\xb7)\xa1' # noqa: E501
msg_hash = to_hex_if_py2(msg_hash)
from_account = acct.recover(msg_hash, vrs=(v, r, s))
assert from_account == '0xFeC2079e80465cc8C687fFF9EE6386ca447aFec4'

Expand All @@ -198,7 +181,6 @@ def test_eth_account_recover_vrs_standard_v(acct):
15655399131600894366408541311673616702363115109327707006109616887384920764603,
)
msg_hash = b'\xbb\r\x8a\xba\x9f\xf7\xa1<N,s{i\x81\x86r\x83{\xba\x9f\xe2\x1d\xaa\xdd\xb3\xd6\x01\xda\x00\xb7)\xa1' # noqa: E501
msg_hash = to_hex_if_py2(msg_hash)
from_account = acct.recover(msg_hash, vrs=(v, r, s))
assert from_account == '0xFeC2079e80465cc8C687fFF9EE6386ca447aFec4'

Expand Down
6 changes: 1 addition & 5 deletions tests/core/eth-module/test_eth_contract.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import sys

import pytest

if sys.version_info >= (3, 3):
from unittest.mock import Mock
from unittest.mock import Mock


ABI = [{}]
Expand Down Expand Up @@ -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, 3), reason="needs Mock library from 3.3")
def test_set_contract_factory(web3):
factoryClass = Mock()
web3.eth.setContractFactory(factoryClass)
Expand Down
2 changes: 0 additions & 2 deletions tests/core/manager/test_middleware_add_and_clear_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
import sys

from web3.manager import (
RequestManager,
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 1 addition & 6 deletions tests/core/middleware/test_stalecheck.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import pytest
import sys

from web3.middleware import make_stalecheck_middleware
from web3.middleware.stalecheck import (
Expand All @@ -9,11 +8,7 @@
)
from web3.utils.datastructures import AttributeDict

if sys.version_info >= (3, 3):
from unittest.mock import Mock, patch


pytestmark = pytest.mark.skipif(sys.version_info < (3, 3), reason="needs Mock library from 3.3")
from unittest.mock import Mock, patch


@pytest.fixture
Expand Down
15 changes: 2 additions & 13 deletions tests/core/utilities/test_encoding.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# encoding: utf-8

import pytest
import sys
from unittest.mock import Mock

from eth_utils import (
Expand All @@ -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",
Expand Down Expand Up @@ -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"),
Expand All @@ -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):
Expand All @@ -113,7 +106,6 @@ def test_hexstr_if_str_curried():
assert converter(255) == '0xff'


@only_python3
@given(hexstr_strategy())
@example('0x')
@example('0')
Expand All @@ -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:
Expand All @@ -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):
Expand All @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions tests/core/utilities/test_validation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
import sys

from web3.exceptions import (
InvalidAddress,
Expand Down Expand Up @@ -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):
Expand Down
27 changes: 3 additions & 24 deletions tests/core/web3-module/test_conversions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# coding=utf-8

import pytest
import sys

from web3 import Web3

Expand All @@ -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',
(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
5 changes: 0 additions & 5 deletions tests/integration/test_ethereum_tester.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import functools
import sys

import pytest

Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions tests/integration/test_ethtestrpc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import functools
import sys

import pytest

Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions tests/integration/test_goethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import signal
import socket
import subprocess
import sys
import shutil
import time
import tempfile
Expand All @@ -26,10 +25,6 @@
)


if sys.version_info.major == 2:
FileNotFoundError = OSError


KEYFILE_PW = 'web3py-test'


Expand Down
4 changes: 2 additions & 2 deletions web3/__init__.py
Original file line number Diff line number Diff line change
@@ -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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for catching this.


from web3.account import Account # noqa: E402
from web3.main import Web3 # noqa: E402
Expand Down
Loading