diff options
author | IWAMOTO Toshihiro <iwamoto@valinux.co.jp> | 2015-06-24 18:47:05 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-06-25 12:23:31 +0900 |
commit | a23734444c38e4881779a45a246296d99f5f4e48 (patch) | |
tree | 2718767931c1cee4ffd4b0b4822261fcbff73642 | |
parent | 536a42d8c1c0be48e78d5f29b6fd55a38012d953 (diff) |
python3: Fix dynamically added test methods
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 <iwamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/tests/test_lib.py | 7 | ||||
-rw-r--r-- | ryu/tests/unit/ofproto/test_parser.py | 10 | ||||
-rw-r--r-- | ryu/tests/unit/ofproto/test_parser_compat.py | 6 | ||||
-rw-r--r-- | ryu/tests/unit/ofproto/test_parser_ofpmatch.py | 8 | ||||
-rw-r--r-- | 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 1d664478..c1c0f82e 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 8ff2f5a6..fe683864 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 4e7236b0..9a879f05 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 80590779..5f86b15b 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 cd28b698..10ad83e2 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) |