Skip to content

Commit a119845

Browse files
committed
Cleanup
1 parent 37e9b53 commit a119845

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

test/test_other.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11899,49 +11899,41 @@ def check_output_sizes(self, *outputs: str, **metadata):
1189911899

1190011900
obtained_results = {}
1190111901

11902+
def update_and_print_diff(key, actual, expected):
11903+
obtained_results[key] = actual
11904+
diff = actual - expected
11905+
s = f'{key}: size={actual}, expected={expected}'
11906+
if diff:
11907+
s += f', delta={diff} ({diff * 100.0 / expected:+.2f}%)'
11908+
print(s)
11909+
return diff
11910+
1190211911
total_output_size = 0
1190311912
total_expected_size = 0
1190411913
total_output_size_gz = 0
1190511914
total_expected_size_gz = 0
11915+
1190611916
for f in outputs:
11907-
f_gz = f + '.gz'
11908-
expected_size = expected_results.get(f, inf)
11909-
expected_size_gz = expected_results.get(f_gz, inf)
1191011917
contents = read_binary(f)
11911-
size = len(contents)
11912-
size_gz = len(gzip.compress(contents))
1191311918

11914-
obtained_results[f] = size
11915-
obtained_results[f_gz] = size_gz
11916-
11917-
if not common.EMTEST_REBASELINE and size != expected_size and (f.endswith(('.js', '.html'))):
11918-
print('Contents of ' + f + ': ')
11919+
size = len(contents)
11920+
expected_size = expected_results.get(f, inf)
11921+
if update_and_print_diff(f, size, expected_size) and common.EMTEST_VERBOSE and not common.EMTEST_REBASELINE and f.endswith(('.js', '.html')):
11922+
print(f'Contents of {f}:')
1191911923
print(contents.decode('utf-8', errors='replace'))
11920-
11921-
def print_diff(title, actual, expected):
11922-
diff = actual - expected
11923-
s = f'{title}={actual}, expected {expected}'
11924-
if diff > 0:
11925-
s += f', delta={diff} ({diff * 100.0 / expected:+.2f}%)'
11926-
print(s)
11927-
11928-
print_diff(f'size of {f}', size, expected_size)
11929-
print_diff(f'size of {f_gz}', size_gz, expected_size_gz)
11930-
11931-
# N.B. even though the test code above prints out gzip compressed sizes, regression testing is done against uncompressed sizes
11932-
# this is because optimizing for compressed sizes can be unpredictable and sometimes counterproductive
1193311924
total_output_size += size
1193411925
total_expected_size += expected_size
1193511926

11927+
f_gz = f + '.gz'
11928+
size_gz = len(gzip.compress(contents))
11929+
expected_size_gz = expected_results.get(f_gz, inf)
11930+
update_and_print_diff(f_gz, size_gz, expected_size_gz)
1193611931
total_output_size_gz += size_gz
1193711932
total_expected_size_gz += expected_size_gz
1193811933

1193911934
if len(outputs) > 1:
11940-
obtained_results['total'] = total_output_size
11941-
obtained_results['total_gz'] = total_output_size_gz
11942-
11943-
print_diff('Total output size', total_output_size, total_expected_size)
11944-
print_diff('Total output size gzipped', total_output_size_gz, total_expected_size_gz)
11935+
update_and_print_diff('total', total_output_size, total_expected_size)
11936+
update_and_print_diff('total_gz', total_output_size_gz, total_expected_size_gz)
1194511937

1194611938
obtained_results.update(metadata)
1194711939

0 commit comments

Comments
 (0)