Example #1
0
    def test_synchsafe_then_unsynchsafe_zero(self):
        size = 0

        encoded = synchsafe(size)
        decoded = unsynchsafe(encoded)

        self.assertEqual(decoded, size)
Example #2
0
    def test_synchsafe_then_unsynchsafe_high(self):
        size = 42949672

        encoded = synchsafe(size)
        decoded = unsynchsafe(encoded)

        self.assertEqual(decoded, size)
Example #3
0
    def test_synchsafe_then_unsynchsafe_low(self):
        size = 2 ** 6

        encoded = synchsafe(size)
        decoded = unsynchsafe(encoded)

        self.assertEqual(decoded, size)
Example #4
0
    def test_deserializes(self):
        """Deserializes from bytes"""
        # Arrange
        f = TagHeader.Flags  # for brevity's sake
        byte_string = b'ID3\x03\x01\x60\x00\x00\x0A\x0A'

        flags = f.Experimental | f.Extended
        major = 3
        minor = 1
        expected_tag_size = unsynchsafe(0x0A0A)

        # System under test / Act
        header = TagHeader.read(BytesIO(byte_string))

        # Assert
        self.assertEqual(len(header), 10)
        self.assertEqual(header.tag_size, expected_tag_size)
        self.assertEqual(header.major, major)
        self.assertEqual(header.minor, minor)
        self.assertEqual(header.flags, flags)
        self.assertEqual(bytes(header), byte_string)
Example #5
0
 def read(self, stream, context) -> int:
     return unsynchsafe(super().read(stream, context))
Example #6
0
    def test_unsynchsafe_small_int(self):
        size = 0b01111111

        self.assertEqual(unsynchsafe(size), size)
Example #7
0
 def test_unsynchsafe_highest_possible_int(self):
     self.assertEqual(unsynchsafe(0x7f7f7f7f), 2 ** 28 - 1)
Example #8
0
    def test_unsynchsafe_example_from_specification(self):
        size = 0x0201
        expected = 257

        self.assertEqual(unsynchsafe(size), expected)