コード例 #1
0
ファイル: test_core.py プロジェクト: near/borsh-py
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)
コード例 #2
0
ファイル: test_core.py プロジェクト: MacLeek/mh
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)
コード例 #3
0
ファイル: test_core.py プロジェクト: andyhelp/construct
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)