Skip to content

Commit

Permalink
Remove Python 2 compatibility from test code
Browse files Browse the repository at this point in the history
  • Loading branch information
pekkaklarck committed Aug 19, 2022
1 parent 969013b commit a9403e8
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions atest/testresources/listeners/VerifyAttributes.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import os

try:
basestring
long
except NameError:
basestring = str
long = int


OUTFILE = open(os.path.join(os.getenv('TEMPDIR'), 'listener_attrs.txt'), 'w')
START = 'doc starttime '
END = START + 'endtime elapsedtime status '
Expand All @@ -20,24 +12,24 @@
'ELSE IF': 'condition',
'EXCEPT': 'patterns pattern_type variable',
'RETURN': 'values'}
EXPECTED_TYPES = {'tags': [basestring],
'args': [basestring],
'assign': [basestring],
'metadata': {basestring: basestring},
'tests': [basestring],
'suites': [basestring],
EXPECTED_TYPES = {'tags': [str],
'args': [str],
'assign': [str],
'metadata': {str: str},
'tests': [str],
'suites': [str],
'totaltests': int,
'elapsedtime': (int, long),
'elapsedtime': int,
'lineno': (int, type(None)),
'source': (basestring, type(None)),
'source': (str, type(None)),
'variables': (dict, list),
'flavor': basestring,
'flavor': str,
'values': (list, dict),
'condition': basestring,
'limit': (basestring, type(None)),
'patterns': (basestring, list),
'pattern_type': (basestring, type(None)),
'variable': (basestring, type(None))}
'condition': str,
'limit': (str, type(None)),
'patterns': (str, list),
'pattern_type': (str, type(None)),
'variable': (str, type(None))}


def verify_attrs(method_name, attrs, names):
Expand All @@ -49,7 +41,7 @@ def verify_attrs(method_name, attrs, names):
return
for name in names:
value = attrs[name]
exp_type = EXPECTED_TYPES.get(name, basestring)
exp_type = EXPECTED_TYPES.get(name, str)
if isinstance(exp_type, list):
verify_attr(name, value, list)
for index, item in enumerate(value):
Expand All @@ -73,9 +65,9 @@ def verify_attr(name, value, exp_type):


def format_value(value):
if isinstance(value, basestring):
if isinstance(value, str):
return value
if isinstance(value, (int, long)):
if isinstance(value, int):
return str(value)
if isinstance(value, list):
return '[%s]' % ', '.join(format_value(item) for item in value)
Expand Down

0 comments on commit a9403e8

Please sign in to comment.