diff --git a/bin/tests/system/isctest/check.py b/bin/tests/system/isctest/check.py index 28eb16d5dd..251e87e4f3 100644 --- a/bin/tests/system/isctest/check.py +++ b/bin/tests/system/isctest/check.py @@ -10,23 +10,14 @@ # information regarding copyright ownership. import shutil -from typing import Any, Optional +from typing import Optional import dns.rcode import dns.message import dns.zone import isctest.log - -# compatiblity with dnspython<2.0.0 -try: - # In dnspython>=2.0.0, dns.rcode.Rcode class is available - # pylint: disable=invalid-name - dns_rcode = dns.rcode.Rcode # type: Any -except AttributeError: - # In dnspython<2.0.0, selected rcodes are available as integers directly - # from dns.rcode - dns_rcode = dns.rcode +from isctest.compat import dns_rcode def rcode(message: dns.message.Message, expected_rcode) -> None: diff --git a/bin/tests/system/isctest/compat.py b/bin/tests/system/isctest/compat.py new file mode 100644 index 0000000000..5580f1f4c5 --- /dev/null +++ b/bin/tests/system/isctest/compat.py @@ -0,0 +1,24 @@ +# 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 typing import Any + +import dns.rcode + +# compatiblity with dnspython<2.0.0 +try: + # In dnspython>=2.0.0, dns.rcode.Rcode class is available + # pylint: disable=invalid-name + dns_rcode = dns.rcode.Rcode # type: Any +except AttributeError: + # In dnspython<2.0.0, selected rcodes are available as integers directly + # from dns.rcode + dns_rcode = dns.rcode diff --git a/bin/tests/system/isctest/query.py b/bin/tests/system/isctest/query.py index c001e063d1..3e5ed8b78b 100644 --- a/bin/tests/system/isctest/query.py +++ b/bin/tests/system/isctest/query.py @@ -17,16 +17,7 @@ import dns.query import dns.message import isctest.log - -# compatiblity with dnspython<2.0.0 -try: - # In dnspython>=2.0.0, dns.rcode.Rcode class is available - # pylint: disable=invalid-name - dns_rcode = dns.rcode.Rcode # type: Any -except AttributeError: - # In dnspython<2.0.0, selected rcodes are available as integers directly - # from dns.rcode - dns_rcode = dns.rcode +from isctest.compat import dns_rcode QUERY_TIMEOUT = 10 diff --git a/bin/tests/system/isctest/run.py b/bin/tests/system/isctest/run.py index 60703749ce..b3cb8200c0 100644 --- a/bin/tests/system/isctest/run.py +++ b/bin/tests/system/isctest/run.py @@ -12,24 +12,14 @@ import os import subprocess import time -from typing import Any, Optional +from typing import Optional import isctest.log +from isctest.compat import dns_rcode import dns.message -# compatiblity with dnspython<2.0.0 -try: - # In dnspython>=2.0.0, dns.rcode.Rcode class is available - # pylint: disable=invalid-name - dns_rcode = dns.rcode.Rcode # type: Any -except AttributeError: - # In dnspython<2.0.0, selected rcodes are available as integers directly - # from dns.rcode - dns_rcode = dns.rcode - - def cmd( # pylint: disable=too-many-arguments args, cwd=None, diff --git a/bin/tests/system/rpzextra/tests_rpzextra.py b/bin/tests/system/rpzextra/tests_rpzextra.py index 5c2740ad63..bf2fe94c6b 100644 --- a/bin/tests/system/rpzextra/tests_rpzextra.py +++ b/bin/tests/system/rpzextra/tests_rpzextra.py @@ -16,21 +16,11 @@ import pytest pytest.importorskip("dns", minversion="2.0.0") import isctest +from isctest.compat import dns_rcode import dns.message -# compatiblity with dnspython<2.0.0 -try: - # In dnspython>=2.0.0, dns.rcode.Rcode class is available - # pylint: disable=invalid-name - dns_rcode = dns.rcode.Rcode # type: Any -except AttributeError: - # In dnspython<2.0.0, selected rcodes are available as integers directly - # from dns.rcode - dns_rcode = dns.rcode - - @pytest.mark.parametrize( "qname,source,rcode", [