def test_nan_floats(nonan_type: FormatField, construct_type: FormatField) -> None: """Check that error is raised if you try to build or parse nan floats.""" nan = float("nan") # noqa: WPS456 with pytest.raises(FormatFieldError): nonan_type.build(nan) nan_serialized = construct_type.build(nan) with pytest.raises(FormatFieldError): nonan_type.parse(nan_serialized)
class TestFormatField(unittest.TestCase): def setUp(self): self.ff = FormatField("formatfield", "<", "L") def test_trivial(self): pass def test_parse(self): self.assertEqual(self.ff.parse("\x12\x34\x56\x78"), 0x78563412) def test_build(self): self.assertEqual(self.ff.build(0x78563412), "\x12\x34\x56\x78") def test_parse_too_short(self): self.assertRaises(FieldError, self.ff.parse, "\x12\x34\x56") def test_build_too_long(self): self.assertRaises(FieldError, self.ff.build, 9e9999) def test_sizeof(self): self.assertEqual(self.ff.sizeof(), 4)
class TestFormatField(unittest.TestCase): def setUp(self): self.ff = FormatField("formatfield", "<", "L") def test_trivial(self): pass def test_parse(self): self.assertEqual(self.ff.parse(b"\x12\x34\x56\x78"), 0x78563412) def test_build(self): self.assertEqual(self.ff.build(0x78563412), b"\x12\x34\x56\x78") def test_parse_too_short(self): self.assertRaises(FieldError, self.ff.parse, b"\x12\x34\x56") def test_build_too_long(self): self.assertRaises(FieldError, self.ff.build, 9e9999) def test_sizeof(self): self.assertEqual(self.ff.sizeof(), 4)