mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-28 04:34:54 -04:00
Rework imports in dnspython-based system tests
Ensure all "import dns.*" statements are always placed after
pytest.importorskip('dns') calls, in order to allow the latter to
fulfill their purpose. Explicitly import all dnspython modules used by
each dnspython-based test to avoid relying on nested imports. Replace
function-scoped imports with global imports to reduce code duplication.
(cherry picked from commit 49312d6bb2)
This commit is contained in:
parent
238781de4a
commit
ac229a2fd5
6 changed files with 22 additions and 31 deletions
|
|
@ -17,10 +17,17 @@ import subprocess
|
|||
import sys
|
||||
import time
|
||||
|
||||
import dns.resolver
|
||||
import pytest
|
||||
|
||||
pytest.importorskip('dns', minversion='2.0.0')
|
||||
import dns.exception
|
||||
import dns.message
|
||||
import dns.name
|
||||
import dns.query
|
||||
import dns.rcode
|
||||
import dns.rdataclass
|
||||
import dns.rdatatype
|
||||
import dns.resolver
|
||||
|
||||
|
||||
def has_signed_apex_nsec(zone, response):
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ import pytest
|
|||
pytest.importorskip('dns')
|
||||
import dns.exception
|
||||
import dns.message
|
||||
import dns.name
|
||||
import dns.rdataclass
|
||||
import dns.rdatatype
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,10 +19,11 @@ import subprocess
|
|||
from string import ascii_lowercase as letters
|
||||
import time
|
||||
|
||||
import dns.resolver
|
||||
import pytest
|
||||
|
||||
pytest.importorskip('dns')
|
||||
import dns.exception
|
||||
import dns.resolver
|
||||
|
||||
|
||||
def do_work(named_proc, resolver, rndc_cmd, kill_method, n_workers, n_queries):
|
||||
|
|
|
|||
|
|
@ -20,13 +20,14 @@ import time
|
|||
import pytest
|
||||
|
||||
pytest.importorskip('dns', minversion='2.0.0')
|
||||
import dns.message
|
||||
import dns.query
|
||||
|
||||
|
||||
TIMEOUT = 10
|
||||
|
||||
|
||||
def create_msg(qname, qtype):
|
||||
import dns.message
|
||||
msg = dns.message.make_query(qname, qtype, want_dnssec=True,
|
||||
use_edns=0, payload=4096)
|
||||
return msg
|
||||
|
|
@ -43,8 +44,6 @@ def create_socket(host, port):
|
|||
|
||||
|
||||
def test_tcp_garbage(named_port):
|
||||
import dns.query
|
||||
|
||||
with create_socket("10.53.0.7", named_port) as sock:
|
||||
|
||||
msg = create_msg("a.example.", "A")
|
||||
|
|
@ -68,9 +67,6 @@ def test_tcp_garbage(named_port):
|
|||
|
||||
|
||||
def test_tcp_garbage_response(named_port):
|
||||
import dns.query
|
||||
import dns.message
|
||||
|
||||
with create_socket("10.53.0.7", named_port) as sock:
|
||||
|
||||
msg = create_msg("a.example.", "A")
|
||||
|
|
|
|||
|
|
@ -19,13 +19,18 @@ import time
|
|||
import pytest
|
||||
|
||||
pytest.importorskip('dns', minversion='2.0.0')
|
||||
import dns.edns
|
||||
import dns.message
|
||||
import dns.name
|
||||
import dns.query
|
||||
import dns.rdataclass
|
||||
import dns.rdatatype
|
||||
|
||||
|
||||
TIMEOUT = 10
|
||||
|
||||
|
||||
def create_msg(qname, qtype):
|
||||
import dns.message
|
||||
msg = dns.message.make_query(qname, qtype, want_dnssec=True,
|
||||
use_edns=0, payload=4096)
|
||||
return msg
|
||||
|
|
@ -39,8 +44,6 @@ def test_initial_timeout(named_port):
|
|||
#
|
||||
# The initial timeout is 2.5 seconds, so this should timeout
|
||||
#
|
||||
import dns.query
|
||||
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(("10.53.0.1", named_port))
|
||||
|
||||
|
|
@ -60,8 +63,6 @@ def test_idle_timeout(named_port):
|
|||
#
|
||||
# The idle timeout is 5 seconds, so the third message should fail
|
||||
#
|
||||
import dns.rcode
|
||||
|
||||
msg = create_msg("example.", "A")
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(("10.53.0.1", named_port))
|
||||
|
|
@ -90,8 +91,6 @@ def test_keepalive_timeout(named_port):
|
|||
#
|
||||
# Keepalive is 7 seconds, so the third message should succeed.
|
||||
#
|
||||
import dns.rcode
|
||||
|
||||
msg = create_msg("example.", "A")
|
||||
kopt = dns.edns.GenericOption(11, b'\x00')
|
||||
msg.use_edns(edns=True, payload=4096, options=[kopt])
|
||||
|
|
@ -119,8 +118,6 @@ def test_pipelining_timeout(named_port):
|
|||
#
|
||||
# The pipelining should only timeout after the last message is received
|
||||
#
|
||||
import dns.query
|
||||
|
||||
msg = create_msg("example.", "A")
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(("10.53.0.1", named_port))
|
||||
|
|
@ -156,10 +153,6 @@ def test_long_axfr(named_port):
|
|||
# The timers should not fire during AXFR, thus the connection should not
|
||||
# close abruptly
|
||||
#
|
||||
import dns.query
|
||||
import dns.rdataclass
|
||||
import dns.rdatatype
|
||||
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(("10.53.0.1", named_port))
|
||||
|
||||
|
|
@ -186,8 +179,6 @@ def test_long_axfr(named_port):
|
|||
|
||||
|
||||
def test_send_timeout(named_port):
|
||||
import dns.query
|
||||
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(("10.53.0.1", named_port))
|
||||
|
||||
|
|
@ -215,10 +206,6 @@ def test_send_timeout(named_port):
|
|||
|
||||
@pytest.mark.long
|
||||
def test_max_transfer_idle_out(named_port):
|
||||
import dns.query
|
||||
import dns.rdataclass
|
||||
import dns.rdatatype
|
||||
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(("10.53.0.1", named_port))
|
||||
|
||||
|
|
@ -250,10 +237,6 @@ def test_max_transfer_idle_out(named_port):
|
|||
|
||||
@pytest.mark.long
|
||||
def test_max_transfer_time_out(named_port):
|
||||
import dns.query
|
||||
import dns.rdataclass
|
||||
import dns.rdatatype
|
||||
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(("10.53.0.1", named_port))
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,9 @@ import dns.message
|
|||
import dns.name
|
||||
import dns.query
|
||||
import dns.rcode
|
||||
import dns.rdataclass
|
||||
import dns.rdatatype
|
||||
import dns.rrset
|
||||
|
||||
pytest.importorskip("hypothesis")
|
||||
from hypothesis import given
|
||||
|
|
|
|||
Loading…
Reference in a new issue