From 48ead78c9ad65ca6e00d6565cd6143b8ab879901 Mon Sep 17 00:00:00 2001 From: Rob Hallam <0504004h@student.gla.ac.uk> Date: Thu, 15 Aug 2024 15:09:16 +0100 Subject: [PATCH] test: add TestJSONP & TestVisualisationP --- test/test_producers.py | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/test_producers.py diff --git a/test/test_producers.py b/test/test_producers.py new file mode 100644 index 0000000..0680b59 --- /dev/null +++ b/test/test_producers.py @@ -0,0 +1,52 @@ +"""test_producers.py -- test the producers in the pipeline (eg ffmpeg, visualisation, json)""" +import unittest +import pipeline.video_producers as producers + + +class MockFeature(): + """Mock feature object for testing JSONProducer""" + def __init__(self, interval): + self.interval = interval + def to_json(self): + return {"interval": self.interval} + +class TestVisualisationProducer(unittest.TestCase): + """Test VisualisationProducer (produces matplotlib visualisations)""" + + def test_init_empty(self): + # test with no features -- should raise ValueError + with self.assertRaises(ValueError): + producers.VisualisationProducer(features=None) + + def test_init(self): + # test with features + feature = MockFeature(interval="") + features = [feature] + visprod = producers.VisualisationProducer(features=features) + self.assertEqual(visprod.features, features) + + def test_produce(self): + """Test we can call produce without error""" + # TODO + pass + +class TestJSONProducer(unittest.TestCase): + def test_init_empty(self): + # test with no features -- should raise ValueError + with self.assertRaises(ValueError): + producers.JSONProducer(features=None) + + def test_init(self): + # test with features + feature = 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="") + features = [feature] + jsonprod = producers.JSONProducer(features=features) + jsonprod.produce() +