ソースを参照

test: expand TestFfmpegVideoProducer coverage

mocks out calls to ffmpeg for obvious reasons
main
Rob Hallam 3ヶ月前
コミット
649fcae070
1個のファイルの変更40行の追加17行の削除
  1. +40
    -17
      test/test_producers.py

+ 40
- 17
test/test_producers.py ファイルの表示

@@ -1,18 +1,16 @@
"""test_producers.py -- test the producers in the pipeline (eg ffmpeg, visualisation, json)"""
import unittest
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):
"""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):
# test with no features -- should raise ValueError
with self.assertRaises(ValueError):
@@ -20,23 +18,40 @@ class TestFfmpegVideoProducer(unittest.TestCase):

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

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):
# 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):
"""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):
"""Test VisualisationProducer (produces matplotlib visualisations)"""
@@ -48,7 +63,7 @@ class TestVisualisationProducer(unittest.TestCase):

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

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

def test_produce(self):
"""Test we can call produce without error"""
feature = MockFeature(interval="")
feature = mocks.MockFeature(interval="")
features = [feature]
jsonprod = producers.JSONProducer(features=features)
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())

読み込み中…
キャンセル
保存