Skip to content

Commit d858959

Browse files
committed
started refactoring test suite to add Python 3 support
1 parent 50c5035 commit d858959

1 file changed

Lines changed: 35 additions & 25 deletions

File tree

‎v3/tests/golden_test.py‎

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,6 @@
99
from subprocess import *
1010

1111

12-
PROGRAM = ['python', '../generate_json_trace.py']
13-
14-
INPUT_FILE_EXTENSION = '.txt' # input test files are .txt, NOT .py
15-
16-
17-
ALL_TESTS = []
18-
19-
for (pwd, subdirs, files) in os.walk('.', followlinks=True): # need to follow example-code symlink
20-
for f in files:
21-
(base, ext) = os.path.splitext(f)
22-
if ext == INPUT_FILE_EXTENSION:
23-
fullpath = os.path.join(pwd, f)
24-
ALL_TESTS.append(fullpath)
25-
26-
2712
def filter_output(s):
2813
return s
2914

@@ -41,7 +26,7 @@ def execute(input_filename):
4126
# print stderr, '}'
4227

4328
# capture stdout into outfile, filtering out machine-specific addresses
44-
outfile = base + '.out'
29+
outfile = base + OUTPUT_FILE_EXTENSION
4530
outf = open(outfile, 'w')
4631

4732
for line in stdout.splitlines():
@@ -53,7 +38,7 @@ def execute(input_filename):
5338

5439
def clobber_golden_file(golden_file):
5540
(base, ext) = os.path.splitext(golden_file)
56-
outfile = base + '.out'
41+
outfile = base + OUTPUT_FILE_EXTENSION
5742
assert os.path.isfile(outfile)
5843
print ' Clobber %s => %s' % (outfile, golden_file)
5944
shutil.copy(outfile, golden_file)
@@ -62,7 +47,7 @@ def clobber_golden_file(golden_file):
6247
# returns True if there is a diff, False otherwise
6348
def golden_differs_from_out(golden_file):
6449
(base, ext) = os.path.splitext(golden_file)
65-
outfile = base + '.out'
50+
outfile = base + OUTPUT_FILE_EXTENSION
6651
assert os.path.isfile(outfile)
6752
assert os.path.isfile(golden_file)
6853

@@ -78,9 +63,9 @@ def golden_differs_from_out(golden_file):
7863
def diff_test_output(test_name):
7964
(base, ext) = os.path.splitext(test_name)
8065

81-
golden_file = base + '.golden'
66+
golden_file = base + GOLDEN_FILE_EXTENSION
8267
assert os.path.isfile(golden_file)
83-
outfile = base + '.out'
68+
outfile = base + OUTPUT_FILE_EXTENSION
8469
assert os.path.isfile(outfile)
8570

8671
golden_s = open(golden_file).readlines()
@@ -105,14 +90,14 @@ def run_test(input_filename, clobber_golden=False):
10590
assert ext == INPUT_FILE_EXTENSION
10691

10792
# to eliminate possibility of using stale output:
108-
outfile = base + '.out'
93+
outfile = base + OUTPUT_FILE_EXTENSION
10994
if os.path.isfile(outfile):
11095
os.remove(outfile)
11196

11297
input_fullpath = input_filename
11398
execute(input_fullpath)
11499

115-
golden_file = base + '.golden'
100+
golden_file = base + GOLDEN_FILE_EXTENSION
116101
if os.path.isfile(golden_file):
117102
if golden_differs_from_out(golden_file):
118103
print " FAILED!!!"
@@ -142,10 +127,35 @@ def diff_all_test_outputs():
142127
parser.add_option("--test", dest="test_name",
143128
help="Run one test")
144129
parser.add_option("--difftest", dest="diff_test_name",
145-
help="Diff against .golden for one test")
130+
help="Diff against golden file for one test")
146131
parser.add_option("--diffall", action="store_true", dest="diff_all",
147-
help="Diff against .golden for all tests")
132+
help="Diff against golden file for all tests")
133+
parser.add_option("--py3", action="store_true", dest="py3",
134+
help="Run Python 3 tests (rather than Python 2)")
148135
(options, args) = parser.parse_args()
136+
137+
138+
INPUT_FILE_EXTENSION = '.txt' # input test files are .txt, NOT .py
139+
140+
if options.py3:
141+
PROGRAM = ['python3', '../generate_json_trace.py']
142+
OUTPUT_FILE_EXTENSION = '.out_py3'
143+
GOLDEN_FILE_EXTENSION = '.golden_py3'
144+
else:
145+
PROGRAM = ['python2', '../generate_json_trace.py']
146+
OUTPUT_FILE_EXTENSION = '.out'
147+
GOLDEN_FILE_EXTENSION = '.golden'
148+
149+
ALL_TESTS = []
150+
151+
for (pwd, subdirs, files) in os.walk('.', followlinks=True): # need to follow example-code symlink
152+
for f in files:
153+
(base, ext) = os.path.splitext(f)
154+
if ext == INPUT_FILE_EXTENSION:
155+
fullpath = os.path.join(pwd, f)
156+
ALL_TESTS.append(fullpath)
157+
158+
149159
if options.run_all:
150160
if options.clobber:
151161
print 'Running all tests and clobbering results ...'
@@ -164,7 +174,7 @@ def diff_all_test_outputs():
164174
elif options.only_clobber:
165175
for t in ALL_TESTS:
166176
(base, ext) = os.path.splitext(t)
167-
golden_file = base + '.golden'
177+
golden_file = base + GOLDEN_FILE_EXTENSION
168178
clobber_golden_file(golden_file)
169179
else:
170180
parser.print_help()

0 commit comments

Comments
 (0)