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 <[email protected]>
---
 .travis.yml                                                 |  1 +
 ryu/lib/ofctl_v1_3.py                                       |  4 ++--
 ryu/lib/packet/ospf.py                                      |  2 +-
 .../ofctl_json/of13/4-48-ofp_meter_config_reply.packet.json |  4 ++--
 .../of13/4-52-ofp_meter_features_reply.packet.json          |  4 ++--
 ryu/tests/unit/lib/test_ofctl.py                            |  9 ++++++---
 ryu/tests/unit/lib/test_rpc.py                              | 13 ++++++++++++-
 tools/test-requires                                         |  3 ++-
 tox.ini                                                     |  2 +-
 9 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 263224d..f55c0ed 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,6 +6,7 @@ env:
   - TOX_ENV=py26
   - TOX_ENV=py27
   - TOX_ENV=py34
+  - TOX_ENV=pypy
   - TOX_ENV=pep8
 
 install:
diff --git a/ryu/lib/ofctl_v1_3.py b/ryu/lib/ofctl_v1_3.py
index 2de9e37..3f8ee8f 100644
--- a/ryu/lib/ofctl_v1_3.py
+++ b/ryu/lib/ofctl_v1_3.py
@@ -787,7 +787,7 @@ def get_meter_features(dp, waiters):
                 if (1 << k) & feature.band_types:
                     band_types.append(v)
             capabilities = []
-            for k, v in capa_convert.items():
+            for k, v in sorted(capa_convert.items()):
                 if k & feature.capabilities:
                     capabilities.append(v)
             f = {'max_meter': feature.max_meter,
@@ -829,7 +829,7 @@ def get_meter_config(dp, waiters):
                     b['experimenter'] = band.experimenter
                 bands.append(b)
             c_flags = []
-            for k, v in flags.items():
+            for k, v in sorted(flags.items()):
                 if k & config.flags:
                     c_flags.append(v)
             c = {'flags': c_flags,
diff --git a/ryu/lib/packet/ospf.py b/ryu/lib/packet/ospf.py
index 98c5d71..464f089 100644
--- a/ryu/lib/packet/ospf.py
+++ b/ryu/lib/packet/ospf.py
@@ -682,7 +682,7 @@ class OSPFMessage(packet_base.PacketBase, _TypeDisp):
         rest = buf[length:]
         subcls = cls._lookup_type(type_)
         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
 
     @classmethod
diff --git 
a/ryu/tests/unit/lib/ofctl_json/of13/4-48-ofp_meter_config_reply.packet.json 
b/ryu/tests/unit/lib/ofctl_json/of13/4-48-ofp_meter_config_reply.packet.json
index 799bde4..d5efcd9 100644
--- a/ryu/tests/unit/lib/ofctl_json/of13/4-48-ofp_meter_config_reply.packet.json
+++ b/ryu/tests/unit/lib/ofctl_json/of13/4-48-ofp_meter_config_reply.packet.json
@@ -9,9 +9,9 @@
                 }
             ],
             "flags": [
-                "STATS",
                 "PKTPS",
-                "BURST"
+                "BURST",
+                "STATS"
             ],
             "meter_id": 100
         }
diff --git 
a/ryu/tests/unit/lib/ofctl_json/of13/4-52-ofp_meter_features_reply.packet.json 
b/ryu/tests/unit/lib/ofctl_json/of13/4-52-ofp_meter_features_reply.packet.json
index 025e6cc..24dac7d 100644
--- 
a/ryu/tests/unit/lib/ofctl_json/of13/4-52-ofp_meter_features_reply.packet.json
+++ 
b/ryu/tests/unit/lib/ofctl_json/of13/4-52-ofp_meter_features_reply.packet.json
@@ -6,10 +6,10 @@
                 "DSCP_REMARK"
             ],
             "capabilities": [
-                "STATS",
                 "KBPS",
                 "PKTPS",
-                "BURST"
+                "BURST",
+                "STATS"
             ],
             "max_bands": 255,
             "max_color": 0,
diff --git a/ryu/tests/unit/lib/test_ofctl.py b/ryu/tests/unit/lib/test_ofctl.py
index a8ca01f..8030dc6 100644
--- a/ryu/tests/unit/lib/test_ofctl.py
+++ b/ryu/tests/unit/lib/test_ofctl.py
@@ -73,7 +73,8 @@ class Test_ofctl(unittest.TestCase):
         # expected message <--> sent message
         request.serialize()
         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:
             # For debugging
             json.dump(dp.request_msg.to_jsondict(),
@@ -95,9 +96,11 @@ class Test_ofctl(unittest.TestCase):
                 return d2
             return d
 
+        expected = _remove(expected, ['len', 'length'])
+        output = _remove(output, ['len', 'length'])
         try:
-            eq_(_remove(expected, ['len', 'length']),
-                _remove(output, ['len', 'length']))
+            eq_(json.dumps(expected, sort_keys=True),
+                json.dumps(output, sort_keys=True))
         except AssertionError as e:
             # For debugging
             json.dump(output, open('/tmp/' + name + '_reply.json', 'w'),
diff --git a/ryu/tests/unit/lib/test_rpc.py b/ryu/tests/unit/lib/test_rpc.py
index 149912a..cedab55 100644
--- a/ryu/tests/unit/lib/test_rpc.py
+++ b/ryu/tests/unit/lib/test_rpc.py
@@ -119,7 +119,13 @@ class Test_rpc(unittest.TestCase):
         assert isinstance(obj, int)
         result = c.call(b'resp', [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):
         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")
     def test_4_call_large_binary(self):
         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)
         obj = struct.pack("10000000x")
diff --git a/tools/test-requires b/tools/test-requires
index 04ed5a2..3150b92 100644
--- a/tools/test-requires
+++ b/tools/test-requires
@@ -4,5 +4,6 @@ nose
 pep8
 pylint==0.25.0
 formencode
-lxml  # OF-Config
+lxml; platform_python_implementation != 'PyPy'  # OF-Config
+lxml==3.4.0; platform_python_implementation == 'PyPy'
 paramiko  # NETCONF, BGP speaker
diff --git a/tox.ini b/tox.ini
index 60e5d70..d13f444 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = py26,py27,py34,pep8
+envlist = py26,py27,py34,pypy,pep8
 
 [testenv]
 deps = -U
-- 
1.9.1


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to