]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Rework imports in dnspython-based system tests
authorMichał Kępień <michal@isc.org>
Mon, 14 Mar 2022 07:59:32 +0000 (08:59 +0100)
committerMichał Kępień <michal@isc.org>
Mon, 14 Mar 2022 08:19:03 +0000 (09:19 +0100)
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 49312d6bb2e4d4c7fe513e6832f0521394bb37f6)

bin/tests/system/checkds/tests-checkds.py
bin/tests/system/shutdown/tests-shutdown.py
bin/tests/system/timeouts/tests-tcp.py
bin/tests/system/wildcard/tests-wildcard.py

index afd77faa08520f284d2818cce9105847bf3e0930..a463b72b5733b5a2f94f0e4794c0f956e8a770a8 100755 (executable)
@@ -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):
index dd6b62348fb58aabaf07cc555cabea25a0caf6be..56077391008983c8949805392e320a6861970cac 100755 (executable)
@@ -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):
index a17380af586ae0ba2d6e9f6864b8c30b6434625b..e883dddda40c0266e387362c7c165ff84a98b227 100644 (file)
@@ -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))
 
index 3c724b1335f5c48b99ed962a2f9d3a2d39547727..f4134225e1223e66a9ab4f881f12ee0de73aacb9 100755 (executable)
@@ -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