- detect.py: _best_sibling_estimate() replaces a median/consensus across neighbouring episodes with the best match found. Found directly on a user-reported case (hpr0400): its three closest neighbours correlated at ~0 since they don't share this episode's specific jingle variant, but a fourth matched cleanly at 29.25s -- the median discarded that real evidence because it was outvoted by neighbours that simply aren't relevant, not because the intro genuinely doesn't match anything. Only the case where nothing nearby correlates at all is still flagged inconclusive. - cli.py: trim --episode N with no prior detect for that episode used to silently do nothing -- no output, no error, exit 0. Now errors clearly and tells the user to run detect first; a batch trim over a range still treats this as normal and reports a count instead. Also made trim's metadata connection lazy, so the error path doesn't need network access at all (a test that exercises it dropped from ~4s to instant). - docs/DESIGN.md: documented both fixes, and the format-default/ --format/precision fixes from immediately before this round. New tests: test_sibling_aggregation.py, test_cli_trim_errors.py.
40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
"""
|
|
Regression test for a real bug: taking a median/consensus across
|
|
sibling-correlation estimates discarded a genuine match whenever most
|
|
neighbours simply didn't happen to share this episode's specific jingle
|
|
variant. Found directly on hpr0400: its three closest neighbours
|
|
(399, 401, 402) correlated at ~0, but hpr0398 matched cleanly at 29.25s --
|
|
a median across all four reports ~0, silently discarding real evidence.
|
|
"""
|
|
import unittest
|
|
|
|
from hpr_stripper.detect import _best_sibling_estimate
|
|
|
|
|
|
class TestBestSiblingEstimate(unittest.TestCase):
|
|
def test_takes_the_best_match_not_the_median(self):
|
|
# hpr0400's real neighbour estimates: 398 matched cleanly, the
|
|
# other three didn't share this episode's jingle variant at all.
|
|
estimates = [0.25, 0.25, 0.25, 29.25]
|
|
value, flag = _best_sibling_estimate(estimates)
|
|
self.assertEqual(value, 29.25)
|
|
self.assertIsNone(flag)
|
|
|
|
def test_flags_when_nothing_found_anywhere_nearby(self):
|
|
estimates = [0.25, 0.25, 0.25, 0.25]
|
|
value, flag = _best_sibling_estimate(estimates)
|
|
self.assertEqual(value, 0.25)
|
|
self.assertEqual(flag, "no_asr_anchor_and_xcorr_inconclusive")
|
|
|
|
def test_no_estimates_returns_none_none(self):
|
|
self.assertEqual(_best_sibling_estimate([]), (None, None))
|
|
|
|
def test_single_strong_estimate_is_trusted(self):
|
|
value, flag = _best_sibling_estimate([15.25])
|
|
self.assertEqual(value, 15.25)
|
|
self.assertIsNone(flag)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|