Skip to content

Commit 2c8ddf0

Browse files
committed
use unittest instead of unittest2
1 parent 9afc4c5 commit 2c8ddf0

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: python
22
python:
3-
- "2.5"
43
- "2.6"
54
- "2.7"
65
- "3.3"

pystatsd/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def signal_handler(signal, frame):
305305
data, addr = self._sock.recvfrom(self.buf)
306306
try:
307307
self.process(data)
308-
except Exception, error:
308+
except Exception as error:
309309
log.error("Bad data from %s: %s",addr,error)
310310

311311

pystatsd/statsd.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,13 @@ def send(self, data, sample_rate=1):
9797
if sample_rate < 1:
9898
if random.random() > sample_rate:
9999
return
100-
sampled_data = dict((stat, "%s|@%s" % (value, sample_rate)) for stat, value in data.items())
100+
sampled_data = dict((stat, "%s|@%s" % (value, sample_rate))
101+
for stat, value in data.items())
101102
else:
102103
sampled_data = data
103104

104105
try:
105-
[self.udp_sock.sendto(bytes(bytearray("%s:%s" % (stat, value), "utf-8")), self.addr) for stat, value in sampled_data.items()]
106+
[self.udp_sock.sendto(bytes("%s:%s" % (stat, value), "utf-8"), self.addr) for stat, value in sampled_data.items()]
106107
except:
107108
self.log.exception("unexpected error")
108109

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
unittest2
21
nose
3-
mock
2+
mock

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ def read(fname):
1414
url='https://github.com/sivy/py-statsd',
1515
license = "BSD",
1616
packages=['pystatsd'],
17-
install_requires=['argparse >= 1.2'],
1817
long_description=read('README.md'),
19-
requires=['argparse'],
2018
classifiers=[
2119
"License :: OSI Approved :: BSD License",
2220
],

tests/client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import time
2-
import unittest2
2+
import unittest
33
import mock
44
import socket
55

66
from pystatsd.statsd import Client
77

88

9-
class ClientBasicsTestCase(unittest2.TestCase):
9+
class ClientBasicsTestCase(unittest.TestCase):
1010
"""
1111
Tests the basic operations of the client
1212
"""
@@ -40,7 +40,7 @@ def test_basic_client_incr(self):
4040

4141
# thanks tos9 in #python for 'splaining the return_value bit.
4242
self.mock_socket.return_value.sendto.assert_called_with(
43-
stat_str, self.addr)
43+
bytes(stat_str, 'utf-8'), self.addr)
4444

4545
def test_basic_client_decr(self):
4646
stat = 'pystatsd.unittests.test_basic_client_decr'
@@ -50,7 +50,7 @@ def test_basic_client_decr(self):
5050

5151
# thanks tos9 in #python for 'splaining the return_value bit.
5252
self.mock_socket.return_value.sendto.assert_called_with(
53-
stat_str, self.addr)
53+
bytes(stat_str, 'utf-8'), self.addr)
5454

5555
def test_basic_client_update_stats(self):
5656
stat = 'pystatsd.unittests.test_basic_client_update_stats'
@@ -60,7 +60,7 @@ def test_basic_client_update_stats(self):
6060

6161
# thanks tos9 in #python for 'splaining the return_value bit.
6262
self.mock_socket.return_value.sendto.assert_called_with(
63-
stat_str, self.addr)
63+
bytes(stat_str, 'utf-8'), self.addr)
6464

6565
def test_basic_client_update_stats_multi(self):
6666
stats = [
@@ -76,7 +76,7 @@ def test_basic_client_update_stats_multi(self):
7676
stat_str = stat + value
7777
# thanks tos9 in #python for 'splaining the return_value bit.
7878
self.mock_socket.return_value.sendto.assert_call_any(
79-
stat_str, self.addr)
79+
bytes(stat_str, 'utf-8'), self.addr)
8080

8181
def test_basic_client_timing(self):
8282
stat = 'pystatsd.unittests.test_basic_client_timing.time'
@@ -86,7 +86,7 @@ def test_basic_client_timing(self):
8686

8787
# thanks tos9 in #python for 'splaining the return_value bit.
8888
self.mock_socket.return_value.sendto.assert_called_with(
89-
stat_str, self.addr)
89+
bytes(stat_str, 'utf-8'), self.addr)
9090

9191
def test_basic_client_timing_since(self):
9292
ts = (1971, 6, 29, 4, 13, 0, 0, 0, -1)
@@ -104,7 +104,7 @@ def test_basic_client_timing_since(self):
104104

105105
# thanks tos9 in #python for 'splaining the return_value bit.
106106
self.mock_socket.return_value.sendto.assert_called_with(
107-
stat_str, self.addr)
107+
bytes(stat_str, 'utf-8'), self.addr)
108108

109109
mock_time_patcher.stop()
110110

tests/server.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import unittest2
1+
import unittest
22
import mock
33

44
# from pystatsd.statsd import Client
55
from pystatsd.server import Server
66

77

8-
class ServerBasicsTestCase(unittest2.TestCase):
8+
class ServerBasicsTestCase(unittest.TestCase):
99
"""
1010
Tests the basic operations of the client
1111
"""
@@ -19,4 +19,7 @@ def setUp(self):
1919
def test_server_create(self):
2020
server = Server()
2121

22-
self.assertIsNotNone(server)
22+
if getattr(self, "assertIsNotNone", False):
23+
self.assertIsNotNone(server)
24+
else:
25+
assert server is not None

0 commit comments

Comments
 (0)