]> Cypherpunks repositories - keks.git/commitdiff
DRY: move commonly used strategies to single module
authorSergey Matveev <stargrave@stargrave.org>
Sat, 30 Nov 2024 15:57:52 +0000 (18:57 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 30 Nov 2024 19:38:56 +0000 (22:38 +0300)
pyac/tests/strategies.py [new file with mode: 0644]
pyac/tests/test_list.py
pyac/tests/test_map.py
pyac/tests/test_symmetric.py

diff --git a/pyac/tests/strategies.py b/pyac/tests/strategies.py
new file mode 100644 (file)
index 0000000..b84dd7c
--- /dev/null
@@ -0,0 +1,30 @@
+from hypothesis.strategies import binary
+from hypothesis.strategies import booleans
+from hypothesis.strategies import characters
+from hypothesis.strategies import datetimes
+from hypothesis.strategies import integers
+from hypothesis.strategies import just
+from hypothesis.strategies import none
+from hypothesis.strategies import one_of
+from hypothesis.strategies import text
+from hypothesis.strategies import tuples
+from hypothesis.strategies import uuids
+
+from pyac import Blob
+
+
+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)
+mapkey_st = text(alphabet=unicode_allowed, min_size=1, max_size=8)
+any_st = one_of(
+    booleans(),
+    integers(),
+    just(0),
+    just(-1),
+    binary(max_size=32),
+    text_st,
+    none(),
+    uuids(),
+    datetimes(),
+)
index db73033d199a4c089524fa6546a4cd7930cfd7b3a0bc76fbac739656ff1ef28c..6f3f969f493ac2eefac8652a64dbc81746e4e99d2b101ebdfa18d54e2340ee0d 100644 (file)
@@ -3,42 +3,12 @@ from unittest import TestCase
 
 from hypothesis import given
 from hypothesis.strategies import binary
-from hypothesis.strategies import booleans
-from hypothesis.strategies import characters
-from hypothesis.strategies import datetimes
-from hypothesis.strategies import integers
-from hypothesis.strategies import just
 from hypothesis.strategies import lists
-from hypothesis.strategies import none
-from hypothesis.strategies import one_of
-from hypothesis.strategies import text
-from hypothesis.strategies import tuples
-from hypothesis.strategies import uuids
 
-from pyac import Blob
 from pyac import dumps
 from pyac import loads
 from pyac import NotEnoughData
-
-
-blobs_st = tuples(integers(1, 20), binary(max_size=60)).map(lambda x: Blob(*x))
-
-text_st = text(
-    alphabet=characters(exclude_characters="\x00", exclude_categories=("Cs",)),
-    max_size=32,
-)
-
-any_st = one_of(
-    booleans(),
-    integers(),
-    just(0),
-    just(-1),
-    binary(max_size=32),
-    text_st,
-    none(),
-    uuids(),
-    datetimes(),
-)
+from tests.strategies import any_st
 
 
 class TestList(TestCase):
index c3579b932595b0e369f5757519d743976cdbd4053e8c206aac0835b7fff62b9e..0d069fff8e672e6f75bfaebff1deb7b3132580f50d253ad089ba24b6786c4138 100644 (file)
@@ -2,49 +2,14 @@ from unittest import TestCase
 
 from hypothesis import given
 from hypothesis.strategies import binary
-from hypothesis.strategies import booleans
-from hypothesis.strategies import characters
-from hypothesis.strategies import datetimes
 from hypothesis.strategies import dictionaries
-from hypothesis.strategies import integers
-from hypothesis.strategies import just
 from hypothesis.strategies import lists
-from hypothesis.strategies import none
-from hypothesis.strategies import one_of
-from hypothesis.strategies import text
-from hypothesis.strategies import tuples
-from hypothesis.strategies import uuids
 
-from pyac import Blob
-from pyac import dumps
 from pyac import DecodeError
+from pyac import dumps
 from pyac import loads
-
-
-blobs_st = tuples(integers(1, 20), binary(max_size=60)).map(lambda x: Blob(*x))
-
-text_st = text(
-    alphabet=characters(exclude_characters="\x00", exclude_categories=("Cs",)),
-    max_size=32,
-)
-
-any_st = one_of(
-    booleans(),
-    integers(),
-    just(0),
-    just(-1),
-    binary(max_size=32),
-    text_st,
-    none(),
-    uuids(),
-    datetimes(),
-)
-
-mapkey_st = text(
-    alphabet=characters(exclude_characters="\x00", exclude_categories=("Cs",)),
-    min_size=1,
-    max_size=8,
-)
+from tests.strategies import any_st
+from tests.strategies import mapkey_st
 
 
 class TestMap(TestCase):
index 9eff3fe319186ab2ae61803412704ee2b53e224d9331a41816b2325220491a8c..8468cc16a1c7d322617d4e1d64f1168571bd5104094734878fc02a3d0618d008 100644 (file)
@@ -3,58 +3,20 @@ from unittest import TestCase
 
 from hypothesis import given
 from hypothesis.strategies import binary
-from hypothesis.strategies import booleans
-from hypothesis.strategies import characters
-from hypothesis.strategies import datetimes
 from hypothesis.strategies import deferred
 from hypothesis.strategies import dictionaries
-from hypothesis.strategies import integers
-from hypothesis.strategies import just
 from hypothesis.strategies import lists
-from hypothesis.strategies import none
-from hypothesis.strategies import one_of
-from hypothesis.strategies import text
-from hypothesis.strategies import tuples
-from hypothesis.strategies import uuids
 
-from pyac import Blob
 from pyac import dumps
 from pyac import loads
+from tests.strategies import any_st
+from tests.strategies import mapkey_st
 
 
-blobs_st = tuples(integers(1, 20), binary(max_size=60)).map(lambda x: Blob(*x))
-
-text_st = text(
-    alphabet=characters(exclude_characters="\x00", exclude_categories=("Cs",)),
-    max_size=32,
-)
-
-mapkey_st = text(
-    alphabet=characters(exclude_characters="\x00", exclude_categories=("Cs",)),
-    min_size=1,
-    max_size=8,
-)
-
-any_st = one_of(
-    booleans(),
-    integers(),
-    just(0),
-    just(-1),
-    binary(max_size=32),
-    text_st,
-    none(),
-    uuids(),
-    datetimes(),
-)
-
 everything_st = deferred(
     lambda: any_st |
     lists(everything_st, max_size=4) |
-    dictionaries(
-        mapkey_st,
-        everything_st,
-        max_size=4,
-    )
+    dictionaries(mapkey_st, everything_st, max_size=4)
 )