Browse Source

test: expand TestFfmpegVideoProducer coverage

mocks out calls to ffmpeg for obvious reasons
main
Rob Hallam 3 months ago
parent
commit
649fcae070
1 changed files with 40 additions and 17 deletions
  1. +40
    -17
      test/test_producers.py

+ 40
- 17
test/test_producers.py View File

@@ -1,18 +1,16 @@
"""test_producers.py -- test the producers in the pipeline (eg ffmpeg, visualisation, json)""" """test_producers.py -- test the producers in the pipeline (eg ffmpeg, visualisation, json)"""
import unittest import unittest
import pipeline.video_producers as producers import pipeline.video_producers as producers
import test.mocks as mocks




class MockFeature():
"""Mock feature object for testing JSONProducer"""
def __init__(self, interval):
self.interval = interval
def to_json(self):
return {"interval": self.interval}

class TestFfmpegVideoProducer(unittest.TestCase): class TestFfmpegVideoProducer(unittest.TestCase):
"""Test FfmpegVideoProducer (produces videos using ffmpeg)""" """Test FfmpegVideoProducer (produces videos using ffmpeg)"""


def mock_run_no_output(self, cmd, cwd="."):
"""Mock out _run_no_output"""
return None

def test_init_empty(self): def test_init_empty(self):
# test with no features -- should raise ValueError # test with no features -- should raise ValueError
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
@@ -20,23 +18,40 @@ class TestFfmpegVideoProducer(unittest.TestCase):


def test_init(self): def test_init(self):
# test with features # test with features
feature = MockFeature(interval="")
feature = mocks.MockFeature(interval="")
features = [feature] features = [feature]
vidprod = producers.FfmpegVideoProducer(features=features) vidprod = producers.FfmpegVideoProducer(features=features)
self.assertEqual(vidprod.features, features) self.assertEqual(vidprod.features, features)


def test_ffmpeg_feature_to_clip(self): def test_ffmpeg_feature_to_clip(self):
# TODO
pass
"""Test without a feature and without output path -- unhappy path"""
feature = mocks.MockFeature(interval=mocks.MockInterval(start=0, end=5),
source=mocks.MockSource(path="test.mp4"))
features = [feature]
vidprod = producers.FfmpegVideoProducer(features=features)
with self.assertRaises(ValueError):
vidprod._ffmpeg_feature_to_clip(feature=None)
with self.assertRaises(ValueError):
vidprod._ffmpeg_feature_to_clip(feature=feature, output_filepath=None)


def test_ffmpeg_concat_clips(self): def test_ffmpeg_concat_clips(self):
# TODO
pass
"""Test without clips and without output path -- unhappy path"""
feature = mocks.MockFeature(interval="")
features = [feature]
vidprod = producers.FfmpegVideoProducer(features=features)
with self.assertRaises(ValueError):
vidprod._ffmpeg_concat_clips(clips=None)
with self.assertRaises(ValueError):
vidprod._ffmpeg_concat_clips(clips=features, output_filepath=None)


# happy path
def test_produce(self): def test_produce(self):
"""Test we can call produce without error""" """Test we can call produce without error"""
# TODO
pass
feature = mocks.MockFeature(interval=mocks.MockInterval(start=0, end=5),
source=mocks.MockSource(path="test.mp4"))
features = [feature]
vidprod = producers.FfmpegVideoProducer(features=features)
vidprod.produce()


class TestVisualisationProducer(unittest.TestCase): class TestVisualisationProducer(unittest.TestCase):
"""Test VisualisationProducer (produces matplotlib visualisations)""" """Test VisualisationProducer (produces matplotlib visualisations)"""
@@ -48,7 +63,7 @@ class TestVisualisationProducer(unittest.TestCase):


def test_init(self): def test_init(self):
# test with features # test with features
feature = MockFeature(interval="")
feature = mocks.MockFeature(interval="")
features = [feature] features = [feature]
visprod = producers.VisualisationProducer(features=features) visprod = producers.VisualisationProducer(features=features)
self.assertEqual(visprod.features, features) self.assertEqual(visprod.features, features)
@@ -66,15 +81,23 @@ class TestJSONProducer(unittest.TestCase):


def test_init(self): def test_init(self):
# test with features # test with features
feature = MockFeature(interval="")
feature = mocks.MockFeature(interval="")
features = [feature] features = [feature]
jsonprod = producers.JSONProducer(features=features) jsonprod = producers.JSONProducer(features=features)
self.assertEqual(jsonprod.features, features) self.assertEqual(jsonprod.features, features)


def test_produce(self): def test_produce(self):
"""Test we can call produce without error""" """Test we can call produce without error"""
feature = MockFeature(interval="")
feature = mocks.MockFeature(interval="")
features = [feature] features = [feature]
jsonprod = producers.JSONProducer(features=features) jsonprod = producers.JSONProducer(features=features)
jsonprod.produce() jsonprod.produce()


class TestPipelineJSONEncoder(unittest.TestCase):
"""Test PipelineJSONEncoder"""
# unhappy path

def test_default_unserializable(self):
pje = producers.PipelineJSONEncoder()
with self.assertRaises(TypeError):
pje.default(object())

Loading…
Cancel
Save