From a288d97b1434cd03baf692899963108be6447cf9 Mon Sep 17 00:00:00 2001 From: Rob Hallam <0504004h@student.gla.ac.uk> Date: Sat, 31 Aug 2024 14:25:54 +0100 Subject: [PATCH] test: [WFE] Negative and aprtial tests Ensure: - no words are correctly not matched - some words are matched --- test/test_feature_extractors.py | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/test/test_feature_extractors.py b/test/test_feature_extractors.py index 796c4d9..d19c93e 100644 --- a/test/test_feature_extractors.py +++ b/test/test_feature_extractors.py @@ -337,8 +337,8 @@ class TestWordFeatureExtractor(unittest.TestCase): test_extractor.teardown() self.assertEqual(test_extractor.features, []) - def test_extract_mocked_transcribe(self): - """Mock out the actual call to transcribe""" + def test_extract_mocked_transcribe_matching_words(self): + """Mock out the actual call to transcribe but match all words in the sentence""" video_source = TestSourceMedia().one_colour_silent_audio() test_extractor = extractors.WordFeatureExtractor(input_files=video_source) # mock _transcribe and mock out model and batched pipeline for speed @@ -352,3 +352,33 @@ class TestWordFeatureExtractor(unittest.TestCase): self.assertEqual(len(test_extractor.features), 9) + def test_extract_mocked_transcribe_no_matching_words(self): + """Mock out the actual call to transcribe but match no words in the sentence""" + video_source = TestSourceMedia().one_colour_silent_audio() + test_extractor = extractors.WordFeatureExtractor(input_files=video_source) + # mock _transcribe and mock out model and batched pipeline for speed + test_extractor._transcribe = self.mock_transcribe + test_extractor._model = MagicMock() + test_extractor._batched_model = MagicMock() + # set up and run the extractor + test_extractor.setup(words=["nonexistentword"]) + test_extractor.run() + test_extractor.teardown() + + self.assertEqual(len(test_extractor.features), 0) + + + def test_extract_mocked_transcribe_some_matching_words(self): + """Mock out the actual call to transcribe but match some words in the sentence""" + video_source = TestSourceMedia().one_colour_silent_audio() + test_extractor = extractors.WordFeatureExtractor(input_files=video_source) + # mock _transcribe and mock out model and batched pipeline for speed + test_extractor._transcribe = self.mock_transcribe + test_extractor._model = MagicMock() + test_extractor._batched_model = MagicMock() + # set up and run the extractor + test_extractor.setup(words=["quick", "jumps", "dog"]) + test_extractor.run() + test_extractor.teardown() + + self.assertEqual(len(test_extractor.features), 3)