Skip to content

Commit fa736d1

Browse files
authored
Fix syntax errors and undefined names in Python code (#1515)
1 parent 8436e88 commit fa736d1

File tree

7 files changed

+50
-39
lines changed

7 files changed

+50
-39
lines changed

test-tools/IoT-APP-Store-Demo/wasm_django/devices/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,6 @@ def removeapps(req):
268268
return render(req, 'appstore.html', {'alist': json.dumps(avaliable_list),'flist': json.dumps(user_file_list)})
269269

270270
# Test
271-
if __name__ == "__main__":
272-
print(device_list[0]['IP'])
273-
print(device['IP'])
271+
# if __name__ == "__main__":
272+
# print(device_list[0]['IP'])
273+
# print(device['IP'])

test-tools/component-test/framework/engine.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
#
23
# Copyright (C) 2019 Intel Corporation. All rights reserved.
34
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -28,7 +29,7 @@ def read_cases_from_file(file_path):
2829
content = f.readlines()
2930

3031
content = [x.strip() for x in content]
31-
print content
32+
print(content)
3233
if len(content) == 0:
3334
return False, None
3435

test-tools/component-test/framework/framework.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
#
23
# Copyright (C) 2019 Intel Corporation. All rights reserved.
34
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -66,7 +67,7 @@ def __init__(self, path):
6667

6768
api_set_root_path(path)
6869

69-
print "root_path is " + self.root_path
70+
print("root_path is " + self.root_path)
7071

7172
def gen_execution_stats(self):
7273
return '\nTest Execution Summary: ' \
@@ -103,7 +104,7 @@ def run_case(self, suite_instance, case):
103104
module_name = 'suites.' + suite + ".cases." + case + ".case"
104105
try:
105106
module = my_import(module_name)
106-
except Exception, e:
107+
except Exception as e:
107108
report_fail("load case fail: " + str(e))
108109
api_log_error("load case fail: " + str(e))
109110
self.load_fails = self.load_fails +1
@@ -112,7 +113,7 @@ def run_case(self, suite_instance, case):
112113

113114
try:
114115
case = module.CTestCase(suite_instance)
115-
except Exception, e:
116+
except Exception as e:
116117
report_fail("initialize case fail: " + str(e))
117118
api_log_error("initialize case fail: " + str(e))
118119
self.load_fails = self.load_fails +1
@@ -122,7 +123,7 @@ def run_case(self, suite_instance, case):
122123
try:
123124
case_description = case.on_get_case_description()
124125
result, message = case.on_setup_case()
125-
except Exception, e:
126+
except Exception as e:
126127
result = False
127128
message = str(e);
128129
if not result:
@@ -134,7 +135,7 @@ def run_case(self, suite_instance, case):
134135
# call the case execution callaback
135136
try:
136137
result, message = case.on_run_case()
137-
except Exception, e:
138+
except Exception as e:
138139
result = False
139140
message = str(e);
140141
if not result:
@@ -148,7 +149,7 @@ def run_case(self, suite_instance, case):
148149
# call the case cleanup callback
149150
try:
150151
clean_result, message = case.on_cleanup_case()
151-
except Exception, e:
152+
except Exception as e:
152153
clean_result = False
153154
message = str(e)
154155

@@ -166,15 +167,15 @@ def run_suite(self, suite, cases):
166167
module_name = 'suites.' + suite + ".suite_setup"
167168
try:
168169
module = my_import(module_name)
169-
except Exception, e:
170+
except Exception as e:
170171
report_fail("load suite [" + suite +"] fail: " + str(e))
171172
self.load_fails = self.load_fails +1
172173
return False
173174

174175
try:
175176
suite_instance = module.CTestSuite(suite, \
176177
self.root_path + '/suites/' + suite, running_folder)
177-
except Exception, e:
178+
except Exception as e:
178179
report_fail("initialize suite fail: " + str(e))
179180
self.load_fails = self.load_fails +1
180181
return False
@@ -187,7 +188,7 @@ def run_suite(self, suite, cases):
187188

188189
try:
189190
result, message = suite_instance.on_suite_setup()
190-
except Exception, e:
191+
except Exception as e:
191192
result = False
192193
message = str(e);
193194
if not result:
@@ -213,7 +214,7 @@ def run_suite(self, suite, cases):
213214
self.running_suite = ''
214215
try:
215216
result, message = suite_instance.on_suite_cleanup()
216-
except Exception, e:
217+
except Exception as e:
217218
result = False
218219
message = str(e);
219220
if not result:
@@ -224,7 +225,7 @@ def run_suite(self, suite, cases):
224225

225226
def start_run(self):
226227
if self.target_suites is None:
227-
print "\n\nstart run: no target suites, exit.."
228+
print("\n\nstart run: no target suites, exit..")
228229
return
229230

230231
cur_time = time.localtime()
@@ -268,7 +269,7 @@ def start_run(self):
268269
self.report.write(summary);
269270
self.report.flush()
270271
self.report.close()
271-
print summary
272+
print(summary)
272273

273274

274275
def report_fail(message, case_description=''):

test-tools/component-test/framework/test_api.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
#
23
# Copyright (C) 2019 Intel Corporation. All rights reserved.
34
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -12,7 +13,7 @@
1213

1314
def api_init_log(log_path):
1415
global logger
15-
print "api_init_log: " + log_path
16+
print("api_init_log: " + log_path)
1617
logger = logging.getLogger(__name__)
1718

1819
logger.setLevel(level = logging.INFO)
@@ -32,23 +33,23 @@ def api_init_log(log_path):
3233
def api_log(message):
3334
global logger
3435
if logger is None:
35-
print message
36+
print(message)
3637
else:
3738
logger.info (message)
3839
return
3940

4041
def api_log_error(message):
4142
global logger
4243
if logger is None:
43-
print message
44+
print(message)
4445
else:
4546
logger.error (message)
4647
return
4748

4849
def api_logv(message):
4950
global logger
5051
if logger is None:
51-
print message
52+
print(message)
5253
else:
5354
logger.info(message)
5455
return

test-tools/component-test/framework/test_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
#
23
# Copyright (C) 2019 Intel Corporation. All rights reserved.
34
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -52,19 +53,19 @@ def t_process_exists(proc, kill = 0):
5253
if kill == 0:
5354
return True
5455
else:
55-
print "kill [" + proc + "], pid=" + str(pid)
56+
print("kill [" + proc + "], pid=" + str(pid))
5657
os.kill((pid), 9)
5758
ret = True
5859
return ret
5960

6061
def t_copy_files(source_dir, pattern, dest_dir):
6162
files = os.listdir(source_dir)
6263
for file in files:
63-
if file is '/' or file is '.' or file is '..':
64+
if file in ('/', '.', '..'):
6465
continue
6566

66-
if pattern == '*' or pattern is '' or files.endswith(pattern):
67-
shutil.copy(source_dir+"/"+ file,dest_dir)
67+
if pattern in ('*', '') or files.endswith(pattern):
68+
shutil.copy(source_dir+"/"+ file, dest_dir)
6869

6970

7071

test-tools/component-test/start.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
It is the entrance of the iagent test framework.
1111
1212
"""
13+
from __future__ import print_function
1314

1415
import argparse
1516
import datetime
@@ -84,9 +85,9 @@ def flatten_args_list(l):
8485
help = 'rebuild all test binaries')
8586
args = parser.parse_args()
8687

87-
print "------------------------------------------------------------"
88-
print "parsing arguments ... ..."
89-
print args
88+
print("------------------------------------------------------------")
89+
print("parsing arguments ... ...")
90+
print(args)
9091

9192
'''
9293
logger = logging.getLogger('coapthon.server.coap')
@@ -95,8 +96,8 @@ def flatten_args_list(l):
9596
console.setLevel(logging.DEBUG)
9697
logger.addHandler(console)
9798
'''
98-
print "------------------------------------------------------------"
99-
print "preparing wamr binary and test tools ... ..."
99+
print("------------------------------------------------------------")
100+
print("preparing wamr binary and test tools ... ...")
100101
os.system("cd ../../samples/simple/ && bash build.sh -p host-interp")
101102

102103
Register_signal_handler()
@@ -124,9 +125,9 @@ def flatten_args_list(l):
124125
if binary_path is None:
125126
binary_path = os.path.abspath(dirname + '/../..')
126127

127-
print "checking execution binary path: " + binary_path
128+
print("checking execution binary path: " + binary_path)
128129
if not os.path.exists(binary_path):
129-
print "The execution binary path was not available. quit..."
130+
print("The execution binary path was not available. quit...")
130131
os._exit(0)
131132
api_set_value('binary_path', binary_path)
132133

@@ -138,11 +139,11 @@ def flatten_args_list(l):
138139
framework.target_cases = cases_list
139140
framework.start_run()
140141

141-
print "\n\n------------------------------------------------------------"
142-
print "The run folder is [" + framework.running_folder +"]"
143-
print "that's all. bye"
142+
print("\n\n------------------------------------------------------------")
143+
print("The run folder is [" + framework.running_folder +"]")
144+
print("that's all. bye")
144145

145-
print "kill to quit.."
146+
print("kill to quit..")
146147
t_kill_process_by_name("start.py")
147148

148149
sys.exit(0)

tests/wamr-test-suites/spec-test-script/runtest.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import print_function
44
import os, sys, re
5+
from pickletools import long1
56
import argparse, time
67
import signal, atexit, tempfile, subprocess
78

@@ -17,7 +18,12 @@
1718
import math
1819
import traceback
1920

20-
IS_PY_3 = sys.version_info[0] == 3
21+
try:
22+
long
23+
IS_PY_3 = False
24+
except NameError:
25+
long = int
26+
IS_PY_3 = True
2127

2228
test_aot = False
2329
# "x86_64", "i386", "aarch64", "armv7" or "thumbv7"
@@ -312,7 +318,7 @@ def get_module_exp_from_assert(string):
312318

313319
def string_to_unsigned(number_in_string, lane_type):
314320
if not lane_type in ['i8x16', 'i16x8', 'i32x4', 'i64x2']:
315-
raise Exception("invalid value {} and type {} and lane_type {}".format(numbers, type, lane_type))
321+
raise Exception("invalid value {} and type {} and lane_type {}".format(number_in_string, type, lane_type))
316322

317323
number = int(number_in_string, 16) if '0x' in number_in_string else int(number_in_string)
318324

@@ -896,7 +902,7 @@ def skip_test(form, skip_list):
896902

897903
def compile_wast_to_wasm(form, wast_tempfile, wasm_tempfile, opts):
898904
log("Writing WAST module to '%s'" % wast_tempfile)
899-
file(wast_tempfile, 'w').write(form)
905+
open(wast_tempfile, 'w').write(form)
900906
log("Compiling WASM to '%s'" % wasm_tempfile)
901907

902908
# default arguments
@@ -1122,7 +1128,7 @@ def test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile,
11221128
# workaround: spec test changes error message to "malformed" while iwasm still use "invalid"
11231129
error_msg = m.group(2).replace("malformed", "invalid")
11241130
log("Testing(malformed)")
1125-
f = file(wasm_tempfile, 'w')
1131+
f = open(wasm_tempfile, 'w')
11261132
s = m.group(1)
11271133
while s:
11281134
res = re.match("[^\"]*\"([^\"]*)\"(.*)", s, re.DOTALL)

0 commit comments

Comments
 (0)