From 55b532f1ebdb83957a4e45286c6fec32b5ee8ccf Mon Sep 17 00:00:00 2001 From: Rob Hallam <0504004h@student.gla.ac.uk> Date: Mon, 16 Sep 2024 00:33:15 +0100 Subject: [PATCH] test: fix LoudFE tests --- test/test_feature_extractors.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/test/test_feature_extractors.py b/test/test_feature_extractors.py index 914e11c..fceed31 100644 --- a/test/test_feature_extractors.py +++ b/test/test_feature_extractors.py @@ -159,12 +159,12 @@ class TestRandomFeatureExtractor(unittest.TestCase): class TestLoudAudioFeatureExtractor(unittest.TestCase): """Test LoudAudioFeatureExtractor""" - def _mock_loudnorm(self, *args, **kwargs): + def _mock_loudnorm_5(self, *args, **kwargs): """Mock _loudnorm It returns a list of 2-tuple floats (time, loudness) representing loud audio instances """ - return [(0.0, 0.0), (1.0, 1.0), (2.0, 2.0), (3.0, 3.0), (4.0, 4.0)] + return [(0.0, 0.0), (15.0, 1.0), (25.0, 2.0), (35.0, 3.0), (45.0, 4.0)] def _mock_get_loudnessess(self, *args, length=100, min_loudness=-101, max_loudness=100, seed=42, **kwargs) -> list: @@ -186,7 +186,7 @@ class TestLoudAudioFeatureExtractor(unittest.TestCase): loudness = random.randint(min_loudness, max_loudness) / 100 if min_loudness == -101: loudness = "-inf" if loudness == -1.01 else f"{loudness}" - loudnesses.append((float(f"{i}.0"), float(loudness))) + loudnesses.append((float(f"{i*20}.0"), float(loudness))) return loudnesses @@ -209,11 +209,11 @@ class TestLoudAudioFeatureExtractor(unittest.TestCase): test_extractor.teardown() self.assertEqual(test_extractor.features, []) - def test_extract_mocked_loudnorm(self): + def test_extract_mocked_loudnorm_5(self): """Test extract with mocked loudness detection""" video_source = TestSourceMedia().one_colour_silent_audio() test_extractor = extractors.LoudAudioFeatureExtractor(input_files=video_source) - test_extractor._loudnorm = self._mock_loudnorm + test_extractor._loudnorm = self._mock_loudnorm_5 test_extractor.setup() test_extractor.run() test_extractor.teardown() @@ -231,16 +231,21 @@ class TestLoudAudioFeatureExtractor(unittest.TestCase): def test_keep_num(self): """Test keep_num correctly keeps 5 / 10""" + min_duration = 0 video_source = TestSourceMedia().one_colour_silent_audio() with self.subTest("keep 5 (default)"): - test_extractor = extractors.LoudAudioFeatureExtractor(input_files=video_source) + test_extractor = extractors.LoudAudioFeatureExtractor(input_files=video_source, + min_duration=min_duration, + num_features=5) test_extractor._get_loudnesses = self._mock_get_loudnessess test_extractor.setup() test_extractor.run() test_extractor.teardown() self.assertEqual(len(test_extractor.features), 5) with self.subTest("keep 10"): - test_extractor = extractors.LoudAudioFeatureExtractor(input_files=video_source, num_features=10) + test_extractor = extractors.LoudAudioFeatureExtractor(input_files=video_source, + min_duration=min_duration, + num_features=10) test_extractor._get_loudnesses = self._mock_get_loudnessess test_extractor.setup() test_extractor.run() @@ -264,8 +269,13 @@ class TestVideoActivityFeatureExtractor(unittest.TestCase): def test_extract(self): """Test extract with basic input file runs with no errors""" + num_features = 50 + min_duration = 0 + video_source = TestSourceMedia().one_colour_silent_audio() - test_extractor = extractors.VideoActivityFeatureExtractor(input_files=video_source) + test_extractor = extractors.VideoActivityFeatureExtractor(input_files=video_source, + num_features=num_features, + min_duration=min_duration) test_extractor.setup() test_extractor.run() test_extractor.teardown()