Skip to content

Commit 8d9ee29

Browse files
committed
Allow tolerance when testing expected archive size
Small variation in the archive size could result from compression algorithm changes. With the previous exact comparison against the size data in the golden master index, this would cause a spurious test failure. The solution is to allow some tolerance in the sizes during the comparison. This still provides a useful "smoke test" while avoiding the test requiring undue maintenance effort.
1 parent d1b23ca commit 8d9ee29

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

test/test_all.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
import pathlib
3030
import platform
3131
import typing
32+
import math
3233

3334
import invoke.context
3435
import pytest
3536

3637
test_data_path = pathlib.Path(__file__).resolve().parent.joinpath("testdata")
38+
size_comparison_tolerance = 0.03 # Maximum allowed archive size difference ratio
3739

3840

3941
def test_all(run_command, working_dir):
@@ -174,7 +176,26 @@ def check_index(configuration):
174176
# Order of releases in the index is arbitrary so a simply equality assertion is not possible
175177
assert len(library_index["libraries"]) == len(golden_library_index["libraries"])
176178
for release in library_index["libraries"]:
177-
assert release in golden_library_index["libraries"]
179+
# Find the golden master for the release
180+
golden_release = None
181+
for golden_release_candidate in golden_library_index["libraries"]:
182+
if (
183+
golden_release_candidate["name"] == release["name"]
184+
and golden_release_candidate["version"] == release["version"]
185+
):
186+
golden_release = golden_release_candidate
187+
break
188+
189+
assert golden_release is not None # Matching golden release was found
190+
191+
# Small variation in size could result from compression algorithm changes, so we allow a tolerance
192+
assert "size" in release
193+
assert math.isclose(release["size"], golden_release["size"], rel_tol=size_comparison_tolerance)
194+
# Remove size data so a direct comparison of the remaining data can be made against the golden master
195+
del release["size"]
196+
del golden_release["size"]
197+
198+
assert release == golden_release
178199

179200

180201
# The engine's Git code struggles to get a clean checkout of releases under some circumstances.

0 commit comments

Comments
 (0)