def test_correct_length(self): length_only_seconds = "54" length_minutes = "15:54" length_hours = "8:15:54" result = parse_length(length_only_seconds) result2 = parse_length(length_minutes) result3 = parse_length(length_hours) self.assertEqual((0, 0, 54), result) self.assertEqual((0, 15, 54), result2) self.assertEqual((8, 15, 54), result3)
def test_length_with_seconds_over_a_minute_raises_error(self): length = "14:65" exc = None try: parse_length(length) except Exception as err: exc = err self.assertIsNotNone(exc) self.assertEqual(str(exc), "Incorrect seconds!")
def test_length_with_miutes_over_an_hour_with_hours_raises_error(self): length = "3:123:45" exc = None try: parse_length(length) except Exception as err: exc = err self.assertIsNotNone(exc) self.assertEqual(str(exc), "Incorrect minutes!")
def parse(self, filename): self.length = parse_length(filename, 4) self.name = str(filename.read(4), encoding='utf-8') if self.name == 'IHDR': ihdr = IHDR() ihdr.parse(filename) self.data = ihdr else: self.data = filename.read(self.length) filename.seek(-(4 + self.length), 1) name_data = filename.read(4 + self.length) calculate_crc = zlib.crc32(name_data) self.crc = parse_length(filename, 4) self.crc_pass = self.crc == calculate_crc
def parse(self, filename): self.width = parse_length(filename, 4) self.height = parse_length(filename, 4) self.bit_depth = parse_length(filename, 1) self.color_type = parse_length(filename, 1) self.compression = parse_length(filename, 1) self.filter = parse_length(filename, 1) self.interlace = parse_length(filename, 1)
def test_length_with_hours(self): length = "3:24:34" result = parse_length(length) self.assertEqual((3, 24, 34), result)
def test_length_with_miutes_over_an_hour_without_hours(self): length = "123:45" result = parse_length(length) self.assertEqual((2, 3, 45), result)