Skip to content

Commit

Permalink
make integration tests more tolerant
Browse files Browse the repository at this point in the history
  • Loading branch information
smacke committed Oct 3, 2024
1 parent c200403 commit 4bddf52
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
2 changes: 1 addition & 1 deletion test-data
23 changes: 5 additions & 18 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-

import filecmp
import os
import shutil
import tempfile
Expand All @@ -24,7 +22,6 @@
SYNCED = "synchronized"
UNSYNCED = "unsynchronized"
SKIP = "skip"
FILECMP = "filecmp"
SHOULD_DETECT_ENCODING = "should_detect_encoding"
EXTRA_ARGS = "extra_args"
EXTRA_NO_VALUE_ARGS = "extra_no_value_args"
Expand All @@ -51,13 +48,10 @@ def test_path(fname):
unparsed_args.append("--{}".format(extra_key))
args = parser.parse_args(unparsed_args)
truth = test_path(test[SYNCED])
should_filecmp = True
if FILECMP in test:
should_filecmp = test[FILECMP]
should_detect_encoding = None
if SHOULD_DETECT_ENCODING in test:
should_detect_encoding = test[SHOULD_DETECT_ENCODING]
yield args, truth, should_filecmp, should_detect_encoding
yield args, truth, should_detect_encoding


def timestamps_roughly_match(f1, f2):
Expand All @@ -66,7 +60,7 @@ def timestamps_roughly_match(f1, f2):
pipe = make_pipeline(parser, extractor)
f1_bitstring = pipe.fit_transform(f1).astype(bool)
f2_bitstring = pipe.fit_transform(f2).astype(bool)
return np.alltrue(f1_bitstring == f2_bitstring)
return np.sum(f1_bitstring == f2_bitstring) / len(f1_bitstring) >= 0.99


def detected_encoding(fname):
Expand All @@ -76,10 +70,8 @@ def detected_encoding(fname):


@pytest.mark.integration
@pytest.mark.parametrize(
"args,truth,should_filecmp,should_detect_encoding", gen_synctest_configs()
)
def test_sync_matches_ground_truth(args, truth, should_filecmp, should_detect_encoding):
@pytest.mark.parametrize("args,truth,should_detect_encoding", gen_synctest_configs())
def test_sync_matches_ground_truth(args, truth, should_detect_encoding):
# context manager TemporaryDirectory not available on py2
dirpath = tempfile.mkdtemp()
try:
Expand All @@ -88,12 +80,7 @@ def test_sync_matches_ground_truth(args, truth, should_filecmp, should_detect_en
)
args.skip_ssa_info = True
assert ffsubsync.run(args)["retval"] == 0
if should_filecmp:
# uncomment this after verifying that test failures are false positives
# shutil.copy(args.srtout, truth)
assert filecmp.cmp(args.srtout, truth, shallow=False)
else:
assert timestamps_roughly_match(args.srtout, truth)
assert timestamps_roughly_match(args.srtout, truth)
if should_detect_encoding is not None:
assert detected_encoding(args.srtin[0]) == should_detect_encoding
finally:
Expand Down

0 comments on commit 4bddf52

Please sign in to comment.