tox: Adapt to PyPy interpreter

Note: Though tests may not be enough, as far as running unit test,
this patch makes compatible with PyPy interpreter.

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
IWASE Yusuke 2016-02-10 13:47:04 +09:00 committed by FUJITA Tomonori
parent 4dc709d90d
commit 2ae4f884ab
9 changed files with 29 additions and 13 deletions

View File

@ -6,6 +6,7 @@ env:
- TOX_ENV=py26 - TOX_ENV=py26
- TOX_ENV=py27 - TOX_ENV=py27
- TOX_ENV=py34 - TOX_ENV=py34
- TOX_ENV=pypy
- TOX_ENV=pep8 - TOX_ENV=pep8
install: install:

View File

@ -787,7 +787,7 @@ def get_meter_features(dp, waiters):
if (1 << k) & feature.band_types: if (1 << k) & feature.band_types:
band_types.append(v) band_types.append(v)
capabilities = [] capabilities = []
for k, v in capa_convert.items(): for k, v in sorted(capa_convert.items()):
if k & feature.capabilities: if k & feature.capabilities:
capabilities.append(v) capabilities.append(v)
f = {'max_meter': feature.max_meter, f = {'max_meter': feature.max_meter,
@ -829,7 +829,7 @@ def get_meter_config(dp, waiters):
b['experimenter'] = band.experimenter b['experimenter'] = band.experimenter
bands.append(b) bands.append(b)
c_flags = [] c_flags = []
for k, v in flags.items(): for k, v in sorted(flags.items()):
if k & config.flags: if k & config.flags:
c_flags.append(v) c_flags.append(v)
c = {'flags': c_flags, c = {'flags': c_flags,

View File

@ -682,7 +682,7 @@ class OSPFMessage(packet_base.PacketBase, _TypeDisp):
rest = buf[length:] rest = buf[length:]
subcls = cls._lookup_type(type_) subcls = cls._lookup_type(type_)
kwargs = subcls.parser(binmsg) kwargs = subcls.parser(binmsg)
return subcls(length, router_id, area_id, au_type, authentication, return subcls(length, router_id, area_id, au_type, int(authentication),
checksum, version, **kwargs), None, rest checksum, version, **kwargs), None, rest
@classmethod @classmethod

View File

@ -9,9 +9,9 @@
} }
], ],
"flags": [ "flags": [
"STATS",
"PKTPS", "PKTPS",
"BURST" "BURST",
"STATS"
], ],
"meter_id": 100 "meter_id": 100
} }

View File

@ -6,10 +6,10 @@
"DSCP_REMARK" "DSCP_REMARK"
], ],
"capabilities": [ "capabilities": [
"STATS",
"KBPS", "KBPS",
"PKTPS", "PKTPS",
"BURST" "BURST",
"STATS"
], ],
"max_bands": 255, "max_bands": 255,
"max_color": 0, "max_color": 0,

View File

@ -73,7 +73,8 @@ class Test_ofctl(unittest.TestCase):
# expected message <--> sent message # expected message <--> sent message
request.serialize() request.serialize()
try: try:
eq_(request.to_jsondict(), dp.request_msg.to_jsondict()) eq_(json.dumps(request.to_jsondict(), sort_keys=True),
json.dumps(dp.request_msg.to_jsondict(), sort_keys=True))
except AssertionError as e: except AssertionError as e:
# For debugging # For debugging
json.dump(dp.request_msg.to_jsondict(), json.dump(dp.request_msg.to_jsondict(),
@ -95,9 +96,11 @@ class Test_ofctl(unittest.TestCase):
return d2 return d2
return d return d
expected = _remove(expected, ['len', 'length'])
output = _remove(output, ['len', 'length'])
try: try:
eq_(_remove(expected, ['len', 'length']), eq_(json.dumps(expected, sort_keys=True),
_remove(output, ['len', 'length'])) json.dumps(output, sort_keys=True))
except AssertionError as e: except AssertionError as e:
# For debugging # For debugging
json.dump(output, open('/tmp/' + name + '_reply.json', 'w'), json.dump(output, open('/tmp/' + name + '_reply.json', 'w'),

View File

@ -119,7 +119,13 @@ class Test_rpc(unittest.TestCase):
assert isinstance(obj, int) assert isinstance(obj, int)
result = c.call(b'resp', [obj]) result = c.call(b'resp', [obj])
assert result == obj assert result == obj
assert isinstance(result, type(obj)) import sys
# note: on PyPy, result will be a long type value.
sv = getattr(sys, 'subversion', None)
if sv is not None and sv[0] == 'PyPy':
assert isinstance(result, long)
else:
assert isinstance(result, type(obj))
def test_0_call_int3(self): def test_0_call_int3(self):
c = rpc.Client(self._client_sock) c = rpc.Client(self._client_sock)
@ -237,6 +243,11 @@ class Test_rpc(unittest.TestCase):
@unittest.skip("doesn't work with eventlet 0.18 and later") @unittest.skip("doesn't work with eventlet 0.18 and later")
def test_4_call_large_binary(self): def test_4_call_large_binary(self):
import struct import struct
import sys
# note: on PyPy, this test case may hang up.
sv = getattr(sys, 'subversion', None)
if sv is not None and sv[0] == 'PyPy':
return
c = rpc.Client(self._client_sock) c = rpc.Client(self._client_sock)
obj = struct.pack("10000000x") obj = struct.pack("10000000x")

View File

@ -4,5 +4,6 @@ nose
pep8 pep8
pylint==0.25.0 pylint==0.25.0
formencode formencode
lxml # OF-Config lxml; platform_python_implementation != 'PyPy' # OF-Config
lxml==3.4.0; platform_python_implementation == 'PyPy'
paramiko # NETCONF, BGP speaker paramiko # NETCONF, BGP speaker

View File

@ -1,5 +1,5 @@
[tox] [tox]
envlist = py26,py27,py34,pep8 envlist = py26,py27,py34,pypy,pep8
[testenv] [testenv]
deps = -U deps = -U