Skip to content

Commit afa7bd1

Browse files
author
rocky
committed
Less verbose output in roundtrip testing
1 parent 634bbb3 commit afa7bd1

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

test/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ check: check-short check-roundtrip
2727
--bytecode-pypy35 --bytecode-pypy36 --bytecode-pypy37 \
2828
--bytecode-pypy38 --bytecode-pypy39 --bytecode-pypy310 $(COMPILE)
2929

30-
check-roundtrip: check-roundtrip-3.0 check-roundtrip-3.1 check-roundtrip-3.3 check-roundtrip-3.4
30+
check-roundtrip:
31+
./test_pyc_roundtrip.py --quiet \
32+
--bytecode-2.7 --bytecode-3.0 --bytecode-3.1 --bytecode-3.3 --bytecode-3.4
33+
34+
check-roundtrip-2.7:
35+
./test_pyc_roundtrip.py --bytecode-3.0
3136

3237
check-roundtrip-3.0:
3338
./test_pyc_roundtrip.py --bytecode-3.0

test/test_pyc_roundtrip.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def file_matches(files, root, basenames, patterns):
190190
failure_count = 0
191191
try:
192192
for infile in files:
193-
failure_count += roundtrip_pyc(infile, unlink_on_success=False)
193+
failure_count += roundtrip_pyc(infile, unlink_on_success=False, verbose=test_opts["verbose"])
194194

195195
except (KeyboardInterrupt, OSError):
196196
print()
@@ -200,7 +200,7 @@ def file_matches(files, root, basenames, patterns):
200200

201201
n = len(files)
202202
print(f"Processed {n} files: {n-failure_count} good, and {failure_count} bad.")
203-
sys.exit(failure_count if failure_count < 255 else 255)
203+
return failure_count
204204

205205

206206
if __name__ == "__main__":
@@ -213,7 +213,7 @@ def file_matches(files, root, basenames, patterns):
213213
opts, args = getopt.getopt(
214214
sys.argv[1:],
215215
"",
216-
["start-with=", "all", "no-rm"] + test_options_keys,
216+
["start-with=", "all", "quiet", "no-rm"] + test_options_keys,
217217
)
218218
if not opts:
219219
help()
@@ -223,11 +223,14 @@ def file_matches(files, root, basenames, patterns):
223223
"rmtree": True,
224224
}
225225

226+
test_opts["verbose"] = True
226227
for opt, val in opts:
227228
if opt == "--start-with":
228229
test_opts["start_with"] = val
229230
elif opt == "--no-rm":
230231
test_opts["rmtree"] = False
232+
elif opt == "--quiet":
233+
test_opts["verbose"] = False
231234
elif opt[2:] in test_options_keys:
232235
test_dirs.append(test_options[opt[2:]])
233236
elif opt == "--all":

xdis/roundtrip_pyc.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def load_meta_and_code_from_filename(path: str):
179179
return load_module_from_file_object(fp, filename=path, get_code=True)
180180

181181

182-
def roundtrip_pyc(input_path: str, unlink_on_success: bool) -> int:
182+
def roundtrip_pyc(input_path: str, unlink_on_success: bool, verbose: bool) -> int:
183183

184184
# parser = argparse.ArgumentParser(
185185
# description="Load a .pyc with xdis, rewrite it to a temporary file, and compare."
@@ -262,8 +262,9 @@ def roundtrip_pyc(input_path: str, unlink_on_success: bool) -> int:
262262
print(f"WARNING: could not do raw byte comparison: {e}", file=sys.stderr)
263263

264264
print("Original file:", input_path)
265-
print("Rewritten file:", tf_name)
266-
print("Raw-bytes identical:", same_bytes)
265+
if verbose:
266+
print("Rewritten file:", tf_name)
267+
print("Raw-bytes identical:", same_bytes)
267268
if same_bytes:
268269
if unlink_on_success:
269270
os.unlink(tf_name)

0 commit comments

Comments
 (0)