mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 22:15:20 +00:00
Move hypothesis strategies to isctest for later reuse
`isctest.hypothesis` seems to be a nice place to have these.
This commit is contained in:
committed by
Petr Špaček
parent
f55cacbbfd
commit
bb1e5cfa09
@@ -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
|
||||
|
13
bin/tests/system/isctest/hypothesis/__init__.py
Normal file
13
bin/tests/system/isctest/hypothesis/__init__.py
Normal file
@@ -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
|
18
bin/tests/system/isctest/hypothesis/settings.py
Normal file
18
bin/tests/system/isctest/hypothesis/settings.py
Normal file
@@ -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"))
|
@@ -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.
|
@@ -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(
|
||||
|
Reference in New Issue
Block a user