diff --git a/bin/tests/system/isctest/__init__.py b/bin/tests/system/isctest/__init__.py index afeb55bf79..5426e450fe 100644 --- a/bin/tests/system/isctest/__init__.py +++ b/bin/tests/system/isctest/__init__.py @@ -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 index 0000000000..0bb73f3bab --- /dev/null +++ b/bin/tests/system/isctest/hypothesis/__init__.py @@ -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 index 0000000000..5eae01063b --- /dev/null +++ b/bin/tests/system/isctest/hypothesis/settings.py @@ -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")) diff --git a/bin/tests/system/wildcard/strategies.py b/bin/tests/system/isctest/hypothesis/strategies.py similarity index 92% rename from bin/tests/system/wildcard/strategies.py rename to bin/tests/system/isctest/hypothesis/strategies.py index 2de911d5f6..1e05cc1932 100644 --- a/bin/tests/system/wildcard/strategies.py +++ b/bin/tests/system/isctest/hypothesis/strategies.py @@ -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. diff --git a/bin/tests/system/wildcard/tests_wildcard.py b/bin/tests/system/wildcard/tests_wildcard.py index f304f966b3..cc5c1571a2 100755 --- a/bin/tests/system/wildcard/tests_wildcard.py +++ b/bin/tests/system/wildcard/tests_wildcard.py @@ -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(