2
0
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:
Štěpán Balážik
2024-04-23 16:45:45 +02:00
committed by Petr Špaček
parent f55cacbbfd
commit bb1e5cfa09
5 changed files with 41 additions and 11 deletions

View 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

View 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

View 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"))

View 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.

View File

@@ -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(