VPP-1508: Python3 tests. Explicitly specify string formatting.

.format() doesn't understand what to do with binary values by default.
Specify that we expect coersion to string.

Change-Id: Ic4b697f70852124dc85ab231f76b7934d0d71f4d
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
This commit is contained in:
Paul Vinciguerra
2019-03-06 08:23:58 -08:00
committed by Ole Trøan
parent 4a4cea02ef
commit ea2450fa2d
11 changed files with 29 additions and 27 deletions

View File

@ -1163,7 +1163,7 @@ class VppTestResult(unittest.TestResult):
if isinstance(test, unittest.suite._ErrorHolder):
test_name = str(test)
else:
test_name = "'{}' ({})".format(
test_name = "'{!s}' ({!s})".format(
get_testcase_doc_name(test), test.id())
self.current_test_case_info.core_crash_test = test_name
self.core_crash_test_cases_info.add(

View File

@ -135,7 +135,7 @@ class LispEID(object):
self.prefix_length = 0
self.data_length = 6
else:
raise Exception('Unsupported EID format {}!'.format(eid))
raise Exception('Unsupported EID format {!s}!'.format(eid))
def __str__(self):
if self.eid_type == LispEIDType.IP4:
@ -144,7 +144,7 @@ class LispEID(object):
return socket.inet_pton(socket.AF_INET6, self.eid_address)
elif self.eid_type == LispEIDType.MAC:
return Exception('Unimplemented')
raise Exception('Unknown EID type {}!'.format(self.eid_type))
raise Exception('Unknown EID type {!s}!'.format(self.eid_type))
class VppLispMapping(VppObject):

View File

@ -57,7 +57,7 @@ def get_logger(name):
def get_parallel_logger(stream):
logger = logging.getLogger('parallel_logger_{}'.format(stream))
logger = logging.getLogger('parallel_logger_{!s}'.format(stream))
logger.propagate = False
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(stream)

View File

@ -237,7 +237,8 @@ class MethodHolder(VppTestCase):
mac = ':'.join(re.findall('..', '{:02x}'.format(
src_mac))[:3])+":00:00:00"
else:
mac = ':'.join(re.findall('..', '{:02x}'.format(src_mac)))
mac = ':'.join(re.findall(
'..', '{:02x}'.format(src_mac)))
if ip_type == self.EXACT_IP:
ip4[3] = random.randint(100, 200)

View File

@ -202,7 +202,7 @@ class TestClassifier(VppTestCase):
:param str dst_port: destination port number <0-ffff>
"""
return ('{:0>20}{:0>12}{:0>8}{:0>4}{:0>4}'.format(
return ('{!s:0>20}{!s:0>12}{!s:0>8}{!s:0>4}{!s:0>4}'.format(
proto, src_ip, dst_ip, src_port, dst_port)).rstrip('0')
@staticmethod
@ -221,7 +221,7 @@ class TestClassifier(VppTestCase):
if dst_ip:
dst_ip = binascii.hexlify(socket.inet_aton(dst_ip))
return ('{:0>20}{:0>12}{:0>8}{:0>4}{:0>4}'.format(
return ('{!s:0>20}{!s:0>12}{!s:0>8}{!s:0>4}{!s:0>4}'.format(
hex(proto)[2:], src_ip, dst_ip, hex(src_port)[2:],
hex(dst_port)[2:])).rstrip('0')
@ -234,8 +234,8 @@ class TestClassifier(VppTestCase):
:param str ether_type: ethernet type <0-ffff>
"""
return ('{:0>12}{:0>12}{:0>4}'.format(dst_mac, src_mac,
ether_type)).rstrip('0')
return ('{!s:0>12}{!s:0>12}{!s:0>4}'.format(
dst_mac, src_mac, ether_type)).rstrip('0')
@staticmethod
def build_mac_match(dst_mac='', src_mac='', ether_type=''):
@ -250,8 +250,8 @@ class TestClassifier(VppTestCase):
if src_mac:
src_mac = src_mac.replace(':', '')
return ('{:0>12}{:0>12}{:0>4}'.format(dst_mac, src_mac,
ether_type)).rstrip('0')
return ('{!s:0>12}{!s:0>12}{!s:0>4}'.format(
dst_mac, src_mac, ether_type)).rstrip('0')
def create_classify_table(self, key, mask, data_offset=0):
"""Create Classify Table

View File

@ -168,7 +168,7 @@ class TestClassifier(VppTestCase):
:param str dst_port: destination port number <0-ffff>
"""
return ('{:0>14}{:0>34}{:0>32}{:0>4}{:0>4}'.format(
return ('{!s:0>14}{!s:0>34}{!s:0>32}{!s:0>4}{!s:0>4}'.format(
nh, src_ip, dst_ip, src_port, dst_port)).rstrip('0')
@staticmethod
@ -190,7 +190,7 @@ class TestClassifier(VppTestCase):
dst_ip = binascii.hexlify(socket.inet_pton(
socket.AF_INET6, dst_ip))
return ('{:0>14}{:0>34}{:0>32}{:0>4}{:0>4}'.format(
return ('{!s:0>14}{!s:0>34}{!s:0>32}{!s:0>4}{!s:0>4}'.format(
hex(nh)[2:], src_ip, dst_ip, hex(src_port)[2:],
hex(dst_port)[2:])).rstrip('0')
@ -203,8 +203,8 @@ class TestClassifier(VppTestCase):
:param str ether_type: ethernet type <0-ffff>
"""
return ('{:0>12}{:0>12}{:0>4}'.format(dst_mac, src_mac,
ether_type)).rstrip('0')
return ('{!s:0>12}{!s:0>12}{!s:0>4}'.format(
dst_mac, src_mac, ether_type)).rstrip('0')
@staticmethod
def build_mac_match(dst_mac='', src_mac='', ether_type=''):
@ -219,8 +219,8 @@ class TestClassifier(VppTestCase):
if src_mac:
src_mac = src_mac.replace(':', '')
return ('{:0>12}{:0>12}{:0>4}'.format(dst_mac, src_mac,
ether_type)).rstrip('0')
return ('{!s:0>12}{!s:0>12}{!s:0>4}'.format(
dst_mac, src_mac, ether_type)).rstrip('0')
def create_classify_table(self, key, mask, data_offset=0):
"""Create Classify Table

View File

@ -174,8 +174,8 @@ class TestClassifyAcl(VppTestCase):
:param str ether_type: ethernet type <0-ffff>
"""
return ('{:0>12}{:0>12}{:0>4}'.format(dst_mac, src_mac,
ether_type)).rstrip('0')
return ('{!s:0>12}{!s:0>12}{!s:0>4}'.format(
dst_mac, src_mac, ether_type)).rstrip('0')
@staticmethod
def build_mac_match(dst_mac='', src_mac='', ether_type=''):
@ -190,8 +190,8 @@ class TestClassifyAcl(VppTestCase):
if src_mac:
src_mac = src_mac.replace(':', '')
return ('{:0>12}{:0>12}{:0>4}'.format(dst_mac, src_mac,
ether_type)).rstrip('0')
return ('{!s:0>12}{!s:0>12}{!s:0>4}'.format(
dst_mac, src_mac, ether_type)).rstrip('0')
def create_classify_table(self, key, mask, data_offset=0, is_add=1):
"""Create Classify Table

View File

@ -395,7 +395,7 @@ class TestIPv4FibCrud(VppTestCase):
for ip in ips:
self.assertTrue(_ip_in_route_dump(ip, fib_dump),
'IP {} is not in fib dump.'.format(ip))
'IP {!s} is not in fib dump.'.format(ip))
def verify_not_in_route_dump(self, fib_dump, ips):
@ -406,7 +406,7 @@ class TestIPv4FibCrud(VppTestCase):
for ip in ips:
self.assertFalse(_ip_in_route_dump(ip, fib_dump),
'IP {} is in fib dump.'.format(ip))
'IP {!s} is in fib dump.'.format(ip))
@classmethod
def setUpClass(cls):

View File

@ -154,7 +154,7 @@ class TestLisp(VppTestCase):
self.deid_ip4_net = self.faf.net
self.deid_ip4 = self.faf.get_ip4()
self.seid_ip4 = '{}/{}'.format(self.pg0.local_ip4, 32)
self.seid_ip4 = '{!s}/{!s}'.format(self.pg0.local_ip4, 32)
self.rloc_ip4 = self.pg1.remote_ip4n
test_cases = [

View File

@ -77,7 +77,8 @@ class P2PEthernetAPI(VppTestCase):
for i in range(1, clients+1):
try:
macs.append(':'.join(re.findall('..', '{:02x}'.format(mac+i))))
macs.append(':'.join(re.findall('..', '{:02x}'.format(
mac+i))))
self.vapi.p2p_ethernet_add(self.pg2.sw_if_index,
mac_pton(macs[i-1]),
i)

View File

@ -1224,7 +1224,7 @@ class TestSRv6(VppTestCase):
# add classify table
# mask on dst ip address prefix a7::/8
mask = '{:0<16}'.format('ff')
mask = '{!s:0<16}'.format('ff')
r = self.vapi.classify_add_del_table(
1,
binascii.unhexlify(mask),
@ -1239,7 +1239,7 @@ class TestSRv6(VppTestCase):
'sr-pl-rewrite-insert')
inacl_next_node_index = r.node_index
match = '{:0<16}'.format('a7')
match = '{!s:0<16}'.format('a7')
r = self.vapi.classify_add_del_session(
1,
table_index,