Python 3: fix test_utils
In Python 3, the error message returned when unpacking too many values is a bit different from the one we see in Python 2: Python 2: ValueError: too many values to unpack Python 3: ValueError: too many values to unpack (expected <number of values>) Blueprint: neutron-python3 Change-Id: Ib607a526c007567a370c521fd7e2e4f8b504b934
This commit is contained in:
parent
737d853c19
commit
5afd046d53
|
@ -263,7 +263,7 @@ def str2dict(string):
|
||||||
|
|
||||||
|
|
||||||
def dict2tuple(d):
|
def dict2tuple(d):
|
||||||
items = d.items()
|
items = list(d.items())
|
||||||
items.sort()
|
items.sort()
|
||||||
return tuple(items)
|
return tuple(items)
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ class TestVxlanTunnelRangeVerifyValid(TestParseTunnelRangesMixin,
|
||||||
class UtilTestParseVlanRanges(base.BaseTestCase):
|
class UtilTestParseVlanRanges(base.BaseTestCase):
|
||||||
_err_prefix = "Invalid network VLAN range: '"
|
_err_prefix = "Invalid network VLAN range: '"
|
||||||
_err_too_few = "' - 'need more than 2 values to unpack'"
|
_err_too_few = "' - 'need more than 2 values to unpack'"
|
||||||
_err_too_many = "' - 'too many values to unpack'"
|
_err_too_many_prefix = "' - 'too many values to unpack"
|
||||||
_err_not_int = "' - 'invalid literal for int() with base 10: '%s''"
|
_err_not_int = "' - 'invalid literal for int() with base 10: '%s''"
|
||||||
_err_bad_vlan = "' - '%s is not a valid VLAN tag'"
|
_err_bad_vlan = "' - '%s is not a valid VLAN tag'"
|
||||||
_err_range = "' - 'End of VLAN range is less than start of VLAN range'"
|
_err_range = "' - 'End of VLAN range is less than start of VLAN range'"
|
||||||
|
@ -145,8 +145,8 @@ class UtilTestParseVlanRanges(base.BaseTestCase):
|
||||||
def _range_too_few_err(self, nv_range):
|
def _range_too_few_err(self, nv_range):
|
||||||
return self._err_prefix + nv_range + self._err_too_few
|
return self._err_prefix + nv_range + self._err_too_few
|
||||||
|
|
||||||
def _range_too_many_err(self, nv_range):
|
def _range_too_many_err_prefix(self, nv_range):
|
||||||
return self._err_prefix + nv_range + self._err_too_many
|
return self._err_prefix + nv_range + self._err_too_many_prefix
|
||||||
|
|
||||||
def _vlan_not_int_err(self, nv_range, vlan):
|
def _vlan_not_int_err(self, nv_range, vlan):
|
||||||
return self._err_prefix + nv_range + (self._err_not_int % vlan)
|
return self._err_prefix + nv_range + (self._err_not_int % vlan)
|
||||||
|
@ -267,10 +267,13 @@ class TestParseOneVlanRange(UtilTestParseVlanRanges):
|
||||||
|
|
||||||
def test_parse_one_net_range_too_many(self):
|
def test_parse_one_net_range_too_many(self):
|
||||||
config_str = "net1:100:150:200"
|
config_str = "net1:100:150:200"
|
||||||
expected_msg = self._range_too_many_err(config_str)
|
expected_msg_prefix = self._range_too_many_err_prefix(config_str)
|
||||||
err = self.assertRaises(n_exc.NetworkVlanRangeError,
|
err = self.assertRaises(n_exc.NetworkVlanRangeError,
|
||||||
self.parse_one, config_str)
|
self.parse_one, config_str)
|
||||||
self.assertEqual(str(err), expected_msg)
|
# The error message is not same in Python 2 and Python 3. In Python 3,
|
||||||
|
# it depends on the amount of values used when unpacking, so it cannot
|
||||||
|
# be predicted as a fixed string.
|
||||||
|
self.assertTrue(str(err).startswith(expected_msg_prefix))
|
||||||
|
|
||||||
def test_parse_one_net_vlan1_not_int(self):
|
def test_parse_one_net_vlan1_not_int(self):
|
||||||
config_str = "net1:foo:199"
|
config_str = "net1:foo:199"
|
||||||
|
@ -463,8 +466,8 @@ class TestCachingDecorator(base.BaseTestCase):
|
||||||
|
|
||||||
class TestDict2Tuples(base.BaseTestCase):
|
class TestDict2Tuples(base.BaseTestCase):
|
||||||
def test_dict(self):
|
def test_dict(self):
|
||||||
input_dict = {'foo': 'bar', 42: 'baz', 'aaa': 'zzz'}
|
input_dict = {'foo': 'bar', '42': 'baz', 'aaa': 'zzz'}
|
||||||
expected = ((42, 'baz'), ('aaa', 'zzz'), ('foo', 'bar'))
|
expected = (('42', 'baz'), ('aaa', 'zzz'), ('foo', 'bar'))
|
||||||
output_tuple = utils.dict2tuple(input_dict)
|
output_tuple = utils.dict2tuple(input_dict)
|
||||||
self.assertEqual(expected, output_tuple)
|
self.assertEqual(expected, output_tuple)
|
||||||
|
|
||||||
|
|
1
tox.ini
1
tox.ini
|
@ -236,6 +236,7 @@ commands = python -m testtools.run \
|
||||||
neutron.tests.unit.extensions.test_providernet \
|
neutron.tests.unit.extensions.test_providernet \
|
||||||
neutron.tests.unit.callbacks.test_manager \
|
neutron.tests.unit.callbacks.test_manager \
|
||||||
neutron.tests.unit.hacking.test_checks \
|
neutron.tests.unit.hacking.test_checks \
|
||||||
|
neutron.tests.unit.common.test_utils \
|
||||||
neutron.tests.unit.common.test_config \
|
neutron.tests.unit.common.test_config \
|
||||||
neutron.tests.unit.common.test_rpc \
|
neutron.tests.unit.common.test_rpc \
|
||||||
neutron.tests.unit.common.test_ipv6_utils \
|
neutron.tests.unit.common.test_ipv6_utils \
|
||||||
|
|
Loading…
Reference in New Issue