def setUp(self) -> None: self.GoodContainer = testlib.mockContainer( b"\rframe 918.3kbits/s 38.8image 25 fps \frame 920.3kbits/s" b"\rframe 918.3kbits/s 38.8image 25 fps \frame 920.3kbits/s" b"\rframe 918.3kbits/s 38.8image 25 fps \frame 920.3kbits/s" b"\rframe 918.3kbits/s 38.8image 25 fps \frame 920.3kbits/s") self.badContainer = testlib.mockContainer(b"press [q] press [h]") self.goodConfig = pd.DataFrame({ "File": [ "test_files\\vids\\test.mp4", "test_files\\vids\\test2.mp4", "test_files\\vids\\test4.mp4", ], "Date/Time": [ pd.Timestamp("2025-06-21 12:00:00"), pd.Timestamp("2025-06-22 13:00:00"), pd.Timestamp("2025-07-23 14:00:00"), ], }) self.goodCredentials = { "User": 12345, "Password": 678910, "rtmp-URL": "rtmp://i.amagood.server", "playpath": "dclive_0_1@2345", } self.mockframe = testlib.mockFrame() # draw grid onto mockFrame lib.drawConfigGrid(self.mockframe) # monkey patch lib.showerror so that I can catch to result lib.showerror = testlib.raiseAssertion
def test_checkRightTime_StreamInPast(self): mockframe = testlib.mockFrame() # add current time mockframe.nowDT = pd.Timestamp("2010-06-21 12:00:00") # add schedule mockframe.schedule = pd.DataFrame({ "File": [ "C:\\Users\\michael.mitter\\Documents\\streamscheduler\\test_files\\vids\\test.mp4", "C:\\Users\\michael.mitter\\Documents\\streamscheduler\\test_files\\vids\\test2.mp4", "C:\\Users\\michael.mitter\\Documents\\streamscheduler\\test_files\\vids\\test4.mp4", ], "Date/Time": [ pd.Timestamp("2009-06-21 12:00:00"), pd.Timestamp("2009-06-22 13:00:00"), pd.Timestamp("2009-07-23 14:00:00"), ], }) # monkeypatch dispatch stream oldDispatch = lib.dispatch_stream lib.dispatch_stream = testlib.raiseAssertion lib.checkRightTime(mockframe) # should not raise AssertionError self.assertEqual(mockframe.container, None) self.assertEqual(mockframe.streamActive, False) # undo monkeypatch lib.dispatch_stream = oldDispatch
def test_drawconfigGrid(self): mockframe = testlib.mockFrame() lib.drawConfigGrid(mockframe) self.assertEqual(list(mockframe.grid["Names"].keys()), ["File", "Date/Time"]) self.assertEqual(len(mockframe.grid["grid"]), 10) for i in range(10): self.assertEqual(len(mockframe.grid["grid"][i]), 2)
def test_checkStream_noContainer(self): # test whether nothing happens if container is none mockframe = testlib.mockFrame() # monkey patch onupdate lib.onUpdate = lambda x: 1 lib.createStatusWidget(mockframe) lib.checkStream(mockframe) self.assertEqual(mockframe.status.get(), "yellow") self.assertEqual(mockframe.streamActive, False)
def setUp(self): self.credentials = { "User": 12345, "Password": 678910, "rtmp-URL": "rtmp://i.amagood.server", "playpath": "dclive_0_1@2345", } self.engine = testlib.mockEngine() self.mockframe = testlib.mockFrame() self.mockframe.credentials = self.credentials
def test_checkRightTime_noSchedule(self): mockframe = testlib.mockFrame() # monkeypatch dispatch stream oldDispatch = lib.dispatch_stream lib.dispatch_stream = testlib.raiseAssertion lib.checkRightTime(mockframe) # should not raise AssertionError self.assertEqual(mockframe.container, None) self.assertEqual(mockframe.streamActive, False) # undo monkeypatch lib.dispatch_stream = oldDispatch
def test_createTimeWidget(self): mockframe = testlib.mockFrame() # monkey patch onupdate oldOnUpdate = lib.onUpdate lib.onUpdate = lambda x: 1 lib.createTimeWidget(mockframe) # check whether it is there self.assertTrue(hasattr(mockframe, "time_label")) self.assertTrue(hasattr(mockframe, "time_title")) self.assertTrue(hasattr(mockframe, "now")) # undo monkey patch lib.onUpdate = oldOnUpdate
def test_checkStream_containerRunningEarly(self): """Tests whether the reaction to a running container that has no valid bitrate output is correct.""" # test whether nothing happens if container is none mockframe = testlib.mockFrame() mockframe.container = testlib.mockContainer(status="running", log=b"asdf") # monkey patch onupdate lib.onUpdate = lambda x: 1 lib.createStatusWidget(mockframe) lib.checkStream(mockframe) self.assertEqual(mockframe.status.get(), "green") self.assertEqual(mockframe.streamActive, False) self.assertEqual(mockframe.lbl_StreamSpeed["text"], "-/-")
def test_createStatusWidget(self): mockframe = testlib.mockFrame() # monkey patch onupdate oldOnUpdate = lib.onUpdate lib.onUpdate = lambda x: 1 lib.createStatusWidget(mockframe) # check whether it is there self.assertTrue(hasattr(mockframe, "status")) self.assertTrue(hasattr(mockframe, "streamSpeed")) self.assertTrue(hasattr(mockframe, "status_title")) self.assertTrue(hasattr(mockframe, "rectl_status")) self.assertTrue(hasattr(mockframe, "lbl_StreamSpeed")) # undo monkey patch lib.onUpdate = oldOnUpdate
def test_checkPastStream(self): mockframe = testlib.mockFrame() mockframe.streamActive = True mockframe.nowDT = pd.Timestamp("2009-07-23 14:00:00") # monkey patch draw config and on update oldDrawConfig = lib.draw_config lib.draw_config = lambda x, y: None oldOnUpdate = lib.onUpdate lib.onUpdate = lambda: None # only present/future events goodDf = pd.DataFrame({ "File": [ "C:\\Users\\michael.mitter\\Documents\\streamscheduler\\test_files\\vids\\test.mp4", "C:\\Users\\michael.mitter\\Documents\\streamscheduler\\test_files\\vids\\test2.mp4", "C:\\Users\\michael.mitter\\Documents\\streamscheduler\\test_files\\vids\\test4.mp4", ], "Date/Time": [ pd.Timestamp("2015-06-21 12:00:01"), pd.Timestamp("2015-06-22 13:00:00"), pd.Timestamp("2015-07-23 14:00:00"), ], }) mockframe.schedule = goodDf lib.checkPastStream(mockframe) assert_frame_equal(mockframe.schedule, goodDf) # one past event badDf = pd.DataFrame({ "File": [ "C:\\Users\\michael.mitter\\Documents\\streamscheduler\\test_files\\vids\\test.mp4", "C:\\Users\\michael.mitter\\Documents\\streamscheduler\\test_files\\vids\\test2.mp4", "C:\\Users\\michael.mitter\\Documents\\streamscheduler\\test_files\\vids\\test4.mp4", ], "Date/Time": [ pd.Timestamp("2008-06-21 12:00:01"), pd.Timestamp("2012-06-22 13:00:00"), pd.Timestamp("2012-07-23 14:00:00"), ], }) mockframe.schedule = badDf lib.checkPastStream(mockframe) assert_frame_equal(mockframe.schedule, badDf.iloc[1:, :]) # restore old draw config lib.draw_config = oldDrawConfig lib.onUpdate = oldOnUpdate
def test_askExit(self): # make mockfraem mockframe = testlib.mockFrame() mockroot = testlib.mockRoot() # save old askyesno oldAskYesNo = lib.askyesno # monkey patch in alwasy true lib.askyesno = lambda x, y: True # set stream to active mockframe.streamActive = True destroyCall = partial(lib.askExit, frame=mockframe, root=mockroot) self.assertRaises(testlib.RootDestroyedException, destroyCall) # set stream to inactive lib.askyesno = lambda x, y: False # set stream to active mockframe.streamActive = True destroyCall = partial(lib.askExit, frame=mockframe, root=mockroot) # restore old function lib.askyesno = oldAskYesNo
def test_checkRightTime_RightTime(self): mockframe = testlib.mockFrame() # add current time mockframe.nowDT = pd.Timestamp("2010-06-21 12:00:00") # add schedule mockframe.schedule = pd.DataFrame({ "File": [ "C:\\Users\\michael.mitter\\Documents\\streamscheduler\\test_files\\vids\\test.mp4", "C:\\Users\\michael.mitter\\Documents\\streamscheduler\\test_files\\vids\\test2.mp4", "C:\\Users\\michael.mitter\\Documents\\streamscheduler\\test_files\\vids\\test4.mp4", ], "Date/Time": [ pd.Timestamp("2010-06-21 12:00:01"), pd.Timestamp("2009-06-22 13:00:00"), pd.Timestamp("2009-07-23 14:00:00"), ], }) # monkeypatch dispatch stream oldDispatch = lib.dispatch_stream lib.dispatch_stream = testlib.raiseAssertion goodCall = partial(lib.checkRightTime, mockframe) self.assertRaises(AssertionError, goodCall) # second monkeypatch to check whether events afterwards happen correctly lib.dispatch_stream = lambda x, y, z: None mockframe.after = ( testlib.raiseAssertion ) # this is called by the error dispatching functions oldDrawConfig = lib.draw_config lib.draw_config = lambda x, y: None goodCall = partial(lib.checkRightTime, mockframe) self.assertRaises(AssertionError, goodCall) # call it again to see whether the effects are correct mockframe.after = ( lambda x, y, z, a: None ) # this is called by the error dispatching functions lib.checkRightTime( mockframe ) # before the call only goes through to frame.after because assertion is raised there self.assertEqual(len(mockframe.schedule), 2) self.assertEqual(mockframe.streamActive, False) # undo monkeypatch lib.dispatch_stream = oldDispatch lib.draw_config = oldDrawConfig
def test_checkStream_containerCreated_finished(self): """Check whether reaction to a container that has been created and finished succesfully is correct.""" mockframe = testlib.mockFrame() mockframe.container = testlib.mockContainer(status="created", log=b"asdf") # monkey patch onupdate oldOnUpdate = lib.onUpdate lib.onUpdate = lambda x: 1 # monkeypatch client oldClient = lib.docker.from_env lib.docker.from_env = lambda: testlib.mockEngine(testlib.mockImages()) lib.createStatusWidget(mockframe) lib.checkStream(mockframe) self.assertEqual(mockframe.status.get(), "yellow") self.assertEqual(mockframe.streamActive, False) self.assertEqual(mockframe.lbl_StreamSpeed["text"], "Inactive") self.assertEqual(mockframe.container, None) # undo monkeypatch lib.onUpdate = oldOnUpdate lib.docker.from_env = oldClient
def test_checkStream_containerCreated_inList(self): """Tests whether the reaction to a created container that is then the client.containers.list is correct""" mockframe = testlib.mockFrame() mockframe.container = testlib.mockContainer(status="created", log=b"asdf") # monkey patch onupdate oldOnUpdate = lib.onUpdate lib.onUpdate = lambda x: 1 # monkeypatch client oldClient = lib.docker.from_env lib.docker.from_env = lambda: testlib.mockEngine( testlib.mockImages(), containers=[mockframe.container]) lib.createStatusWidget(mockframe) lib.checkStream(mockframe) self.assertEqual(mockframe.status.get(), "green") self.assertEqual(mockframe.streamActive, False) self.assertEqual(mockframe.lbl_StreamSpeed["text"], "-/-") # undo monkeypatch lib.onUpdate = oldOnUpdate lib.docker.from_env = oldClient
def test_setStream(self): mockframe = testlib.mockFrame() lib.createStatusWidget(mockframe) lib.setStream(mockframe, "green", "1234") self.assertEqual(mockframe.status.get(), "green") self.assertEqual(mockframe.streamSpeed.get(), "1234")