Skip to content

Commit 2b26391

Browse files
Drop unsupported pythons
Drop support for pythons <3.7 (including python 2). Since this makes it part of the standard library, replace `mock` with `unittest.mock` in tests. This also required replacing `nose` with `pytest` in tests This is because `nose` is not under active development[1], and the version specified fails to run on python3 (and newer versions fail to run on python3.10[2]): $ python -m nose Traceback (most recent call last): File "/usr/lib/python3.10/runpy.py", line 187, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "/usr/lib/python3.10/runpy.py", line 146, in _get_module_details return _get_module_details(pkg_main_name, error) File "/usr/lib/python3.10/runpy.py", line 110, in _get_module_details __import__(pkg_name) File "/home/mjh/src/pystatsd/.venv/lib/python3.10/site-packages/nose/__init__.py", line 1, in <module> from nose.core import collector, main, run, run_exit, runmodule File "/home/mjh/src/pystatsd/.venv/lib/python3.10/site-packages/nose/core.py", line 143 print "%s version %s" % (os.path.basename(sys.argv[0]), __version__) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)? `pytest` is pinned at the lowest version supporting python3.10[3], similarly for coverage[4], `flake8` was also bump to a more recent version. [1] https://nose.readthedocs.io/en/latest/#note-to-users [2] nose-devs/nose#1122 [3] https://docs.pytest.org/en/7.1.x/changelog.html#pytest-6-2-5-2021-08-29 [4] https://coverage.readthedocs.io/en/6.4.1/changes.html#version-6-0-2021-10-03
1 parent f3f304b commit 2b26391

File tree

5 files changed

+28
-34
lines changed

5 files changed

+28
-34
lines changed

docs/contributing.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ You can also run the tests with tox::
3636

3737
$ tox
3838

39-
Tox will run the tests in Pythons 2.5, 2.6, 2.7, 3.2, 3.3, 3.4, and
40-
PyPy, if they're available.
39+
Tox will run the tests in Pythons 3.7, 3.8, 3.9, 3.10 and
40+
PyPy3, if they're available.
4141

4242

4343
Writing Tests

requirements.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
mock==1.0.1
2-
nose==1.2.1
3-
flake8==1.7.0
1+
flake8>=4.0
2+
pytest>=6.2.5

setup.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@
1414
include_package_data=True,
1515
package_data={'': ['README.rst']},
1616
test_suite='nose.collector',
17+
python_requires='>=3.7',
1718
classifiers=[
1819
'Development Status :: 5 - Production/Stable',
1920
'Environment :: Web Environment',
2021
'Intended Audience :: Developers',
2122
'License :: OSI Approved :: MIT License',
2223
'Operating System :: OS Independent',
2324
'Programming Language :: Python',
24-
'Programming Language :: Python :: 2',
25-
'Programming Language :: Python :: 2.7',
2625
'Programming Language :: Python :: 3',
27-
'Programming Language :: Python :: 3.5',
28-
'Programming Language :: Python :: 3.6',
2926
'Programming Language :: Python :: 3.7',
3027
'Programming Language :: Python :: 3.8',
28+
'Programming Language :: Python :: 3.9',
29+
'Programming Language :: Python :: 3.10',
30+
'Programming Language :: Python :: Implementation :: CPython',
31+
'Programming Language :: Python :: Implementation :: PyPy',
3132
'Topic :: Software Development :: Libraries :: Python Modules',
3233
],
3334
)

statsd/tests.py

+16-21
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import socket
66
from datetime import timedelta
77
from unittest import SkipTest
8-
9-
import mock
10-
from nose.tools import eq_
8+
from unittest import mock
119

1210
from statsd import StatsClient
1311
from statsd import TCPStatsClient
@@ -66,22 +64,19 @@ def _unix_socket_client(prefix=None, socket_path=None):
6664

6765
def _timer_check(sock, count, proto, start, end):
6866
send = send_method[proto](sock)
69-
eq_(send.call_count, count)
67+
assert send.call_count == count
7068
value = send.call_args[0][0].decode('ascii')
7169
exp = re.compile(r'^%s:\d+|%s$' % (start, end))
7270
assert exp.match(value)
7371

7472

7573
def _sock_check(sock, count, proto, val=None, addr=None):
7674
send = send_method[proto](sock)
77-
eq_(send.call_count, count)
75+
assert send.call_count == count
7876
if not addr:
7977
addr = ADDR
8078
if val is not None:
81-
eq_(
82-
send.call_args,
83-
make_val[proto](val, addr),
84-
)
79+
assert send.call_args == make_val[proto](val, addr)
8580

