Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dnsviz/dnsviz.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCasey Deccio <casey@deccio.net>2021-09-14 21:03:01 +0300
committerGitHub <noreply@github.com>2021-09-14 21:03:01 +0300
commit881485e6c59a1fb0d596e10996ee2d93d184ad32 (patch)
tree1d12a91d136a613312caadddd66db36c1c3c1eba
parent039c50906a7aa2e0d0763a9824280ba151947a8d (diff)
parentac9dff2aca604243170a5925b22fd3bce58b1699 (diff)
Merge pull request #87 from pemensik/pytest
Make tests work with Pytest
-rw-r--r--.travis.yml16
-rw-r--r--dnsviz/commands/graph.py6
-rw-r--r--dnsviz/commands/grok.py6
-rw-r--r--dnsviz/commands/print.py6
-rw-r--r--dnsviz/util.py10
-rw-r--r--tests/test_dnsviz_graph_options.py (renamed from tests/dnsviz_graph_options.py)0
-rw-r--r--tests/test_dnsviz_graph_run.py (renamed from tests/dnsviz_graph_run.py)0
-rw-r--r--tests/test_dnsviz_grok_options.py (renamed from tests/dnsviz_grok_options.py)0
-rw-r--r--tests/test_dnsviz_grok_run.py (renamed from tests/dnsviz_grok_run.py)0
-rw-r--r--tests/test_dnsviz_print_options.py (renamed from tests/dnsviz_print_options.py)0
-rw-r--r--tests/test_dnsviz_print_run.py (renamed from tests/dnsviz_print_run.py)0
-rw-r--r--tests/test_dnsviz_probe_options.py (renamed from tests/dnsviz_probe_options.py)0
-rw-r--r--tests/test_dnsviz_probe_run_offline.py (renamed from tests/dnsviz_probe_run_offline.py)0
-rw-r--r--tests/test_dnsviz_probe_run_online.py (renamed from tests/dnsviz_probe_run_online.py)0
14 files changed, 27 insertions, 17 deletions
diff --git a/.travis.yml b/.travis.yml
index 393fe8f..0dfb728 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,11 +18,11 @@ install:
- pip install -r requirements.txt
- pip install .
script:
- - python tests/dnsviz_probe_options.py
- - python tests/dnsviz_probe_run_offline.py
- - python tests/dnsviz_print_options.py
- - python tests/dnsviz_print_run.py
- - python tests/dnsviz_graph_options.py
- - python tests/dnsviz_graph_run.py
- - python tests/dnsviz_grok_options.py
- - python tests/dnsviz_grok_run.py
+ - python tests/test_dnsviz_probe_options.py
+ - python tests/test_dnsviz_probe_run_offline.py
+ - python tests/test_dnsviz_print_options.py
+ - python tests/test_dnsviz_print_run.py
+ - python tests/test_dnsviz_graph_options.py
+ - python tests/test_dnsviz_graph_run.py
+ - python tests/test_dnsviz_grok_options.py
+ - python tests/test_dnsviz_grok_run.py
diff --git a/dnsviz/commands/graph.py b/dnsviz/commands/graph.py
index 2719b1d..7d3fe06 100644
--- a/dnsviz/commands/graph.py
+++ b/dnsviz/commands/graph.py
@@ -44,7 +44,7 @@ import dns.exception, dns.name
from dnsviz.analysis import OfflineDomainNameAnalysis, DNS_RAW_VERSION
from dnsviz.config import DNSVIZ_SHARE_PATH, JQUERY_PATH, JQUERY_UI_PATH, JQUERY_UI_CSS_PATH, RAPHAEL_PATH
from dnsviz.format import latin1_binary_to_string as lb2s
-from dnsviz.util import get_trusted_keys, get_default_trusted_keys
+from dnsviz.util import get_trusted_keys, get_default_trusted_keys, io_try_buffered
# If the import of DNSAuthGraph fails because of the lack of pygraphviz, it
# will be reported later
@@ -154,8 +154,8 @@ class GraphArgHelper:
self.parser = argparse.ArgumentParser(description='Graph the assessment of diagnostic DNS queries', prog=prog)
# python3/python2 dual compatibility
- stdin_buffer = io.open(sys.stdin.fileno(), 'rb', closefd=False)
- stdout_buffer = io.open(sys.stdout.fileno(), 'wb', closefd=False)
+ stdin_buffer = io_try_buffered(sys.stdin, 'rb', closefd=False)
+ stdout_buffer = io_try_buffered(sys.stdout, 'wb', closefd=False)
try:
self.parser.add_argument('-f', '--names-file',
diff --git a/dnsviz/commands/grok.py b/dnsviz/commands/grok.py
index 6f2d8cd..8fc77c3 100644
--- a/dnsviz/commands/grok.py
+++ b/dnsviz/commands/grok.py
@@ -43,7 +43,7 @@ import dns.exception, dns.name
from dnsviz.analysis import OfflineDomainNameAnalysis, DNS_RAW_VERSION
from dnsviz.format import latin1_binary_to_string as lb2s
-from dnsviz.util import get_trusted_keys
+from dnsviz.util import get_trusted_keys, io_try_buffered
# If the import of DNSAuthGraph fails because of the lack of pygraphviz, it
# will be reported later
@@ -170,8 +170,8 @@ class GrokArgHelper:
self.parser = argparse.ArgumentParser(description='Assess diagnostic DNS queries', prog=prog)
# python3/python2 dual compatibility
- stdin_buffer = io.open(sys.stdin.fileno(), 'rb', closefd=False)
- stdout_buffer = io.open(sys.stdout.fileno(), 'wb', closefd=False)
+ stdin_buffer = io_try_buffered(sys.stdin, 'rb', closefd=False)
+ stdout_buffer = io_try_buffered(sys.stdout, 'wb', closefd=False)
try:
self.parser.add_argument('-f', '--names-file',
diff --git a/dnsviz/commands/print.py b/dnsviz/commands/print.py
index 3dcbb8d..80aa4a5 100644
--- a/dnsviz/commands/print.py
+++ b/dnsviz/commands/print.py
@@ -43,7 +43,7 @@ import dns.exception, dns.name
from dnsviz.analysis import TTLAgnosticOfflineDomainNameAnalysis, DNS_RAW_VERSION
from dnsviz.format import latin1_binary_to_string as lb2s
-from dnsviz.util import get_trusted_keys, get_default_trusted_keys
+from dnsviz.util import get_trusted_keys, get_default_trusted_keys, io_try_buffered
# If the import of DNSAuthGraph fails because of the lack of pygraphviz, it
# will be reported later
@@ -312,8 +312,8 @@ class PrintArgHelper:
self.parser = argparse.ArgumentParser(description='Print the assessment of diagnostic DNS queries', prog=prog)
# python3/python2 dual compatibility
- stdin_buffer = io.open(sys.stdin.fileno(), 'rb', closefd=False)
- stdout_buffer = io.open(sys.stdout.fileno(), 'wb', closefd=False)
+ stdin_buffer = io_try_buffered(sys.stdin, 'rb', closefd=False)
+ stdout_buffer = io_try_buffered(sys.stdout, 'wb', closefd=False)
try:
self.parser.add_argument('-f', '--names-file',
diff --git a/dnsviz/util.py b/dnsviz/util.py
index 8efed82..f4c6c71 100644
--- a/dnsviz/util.py
+++ b/dnsviz/util.py
@@ -184,3 +184,13 @@ def get_client_address(server):
ip = IPAddr(s.getsockname()[0])
s.close()
return ip
+
+def io_try_buffered(f, mode, closefd=True):
+ """Try opening buffered reader, but allow unbuffered on failure.
+
+ Required to pass tests under pytest."""
+ try:
+ return io.open(f.fileno(), mode, closefd=closefd)
+ except io.UnsupportedOperation:
+ # raised by f.fileno()
+ return f
diff --git a/tests/dnsviz_graph_options.py b/tests/test_dnsviz_graph_options.py
index 1e3db2c..1e3db2c 100644
--- a/tests/dnsviz_graph_options.py
+++ b/tests/test_dnsviz_graph_options.py
diff --git a/tests/dnsviz_graph_run.py b/tests/test_dnsviz_graph_run.py
index 41ba970..41ba970 100644
--- a/tests/dnsviz_graph_run.py
+++ b/tests/test_dnsviz_graph_run.py
diff --git a/tests/dnsviz_grok_options.py b/tests/test_dnsviz_grok_options.py
index 346459e..346459e 100644
--- a/tests/dnsviz_grok_options.py
+++ b/tests/test_dnsviz_grok_options.py
diff --git a/tests/dnsviz_grok_run.py b/tests/test_dnsviz_grok_run.py
index c4d0933..c4d0933 100644
--- a/tests/dnsviz_grok_run.py
+++ b/tests/test_dnsviz_grok_run.py
diff --git a/tests/dnsviz_print_options.py b/tests/test_dnsviz_print_options.py
index ce118ad..ce118ad 100644
--- a/tests/dnsviz_print_options.py
+++ b/tests/test_dnsviz_print_options.py
diff --git a/tests/dnsviz_print_run.py b/tests/test_dnsviz_print_run.py
index 8849403..8849403 100644
--- a/tests/dnsviz_print_run.py
+++ b/tests/test_dnsviz_print_run.py
diff --git a/tests/dnsviz_probe_options.py b/tests/test_dnsviz_probe_options.py
index d24b2f4..d24b2f4 100644
--- a/tests/dnsviz_probe_options.py
+++ b/tests/test_dnsviz_probe_options.py
diff --git a/tests/dnsviz_probe_run_offline.py b/tests/test_dnsviz_probe_run_offline.py
index b0705d3..b0705d3 100644
--- a/tests/dnsviz_probe_run_offline.py
+++ b/tests/test_dnsviz_probe_run_offline.py
diff --git a/tests/dnsviz_probe_run_online.py b/tests/test_dnsviz_probe_run_online.py
index 8533d48..8533d48 100644
--- a/tests/dnsviz_probe_run_online.py
+++ b/tests/test_dnsviz_probe_run_online.py