"""Tests for the subltitles script.""" import unittest import prog class TestScript(unittest.TestCase): """Test all the elements in the script.""" def test_convert_time_to_total_seconds(self): """Take hours, minutes, seconds, Return total seconds.""" seconds = prog.convert_time_to_total_seconds(1, 43, 33) self.assertEqual(seconds, 6213) seconds = prog.convert_time_to_total_seconds(2, 0, 0) self.assertEqual(seconds, 7200) seconds = prog.convert_time_to_total_seconds(2, 59, 59) self.assertEqual(seconds, 10799) def test_convert_time_to_h_m_s(self): """Take total seconds, Return hours, minutes, seconds.""" hours, minutes, seconds = prog.convert_time_to_h_m_s(6213) self.assertEqual((hours, minutes, seconds), (1, 43, 33)) hours, minutes, seconds = prog.convert_time_to_h_m_s(7200) self.assertEqual((hours, minutes, seconds), (2, 0, 0)) hours, minutes, seconds = prog.convert_time_to_h_m_s(10799) self.assertEqual((hours, minutes, seconds), (2, 59, 59)) def test_offset(self): """Combine the conversions with an offset in between.""" offset: int = -18 hours: int = 0 minutes: int = 0 seconds: int = 36 temp_seconds: int = prog.convert_time_to_total_seconds( hours, minutes, seconds ) temp_seconds += offset new_hours, new_minutes, new_seconds = prog.convert_time_to_h_m_s( temp_seconds ) self.assertEqual((new_hours, new_minutes, new_seconds), (0, 0, 18)) offset: int = -20 hours: int = 0 minutes: int = 4 seconds: int = 5 temp_seconds: int = prog.convert_time_to_total_seconds( hours, minutes, seconds ) temp_seconds += offset new_hours, new_minutes, new_seconds = prog.convert_time_to_h_m_s( temp_seconds ) self.assertEqual((new_hours, new_minutes, new_seconds), (0, 3, 45)) offset: int = 73 hours: int = 2 minutes: int = 52 seconds: int = 50 temp_seconds: int = prog.convert_time_to_total_seconds( hours, minutes, seconds ) temp_seconds += offset new_hours, new_minutes, new_seconds = prog.convert_time_to_h_m_s( temp_seconds ) self.assertEqual((new_hours, new_minutes, new_seconds), (2, 54, 3)) offset: int = 73 hours: int = 2 minutes: int = 59 seconds: int = 49 temp_seconds: int = prog.convert_time_to_total_seconds( hours, minutes, seconds ) temp_seconds += offset new_hours, new_minutes, new_seconds = prog.convert_time_to_h_m_s( temp_seconds ) self.assertEqual((new_hours, new_minutes, new_seconds), (3, 1, 2)) def test_get_timeline(self): """Correct string is outputted""" original_timeline: str = "00:04:05,080" new_timeline: str = prog.get_new_timeline(original_timeline, -18) self.assertNotEqual(original_timeline, new_timeline) self.assertEqual(new_timeline, "00:03:47,080") original_timeline: str = "00:04:06,373" new_timeline: str = prog.get_new_timeline(original_timeline, -29) self.assertNotEqual(original_timeline, new_timeline) self.assertEqual(new_timeline, "00:03:37,373") if __name__ == '__main__': unittest.main()