|
@@ -0,0 +1,50 @@ |
|
|
|
|
|
"""test_feature_extractors.py - test pipeline feature extractors""" |
|
|
|
|
|
import unittest |
|
|
|
|
|
import os |
|
|
|
|
|
import pytest |
|
|
|
|
|
import pipeline.feature_extractors as extractors |
|
|
|
|
|
|
|
|
|
|
|
from pipeline.utils import Source, SourceMedia # technically makes this an integration test, but... |
|
|
|
|
|
class TestSource(): |
|
|
|
|
|
"""Provide utils.Source for testing""" |
|
|
|
|
|
def one_colour_silent_audio(self): |
|
|
|
|
|
"""Provide a source with a silent mono-colour video""" |
|
|
|
|
|
TEST_DIR = os.path.dirname(os.path.realpath(__file__)) |
|
|
|
|
|
SAMPLE_VIDEO = f"{TEST_DIR}/sample_videos/test_video_red_silentaudio.mp4" # silent video definitely has no laughter |
|
|
|
|
|
return Source(source=SAMPLE_VIDEO, path=SAMPLE_VIDEO, provider="test") |
|
|
|
|
|
|
|
|
|
|
|
class TestLaughterFeatureExtractor(unittest.TestCase): |
|
|
|
|
|
"""Test LaughterFeatureExtractor""" |
|
|
|
|
|
def test_init(self): |
|
|
|
|
|
test_extractor = extractors.LaughterFeatureExtractor() |
|
|
|
|
|
self.assertTrue(test_extractor) |
|
|
|
|
|
|
|
|
|
|
|
def test_setup_noinput(self): |
|
|
|
|
|
"""test setup - no input files""" |
|
|
|
|
|
test_extractor = extractors.LaughterFeatureExtractor() |
|
|
|
|
|
with self.assertRaises(ValueError): |
|
|
|
|
|
test_extractor.setup() |
|
|
|
|
|
# NB test WITH sources implicitly tested in test_extract |
|
|
|
|
|
|
|
|
|
|
|
class TestRandomFeatureExtractor(unittest.TestCase): |
|
|
|
|
|
"""Test RandomFeatureExtractor""" |
|
|
|
|
|
def test_init(self): |
|
|
|
|
|
test_extractor = extractors.RandomFeatureExtractor() |
|
|
|
|
|
self.assertTrue(test_extractor) |
|
|
|
|
|
|
|
|
|
|
|
def test_setup_noinput(self): |
|
|
|
|
|
"""test setup - no input files""" |
|
|
|
|
|
test_extractor = extractors.RandomFeatureExtractor() |
|
|
|
|
|
with self.assertRaises(ValueError): |
|
|
|
|
|
test_extractor.setup() |
|
|
|
|
|
# NB test WITH sources implicitly tested in test_extract |
|
|
|
|
|
|
|
|
|
|
|
def test_extract(self): |
|
|
|
|
|
"""Test extract with input files""" |
|
|
|
|
|
video_source = TestSourceMedia().one_colour_silent_audio() |
|
|
|
|
|
test_extractor = extractors.RandomFeatureExtractor(input_files=video_source) |
|
|
|
|
|
test_extractor.setup() |
|
|
|
|
|
test_extractor.run() |
|
|
|
|
|
test_extractor.teardown() |
|
|
|
|
|
self.assertTrue(test_extractor.features) |
|
|
|
|
|
|