From bf52fd5787e2d7899389a4c942b8e379253823664eb11936f94f9cf20abaec3a Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sat, 30 Nov 2024 21:24:02 +0300 Subject: [PATCH] More symmetric tests --- pyac/tests/test_int.py | 6 ++++++ pyac/tests/test_str.py | 12 ++++++++++++ pyac/tests/test_uuid.py | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/pyac/tests/test_int.py b/pyac/tests/test_int.py index 93f047d..8aa6583 100644 --- a/pyac/tests/test_int.py +++ b/pyac/tests/test_int.py @@ -1,6 +1,7 @@ from unittest import TestCase from hypothesis import given +from hypothesis.strategies import integers from pyac import DecodeError from pyac import dumps @@ -99,3 +100,8 @@ class TestInt(TestCase): encoded: bytes = b"\x0c\x01\x7b" loads(encoded) self.assertEqual(str(err.exception), "non-BIN in INT") + + @given(integers()) + def test_symmetric(self, i: int) -> None: + decoded, _ = loads(dumps(i)) + self.assertEqual(decoded, i) diff --git a/pyac/tests/test_str.py b/pyac/tests/test_str.py index 37504d7..25d6287 100644 --- a/pyac/tests/test_str.py +++ b/pyac/tests/test_str.py @@ -1,6 +1,7 @@ from unittest import TestCase from hypothesis import given +from hypothesis.strategies import binary from hypothesis.strategies import integers from pyac import DecodeError @@ -8,6 +9,7 @@ from pyac import dumps from pyac import loads from pyac import NotEnoughData from tests.strategies import junk_st +from tests.strategies import unicode_allowed TagStr: int = 0x80 @@ -110,6 +112,11 @@ class TestStr(TestCase): loads(encoded) self.assertEqual(err.exception.n, 3) + @given(unicode_allowed) + def test_symmetric(self, s: str): + decoded, _ = loads(dumps(s)) + self.assertEqual(decoded, s) + class TestBin(TestCase): @given(junk_st) @@ -167,3 +174,8 @@ class TestBin(TestCase): with self.assertRaises(NotEnoughData) as err: loads(encoded) self.assertEqual(err.exception.n, 3) + + @given(binary()) + def test_symmetric(self, s: bytes): + decoded, _ = loads(dumps(s)) + self.assertEqual(decoded, s) diff --git a/pyac/tests/test_uuid.py b/pyac/tests/test_uuid.py index 0673a12..7722d95 100644 --- a/pyac/tests/test_uuid.py +++ b/pyac/tests/test_uuid.py @@ -2,6 +2,7 @@ from unittest import TestCase from uuid import UUID from hypothesis import given +from hypothesis.strategies import uuids from pyac import dumps from pyac import loads @@ -33,3 +34,8 @@ class TestUUID(TestCase): with self.assertRaises(NotEnoughData) as err: loads(encoded[:-4]) self.assertEqual(err.exception.n, 1+16) + + @given(uuids()) + def test_symmetric(self, u: UUID) -> None: + decoded, _ = loads(dumps(u)) + self.assertEqual(decoded, u) -- 2.50.0