from typing import Any
from typing import Mapping
+from typing import Set
from unittest import TestCase
from hypothesis import given
self.assertEqual(decoded, test_map)
self.assertSequenceEqual(tail, junk)
- @given(sets(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
- decoded, tail = loads(encoded, sets=True)
- self.assertSetEqual(decoded, keys)
- self.assertSequenceEqual(tail, junk)
-
def test_throws_when_decoding_unsorted_value_keys(self):
encoded = b"".join((
bytes.fromhex("09"),
with self.assertRaises(DecodeError) as err:
decoded, tail = loads(encoded)
self.assertEqual(str(err.exception), "empty key")
+
+
+class TestSet(TestCase):
+ @given(sets(mapkey_st, max_size=4), junk_st)
+ def test_symmetric(self, values: Set[str], junk: bytes) -> None:
+ test_map = {key: None for key in values}
+ encoded = dumps(test_map)
+ decoded, tail = loads(encoded + junk, sets=True)
+ self.assertSetEqual(decoded, values)
+ self.assertSequenceEqual(tail, junk)
+ self.assertSequenceEqual(dumps(values), encoded)
+
+ def test_non_str(self) -> None:
+ with self.assertRaises(ValueError) as err:
+ dumps(set((123,)))
+ self.assertEqual(str(err.exception), "set can contain only strings")