Usage of types.MethodType has changed and means a bound method in python3.
This is probably the reason why self must be passed explicitly in python3.

Signed-off-by: IWAMOTO Toshihiro <[email protected]>
---
 ryu/tests/test_lib.py                          |  7 ++++++-
 ryu/tests/unit/ofproto/test_parser.py          | 10 +++++++---
 ryu/tests/unit/ofproto/test_parser_compat.py   |  6 +++++-
 ryu/tests/unit/ofproto/test_parser_ofpmatch.py |  8 ++++++--
 ryu/tests/unit/ofproto/test_parser_ofpstats.py |  8 ++++++--
 5 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/ryu/tests/test_lib.py b/ryu/tests/test_lib.py
index 1d66447..c1c0f82 100644
--- a/ryu/tests/test_lib.py
+++ b/ryu/tests/test_lib.py
@@ -17,6 +17,7 @@
 import gettext
 import os
 import unittest
+import six
 import sys
 import types
 import logging
@@ -262,4 +263,8 @@ def add_method(cls, method_name, method):
     """Add the method to the class dynamically, keeping unittest/nose happy."""
     method.func_name = method_name
     method.__name__ = method_name
-    setattr(cls, method_name, types.MethodType(method, None, cls))
+    if six.PY3:
+        methodtype = types.MethodType(method, cls)
+    else:
+        methodtype = types.MethodType(method, None, cls)
+    setattr(cls, method_name, methodtype)
diff --git a/ryu/tests/unit/ofproto/test_parser.py 
b/ryu/tests/unit/ofproto/test_parser.py
index 8ff2f5a..fe68386 100644
--- a/ryu/tests/unit/ofproto/test_parser.py
+++ b/ryu/tests/unit/ofproto/test_parser.py
@@ -14,6 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import six
 import sys
 import unittest
 from nose.tools import eq_
@@ -188,7 +189,7 @@ class Test_Parser(unittest.TestCase):
                                      wire_msg)
             json_dict2 = self._msg_to_jsondict(msg)
             # XXXdebug code
-            open(('/tmp/%s.json' % name), 'wb').write(json.dumps(json_dict2))
+            open(('/tmp/%s.json' % name), 'w').write(json.dumps(json_dict2))
             eq_(json_dict, json_dict2)
 
         # json -> OFPxxx -> json
@@ -247,12 +248,15 @@ def _add_tests():
             if not fnmatch.fnmatch(file, '*.packet'):
                 continue
             wire_msg = open(pdir + '/' + file, 'rb').read()
-            json_str = open(jdir + '/' + file + '.json', 'rb').read()
+            json_str = open(jdir + '/' + file + '.json', 'r').read()
             method_name = ('test_' + file).replace('-', '_').replace('.', '_')
 
             def _run(self, name, wire_msg, json_str):
                 print('processing %s ...' % name)
-                self._test_msg(name, wire_msg, json_str)
+                if six.PY3:
+                    self._test_msg(self, name, wire_msg, json_str)
+                else:
+                    self._test_msg(name, wire_msg, json_str)
             print('adding %s ...' % method_name)
             f = functools.partial(_run, name=method_name, wire_msg=wire_msg,
                                   json_str=json_str)
diff --git a/ryu/tests/unit/ofproto/test_parser_compat.py 
b/ryu/tests/unit/ofproto/test_parser_compat.py
index 4e7236b..9a879f0 100644
--- a/ryu/tests/unit/ofproto/test_parser_compat.py
+++ b/ryu/tests/unit/ofproto/test_parser_compat.py
@@ -14,6 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import six
 import sys
 import unittest
 from nose.tools import eq_
@@ -145,7 +146,10 @@ def _add_tests():
 
         def _run(self, name, ofpp):
             print('processing %s ...' % name)
-            self._test(name, ofpp)
+            if six.PY3:
+                self._test(self, name, ofpp)
+            else:
+                self._test(name, ofpp)
         print('adding %s ...' % method_name)
         f = functools.partial(_run, name=method_name,
                               ofpp=ofpp)
diff --git a/ryu/tests/unit/ofproto/test_parser_ofpmatch.py 
b/ryu/tests/unit/ofproto/test_parser_ofpmatch.py
index 8059077..5f86b15 100644
--- a/ryu/tests/unit/ofproto/test_parser_ofpmatch.py
+++ b/ryu/tests/unit/ofproto/test_parser_ofpmatch.py
@@ -21,6 +21,7 @@ except ImportError:
     # Python 2
     pass
 
+import six
 import sys
 import unittest
 from nose.tools import eq_
@@ -55,7 +56,7 @@ class Test_Parser_OFPMatch(unittest.TestCase):
         match = ofpp.OFPMatch(**d)
         b = bytearray()
         match.serialize(b, 0)
-        match2 = match.parser(buffer(b), 0)
+        match2 = match.parser(six.binary_type(b), 0)
         for k, v in d.items():
             ok_(k in match)
             ok_(k in match2)
@@ -235,7 +236,10 @@ def _add_tests():
 
                         def _run(self, name, ofpp, d, domask):
                             print('processing %s ...' % name)
-                            self._test(name, ofpp, d, domask)
+                            if six.PY3:
+                                self._test(self, name, ofpp, d, domask)
+                            else:
+                                self._test(name, ofpp, d, domask)
                         print('adding %s ...' % method_name)
                         f = functools.partial(_run, name=method_name,
                                               ofpp=ofpp, d=d, domask=domask)
diff --git a/ryu/tests/unit/ofproto/test_parser_ofpstats.py 
b/ryu/tests/unit/ofproto/test_parser_ofpstats.py
index cd28b69..10ad83e 100644
--- a/ryu/tests/unit/ofproto/test_parser_ofpstats.py
+++ b/ryu/tests/unit/ofproto/test_parser_ofpstats.py
@@ -20,6 +20,7 @@ except ImportError:
     # Python 2
     pass
 
+import six
 import sys
 import unittest
 from nose.tools import eq_
@@ -47,7 +48,7 @@ class Test_Parser_OFPStats(unittest.TestCase):
         stats = ofpp.OFPStats(**d)
         b = bytearray()
         stats.serialize(b, 0)
-        stats2 = stats.parser(buffer(b), 0)
+        stats2 = stats.parser(six.binary_type(b), 0)
         for k, v in d.iteritems():
             ok_(k in stats)
             ok_(k in stats2)
@@ -193,7 +194,10 @@ def _add_tests():
 
                     def _run(self, name, ofpp, d):
                         print('processing %s ...' % name)
-                        self._test(name, ofpp, d)
+                        if six.PY3:
+                            self._test(self, name, ofpp, d)
+                        else:
+                            self._test(name, ofpp, d)
                     print('adding %s ...' % method_name)
                     f = functools.partial(_run, name=method_name,
                                           ofpp=ofpp, d=d)
-- 
2.1.4


------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors 
network devices and physical & virtual servers, alerts via email & sms 
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to