Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

108 righe
4.3 KiB

  1. """test_feature_extractors.py - test pipeline feature extractors"""
  2. import unittest
  3. import os
  4. import pytest
  5. import pipeline.feature_extractors as extractors
  6. from pipeline.utils import Source, SourceMedia # technically makes this an integration test, but...
  7. class TestSource():
  8. """Provide utils.Source for testing"""
  9. def one_colour_silent_audio(self):
  10. """Provide a source with a silent mono-colour video"""
  11. TEST_DIR = os.path.dirname(os.path.realpath(__file__))
  12. SAMPLE_VIDEO = f"{TEST_DIR}/sample_videos/test_video_red_silentaudio.mp4" # silent video definitely has no laughter
  13. return Source(source=SAMPLE_VIDEO, path=SAMPLE_VIDEO, provider="test")
  14. class TestSourceMedia():
  15. """Provide utils.SourceMedia for testing"""
  16. def one_colour_silent_audio(self):
  17. """Provide a source with a silent mono-colour video"""
  18. return SourceMedia(sources=[TestSource().one_colour_silent_audio()])
  19. class TestLaughterFeatureExtractor(unittest.TestCase):
  20. """Test LaughterFeatureExtractor"""
  21. def test_init(self):
  22. test_extractor = extractors.LaughterFeatureExtractor()
  23. self.assertTrue(test_extractor)
  24. def test_setup_noinput(self):
  25. """test setup - no input files"""
  26. test_extractor = extractors.LaughterFeatureExtractor()
  27. with self.assertRaises(ValueError):
  28. test_extractor.setup()
  29. # NB test WITH sources implicitly tested in test_extract
  30. class TestRandomFeatureExtractor(unittest.TestCase):
  31. """Test RandomFeatureExtractor"""
  32. def test_init(self):
  33. test_extractor = extractors.RandomFeatureExtractor()
  34. self.assertTrue(test_extractor)
  35. def test_setup_noinput(self):
  36. """test setup - no input files"""
  37. test_extractor = extractors.RandomFeatureExtractor()
  38. with self.assertRaises(ValueError):
  39. test_extractor.setup()
  40. # NB test WITH sources implicitly tested in test_extract
  41. def test_extract_noinput(self):
  42. """Test extract with no input files"""
  43. test_extractor = extractors.RandomFeatureExtractor()
  44. with self.assertRaises(ValueError):
  45. test_extractor.run()
  46. def test_extract(self):
  47. """Test extract with input files"""
  48. video_source = TestSourceMedia().one_colour_silent_audio()
  49. test_extractor = extractors.RandomFeatureExtractor(input_files=video_source)
  50. test_extractor.setup()
  51. test_extractor.run()
  52. test_extractor.teardown()
  53. self.assertTrue(test_extractor.features)
  54. class TestLoudAudioFeatureExtractor(unittest.TestCase):
  55. """Test LoudAudioFeatureExtractor"""
  56. def test_init(self):
  57. video_source = TestSourceMedia().one_colour_silent_audio()
  58. test_extractor = extractors.LoudAudioFeatureExtractor(input_files=video_source)
  59. self.assertTrue(test_extractor)
  60. def test_init_noinput(self):
  61. """test init - no input files"""
  62. with self.assertRaises(ValueError):
  63. test_extractor = extractors.LoudAudioFeatureExtractor()
  64. def test_extract(self):
  65. """Test extract with input files"""
  66. video_source = TestSourceMedia().one_colour_silent_audio()
  67. test_extractor = extractors.LoudAudioFeatureExtractor(input_files=video_source)
  68. test_extractor.setup()
  69. test_extractor.run()
  70. test_extractor.teardown()
  71. self.assertEqual(test_extractor.features, [])
  72. class TestVideoActivityFeatureExtractor(unittest.TestCase):
  73. """Test VideoActivityFeatureExtractor"""
  74. def test_init(self):
  75. video_source = TestSourceMedia().one_colour_silent_audio()
  76. test_extractor = extractors.VideoActivityFeatureExtractor(input_files=video_source)
  77. self.assertTrue(test_extractor)
  78. def test_init_noinput(self):
  79. """test init - no input files"""
  80. with self.assertRaises(ValueError):
  81. test_extractor = extractors.VideoActivityFeatureExtractor()
  82. def test_extract(self):
  83. """Test extract with basic input file runs with no errors"""
  84. video_source = TestSourceMedia().one_colour_silent_audio()
  85. test_extractor = extractors.VideoActivityFeatureExtractor(input_files=video_source)
  86. test_extractor.setup()
  87. test_extractor.run()
  88. test_extractor.teardown()
  89. self.assertTrue(test_extractor.features)
  90. # TODO: add sample video with activity to test _activitydetect()