from pyac import Blob
+junk_st = binary(max_size=20)
blobs_st = tuples(integers(1, 20), binary(max_size=60)).map(lambda x: Blob(*x))
unicode_allowed = characters(exclude_characters="\x00", exclude_categories=("Cs",))
text_st = text(alphabet=unicode_allowed, max_size=32)
from unittest import TestCase
from hypothesis import given
-from hypothesis.strategies import binary
from pyac import Blob
from pyac import DecodeError
from pyac import dumps
from pyac import loads
from pyac import NotEnoughData
+from tests.strategies import junk_st
class TestBlob(TestCase):
encoded, b"\x0b\x00\x00\x00\x00\x00\x00\x00\x03\x01test\x01data\x80"
)
- @given(binary(max_size=20))
+ @given(junk_st)
def test_blob_decode(self, junk: bytes) -> None:
encoded = b"\x0B\x00\x00\x00\x00\x00\x00\x00\x03\x01test\x01data\x80" + junk
decoded, remaining = loads(encoded)
from unittest import TestCase
from hypothesis import given
-from hypothesis.strategies import binary
from pyac import dumps
from pyac import loads
+from tests.strategies import junk_st
class TestBool(TestCase):
encoded = dumps(False)
self.assertEqual(encoded, b"\x02")
- @given(binary(max_size=20))
+ @given(junk_st)
def test_bool_decode_true(self, junk):
encoded = b"\x03" + junk
decoded, remaining = loads(encoded)
self.assertIs(decoded, True)
self.assertEqual(remaining, junk)
- @given(binary(max_size=20))
+ @given(junk_st)
def test_bool_decode_false(self, junk):
encoded = b"\x02" + junk
decoded, remaining = loads(encoded)
from unittest import TestCase
from hypothesis import given
-from hypothesis.strategies import binary
from hypothesis.strategies import lists
from pyac import dumps
from pyac import loads
from pyac import NotEnoughData
from tests.strategies import any_st
+from tests.strategies import junk_st
class TestList(TestCase):
self.assertEqual(decoded, [])
self.assertEqual(remaining, b"")
- @given(lists(any_st, max_size=4), binary(max_size=20))
+ @given(lists(any_st, max_size=4), junk_st)
def test_list_decode_non_empty(self, test_list: List, junk: bytes) -> None:
encoded = b"\x08" + b"".join(dumps(i) for i in test_list) + b"\x00" + junk
decoded, remaining = loads(encoded)
from unittest import TestCase
from hypothesis import given
-from hypothesis.strategies import binary
from hypothesis.strategies import dictionaries
from hypothesis.strategies import lists
from pyac import dumps
from pyac import loads
from tests.strategies import any_st
+from tests.strategies import junk_st
from tests.strategies import mapkey_st
)
self.assertEqual(encoded, expected)
- @given(dictionaries(keys=mapkey_st, values=any_st, max_size=4), binary(max_size=20))
+ @given(dictionaries(keys=mapkey_st, values=any_st, max_size=4), junk_st)
def test_map_decode(self, test_map, junk):
encoded = (
b"\x09" +
self.assertEqual(decoded, test_map)
self.assertEqual(remaining, junk)
- @given(binary(max_size=20))
+ @given(junk_st)
def test_map_empty(self, junk):
test_map = {}
encoded = dumps(test_map) + junk
self.assertEqual(decoded, test_map)
self.assertEqual(remaining, junk)
- @given(lists(mapkey_st, max_size=4), binary(max_size=20))
+ @given(lists(mapkey_st, max_size=4), junk_st)
def test_decode_to_set(self, keys, junk):
test_map = {key: None for key in keys}
encoded = dumps(test_map) + junk
from unittest import TestCase
from hypothesis import given
-from hypothesis.strategies import binary
from hypothesis.strategies import deferred
from hypothesis.strategies import dictionaries
from hypothesis.strategies import lists
from pyac import dumps
from pyac import loads
from tests.strategies import any_st
+from tests.strategies import junk_st
from tests.strategies import mapkey_st
class TestSymmetric(TestCase):
- @given(everything_st, binary(max_size=20))
+ @given(everything_st, junk_st)
def test_symmetric(self, obj: Any, junk: bytes) -> None:
encoded: bytes = dumps(obj) + junk
decoded: Any
from unittest import TestCase
from hypothesis import given
-from hypothesis.strategies import binary
from pyac import DecodeError
from pyac import dumps
from pyac import NotEnoughData
from pyac import Raw
from pyac import TAI64Base
+from tests.strategies import junk_st
+
TagTAI64 = 0x18
TagTAI64N = 0x19
class TestTAI64(TestCase):
- @given(binary(max_size=20))
+ @given(junk_st)
def test_encode_decode_tai64(self, junk: bytes) -> None:
dt = datetime(2023, 10, 1, 12, 0, 0)
encoded = dumps(dt)
self.assertEqual(dt, decoded)
self.assertEqual(remaining, junk)
- @given(binary(max_size=20))
+ @given(junk_st)
def test_encode_decode_tai64n(self, junk: bytes) -> None:
dt = datetime(2023, 10, 1, 12, 0, 0, 123456)
encoded = dumps(dt) + junk
self.assertEqual(dt, decoded)
self.assertEqual(remaining, junk)
- @given(binary(max_size=20))
+ @given(junk_st)
def test_decode_tai64na(self, junk: bytes) -> None:
encoded = (
b"\x1A\x40\x00\x00\x00\x65\x19\x5f\x65\x07\x5b\xca\x00\x07\x5b\xca\x00" +