Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

104 linhas
3.9 KiB

  1. """test_producers.py -- test the producers in the pipeline (eg ffmpeg, visualisation, json)"""
  2. import unittest
  3. import pipeline.video_producers as producers
  4. import test.mocks as mocks
  5. class TestFfmpegVideoProducer(unittest.TestCase):
  6. """Test FfmpegVideoProducer (produces videos using ffmpeg)"""
  7. def mock_run_no_output(self, cmd, cwd="."):
  8. """Mock out _run_no_output"""
  9. return None
  10. def test_init_empty(self):
  11. # test with no features -- should raise ValueError
  12. with self.assertRaises(ValueError):
  13. producers.FfmpegVideoProducer(features=None)
  14. def test_init(self):
  15. # test with features
  16. feature = mocks.MockFeature(interval="")
  17. features = [feature]
  18. vidprod = producers.FfmpegVideoProducer(features=features)
  19. self.assertEqual(vidprod.features, features)
  20. def test_ffmpeg_feature_to_clip(self):
  21. """Test without a feature and without output path -- unhappy path"""
  22. feature = mocks.MockFeature(interval=mocks.MockInterval(start=0, end=5),
  23. source=mocks.MockSource(path="test.mp4"))
  24. features = [feature]
  25. vidprod = producers.FfmpegVideoProducer(features=features)
  26. with self.assertRaises(ValueError):
  27. vidprod._ffmpeg_feature_to_clip(feature=None)
  28. with self.assertRaises(ValueError):
  29. vidprod._ffmpeg_feature_to_clip(feature=feature, output_filepath=None)
  30. def test_ffmpeg_concat_clips(self):
  31. """Test without clips and without output path -- unhappy path"""
  32. feature = mocks.MockFeature(interval="")
  33. features = [feature]
  34. vidprod = producers.FfmpegVideoProducer(features=features)
  35. with self.assertRaises(ValueError):
  36. vidprod._ffmpeg_concat_clips(clips=None)
  37. with self.assertRaises(ValueError):
  38. vidprod._ffmpeg_concat_clips(clips=features, output_filepath=None)
  39. # happy path
  40. def test_produce(self):
  41. """Test we can call produce without error"""
  42. feature = mocks.MockFeature(interval=mocks.MockInterval(start=0, end=5),
  43. source=mocks.MockSource(path="test.mp4"))
  44. features = [feature]
  45. vidprod = producers.FfmpegVideoProducer(features=features)
  46. vidprod.produce()
  47. class TestVisualisationProducer(unittest.TestCase):
  48. """Test VisualisationProducer (produces matplotlib visualisations)"""
  49. def test_init_empty(self):
  50. # test with no features -- should raise ValueError
  51. with self.assertRaises(ValueError):
  52. producers.VisualisationProducer(features=None)
  53. def test_init(self):
  54. # test with features
  55. feature = mocks.MockFeature(interval="")
  56. features = [feature]
  57. visprod = producers.VisualisationProducer(features=features)
  58. self.assertEqual(visprod.features, features)
  59. def test_produce(self):
  60. """Test we can call produce without error"""
  61. # TODO
  62. pass
  63. class TestJSONProducer(unittest.TestCase):
  64. def test_init_empty(self):
  65. # test with no features -- should raise ValueError
  66. with self.assertRaises(ValueError):
  67. producers.JSONProducer(features=None)
  68. def test_init(self):
  69. # test with features
  70. feature = mocks.MockFeature(interval="")
  71. features = [feature]
  72. jsonprod = producers.JSONProducer(features=features)
  73. self.assertEqual(jsonprod.features, features)
  74. def test_produce(self):
  75. """Test we can call produce without error"""
  76. feature = mocks.MockFeature(interval="")
  77. features = [feature]
  78. jsonprod = producers.JSONProducer(features=features)
  79. jsonprod.produce()
  80. class TestPipelineJSONEncoder(unittest.TestCase):
  81. """Test PipelineJSONEncoder"""
  82. # unhappy path
  83. def test_default_unserializable(self):
  84. pje = producers.PipelineJSONEncoder()
  85. with self.assertRaises(TypeError):
  86. pje.default(object())