8681

8782
class assert_raises(object):
@@ -443,7 +438,7 @@ def _test_prepare(cl, proto):
443438

444439
def _check(o, s, v, r):
445440
with mock.patch.object(random, 'random', lambda: -1):
446-
eq_(o, cl._prepare(s, v, r))
441+
assert o == cl._prepare(s, v, r)
447442

448443
for o, (s, v, r) in tests:
449444
_check(o, s, v, r)
@@ -519,13 +514,13 @@ def bar(a, b):
519514

520515
# make sure it works with more than one decorator, called multiple
521516
# times, and that parameters are handled correctly
522-
eq_([4, 2], foo(4, 2))
517+
assert [4, 2] == foo(4, 2)
523518
_timer_check(cl._sock, 1, proto, 'foo', 'ms')
524519

525-
eq_([2, 4], bar(4, 2))
520+
assert [2, 4] == bar(4, 2)
526521
_timer_check(cl._sock, 2, proto, 'bar', 'ms')
527522

528-
eq_([6, 5], bar(5, 6))
523+
assert [6, 5] == bar(5, 6)
529524
_timer_check(cl._sock, 3, proto, 'bar', 'ms')
530525

531526

@@ -543,7 +538,7 @@ def test_timer_decorator_tcp():
543538

544539
def _test_timer_capture(cl, proto):
545540
with cl.timer('woo') as result:
546-
eq_(result.ms, None)
541+
assert result.ms is None
547542
assert isinstance(result.ms, float)
548543

549544

@@ -587,7 +582,7 @@ def test_timer_decorator_partial_function():
587582
foo = functools.partial(lambda x: x * x, 2)
588583
func = cl.timer('foo')(foo)
589584

590-
eq_(4, func())
585+
assert 4 == func()
591586

592587
_timer_check(cl._sock, 1, 'tcp', 'foo', 'ms|@0.1')
593588

@@ -601,10 +596,10 @@ def foo(a, b):
601596
def bar(a, b=2, c=3):
602597
return [c, b, a]
603598

604-
eq_([2, 4], foo(4, 2))
599+
assert [2, 4] == foo(4, 2)
605600
_timer_check(cl._sock, 1, proto, 'foo', 'ms|@0.1')
606601

607-
eq_([3, 2, 5], bar(5))
602+
assert [3, 2, 5] == bar(5)
608603
_timer_check(cl._sock, 2, proto, 'bar', 'ms|@0.2')
609604

610605

@@ -906,8 +901,8 @@ def test_pipeline_timer_object_tcp():
906901
def _test_pipeline_empty(cl):
907902
with cl.pipeline() as pipe:
908903
pipe.incr('foo')
909-
eq_(1, len(pipe._stats))
910-
eq_(0, len(pipe._stats))
904+
assert 1 == len(pipe._stats)
905+
assert 0 == len(pipe._stats)
911906

912907

913908
def test_pipeline_empty_udp():
@@ -1006,7 +1001,7 @@ def test_pipeline_packet_size():
10061001
# 32 * 16 = 512, so this will need 2 packets.
10071002
pipe.incr('sixteen_char_str')
10081003
pipe.send()
1009-
eq_(2, sc._sock.sendto.call_count)
1004+
assert 2 == sc._sock.sendto.call_count
10101005
assert len(sc._sock.sendto.call_args_list[0][0][0]) <= 512
10111006
assert len(sc._sock.sendto.call_args_list[1][0][0]) <= 512
10121007

@@ -1017,7 +1012,7 @@ def test_tcp_raises_exception_to_user(mock_socket):
10171012
addr = ('127.0.0.1', 1234)
10181013
cl = _tcp_client(addr=addr[0], port=addr[1])
10191014
cl.incr('foo')
1020-
eq_(1, cl._sock.sendall.call_count)
1015+
assert 1 == cl._sock.sendall.call_count
10211016
cl._sock.sendall.side_effect = socket.error
10221017
with assert_raises(socket.error):
10231018
cl.incr('foo')

tox.ini

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ envlist = py27,pypy,py34,py35,py36,py37
33

44
[testenv]
55
deps=
6-
mock==1.0.1
7-
nose==1.2.1
8-
coverage==3.5.2
6+
coverage>=6.0
7+
pytest>=6.2.5
98

109
commands=
11-
nosetests statsd --with-coverage --cover-package=statsd []
10+
pytest statsd/tests.py

0 commit comments

Comments
 (0)