Exemple #1
0
    def test_coerce_accepts_bytes_bytearray_array(self):
        t = xso.HexBinary()

        import array
        array_value = array.array("h")
        array_value.append(1234)
        array_value.append(5678)
        array_value.append(910)

        values = [
            b"foobar",
            bytearray(b"baz"),
        ]

        for value in values:
            result = t.coerce(value)
            self.assertEqual(bytes(value), result)
            self.assertIsInstance(result, bytes)
Exemple #2
0
    def test_coerce_passes_bytes(self):
        t = xso.HexBinary()

        value = b"foo"

        self.assertIs(value, t.coerce(value))
Exemple #3
0
 def test_coerce_rejects_int(self):
     t = xso.HexBinary()
     with self.assertRaisesRegex(TypeError, "must be convertible to bytes"):
         t.coerce(12)
Exemple #4
0
 def test_format(self):
     t = xso.HexBinary()
     self.assertEqual("666e6f7264", t.format(b"fnord"))
Exemple #5
0
 def test_parse(self):
     t = xso.HexBinary()
     self.assertEqual(b"fnord", t.parse("666e6f7264"))
Exemple #6
0
 def test_is_abstract_type(self):
     self.assertIsInstance(xso.HexBinary(), xso.AbstractType)