]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Move hypothesis strategies to isctest for later reuse
authorŠtěpán Balážik <stepan@isc.org>
Tue, 23 Apr 2024 14:45:45 +0000 (16:45 +0200)
committerPetr Špaček <pspacek@isc.org>
Tue, 28 May 2024 12:12:16 +0000 (12:12 +0000)
`isctest.hypothesis` seems to be a nice place to have these.

bin/tests/system/isctest/__init__.py
bin/tests/system/isctest/hypothesis/__init__.py [new file with mode: 0644]
bin/tests/system/isctest/hypothesis/settings.py [new file with mode: 0644]
bin/tests/system/isctest/hypothesis/strategies.py [moved from bin/tests/system/wildcard/strategies.py with 92% similarity]
bin/tests/system/wildcard/tests_wildcard.py

index afeb55bf79172ea947be584f3a7b6bb99b8ced9f..5426e450feaca3c3dc929f97272e4431c53208d1 100644 (file)
@@ -17,6 +17,7 @@ from . import rndc
 from . import run
 from . import log
 from . import vars  # pylint: disable=redefined-builtin
+from . import hypothesis
 
 # isctest.mark module is intentionally NOT imported, because it relies on
 # environment variables which might not be set at the time of import of the
diff --git a/bin/tests/system/isctest/hypothesis/__init__.py b/bin/tests/system/isctest/hypothesis/__init__.py
new file mode 100644 (file)
index 0000000..0bb73f3
--- /dev/null
@@ -0,0 +1,13 @@
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0.  If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+from . import settings
+from . import strategies
diff --git a/bin/tests/system/isctest/hypothesis/settings.py b/bin/tests/system/isctest/hypothesis/settings.py
new file mode 100644 (file)
index 0000000..5eae010
--- /dev/null
@@ -0,0 +1,18 @@
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0.  If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+import os
+
+from hypothesis import settings
+
+# Timing of hypothesis tests is flaky in the CI, so we disable deadlines.
+settings.register_profile("ci", deadline=None)
+settings.load_profile(os.getenv("HYPOTHESIS_PROFILE", "default"))
similarity index 92%
rename from bin/tests/system/wildcard/strategies.py
rename to bin/tests/system/isctest/hypothesis/strategies.py
index 2de911d5f6089d2b9a3719e346e825461375d6be..1e05cc1932bab2357ad30bd4157e6cfcaf63529e 100644 (file)
@@ -29,8 +29,6 @@ import dns.message
 import dns.rdataclass
 import dns.rdatatype
 
-# LATER: Move this file so it can be easily reused.
-
 
 @composite
 def dns_names(
@@ -131,9 +129,14 @@ def dns_names(
 
 
 RDATACLASS_MAX = RDATATYPE_MAX = 65535
-dns_rdataclasses = builds(dns.rdataclass.RdataClass, integers(0, RDATACLASS_MAX))
+try:
+    dns_rdataclasses = builds(dns.rdataclass.RdataClass, integers(0, RDATACLASS_MAX))
+    dns_rdatatypes = builds(dns.rdatatype.RdataType, integers(0, RDATATYPE_MAX))
+except AttributeError:
+    # In old dnspython versions, RDataTypes and RDataClasses are int and not enums.
+    dns_rdataclasses = integers(0, RDATACLASS_MAX)  # type: ignore
+    dns_rdatatypes = integers(0, RDATATYPE_MAX)  # type: ignore
 dns_rdataclasses_without_meta = dns_rdataclasses.filter(dns.rdataclass.is_metaclass)
-dns_rdatatypes = builds(dns.rdatatype.RdataType, integers(0, RDATATYPE_MAX))
 
 # NOTE: This should really be `dns_rdatatypes_without_meta = dns_rdatatypes_without_meta.filter(dns.rdatatype.is_metatype()`,
 #       but hypothesis then complains about the filter being too strict, so it is done in a “constructive” way.
index f304f966b31a8cc96356c5a5a5f7d206083cd047..cc5c1571a2e754a09b044a0b189a7fa8c095d7f4 100755 (executable)
@@ -28,7 +28,6 @@ Limitations - untested properties:
     - special behavior of rdtypes like CNAME
 """
 
-import os
 import pytest
 
 pytest.importorskip("dns", minversion="2.0.0")
@@ -48,9 +47,9 @@ try:
     pytest.importorskip("hypothesis")
 except ValueError:
     pytest.importorskip("hypothesis", minversion="4.41.2")
-from hypothesis import assume, example, given, settings
+from hypothesis import assume, example, given
 
-from strategies import dns_names, dns_rdatatypes_without_meta
+from isctest.hypothesis.strategies import dns_names, dns_rdatatypes_without_meta
 import isctest.check
 import isctest.name
 import isctest.query
@@ -63,10 +62,6 @@ WILDCARD_RDATA = "192.0.2.1"
 IP_ADDR = "10.53.0.1"
 TIMEOUT = 5  # seconds, just a sanity check
 
-# Timing of hypothesis tests is flaky in the CI, so we disable deadlines.
-settings.register_profile("ci", deadline=None)
-settings.load_profile(os.getenv("HYPOTHESIS_PROFILE", "default"))
-
 
 @given(name=dns_names(suffix=SUFFIX), rdtype=dns_rdatatypes_without_meta)
 def test_wildcard_rdtype_mismatch(