]> 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 07:59:32 +0000 (08:59 +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.

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

index 40611e8d05b7a6df61c10fc1c5ee1c1c9e0ac606..68b197c73e2b9edceeffee509b7c094a46aa1377 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 0e7879e04b58879c8ef0d96accf4909e664a2e4c..ea86a961b2e9020a0d994f2e62c855d404d732cb 100644 (file)
@@ -21,6 +21,8 @@ import pytest
 pytest.importorskip('dns')
 import dns.exception
 import dns.message
+import dns.name
+import dns.rdataclass
 import dns.rdatatype
 
 
index 9ed222bb1a768c59c168ad312b45a821026f8c39..b8de379d6636283ccba0f55aa122f42829ca85b5 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 7a12dc2be2d1f8da03fb627fa3116159a5c714ca..da70b1ef38b503d8ffd46d0a428ffda8b1f99541 100644 (file)
@@ -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")
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