#1 Use pytest to run and manage tests
Opened 2 years ago by pemensik. Modified 2 months ago
rpms/ pemensik/dnsviz pytest  into  rawhide

@@ -0,0 +1,108 @@ 

+ From a544a070e62664ba752375227678dc538790ad2b Mon Sep 17 00:00:00 2001

+ From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>

+ Date: Tue, 14 Sep 2021 16:30:12 +0200

+ Subject: [PATCH 1/4] Do not require working fileno in tests

+ 

+ Pytest replaces stdin and stdout with fake class, ensuring stdin is not

+ used in tests. Tests work fine with file handle directly, fallback from

+ io.open to just pure class. It makes tests passing under pytest.

+ ---

+  dnsviz/commands/graph.py |  6 +++---

+  dnsviz/commands/grok.py  |  6 +++---

+  dnsviz/commands/print.py |  6 +++---

+  dnsviz/util.py           | 10 ++++++++++

+  4 files changed, 19 insertions(+), 9 deletions(-)

+ 

+ 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

+ -- 

+ 2.31.1

+ 

@@ -0,0 +1,69 @@ 

+ From aded653f51738589339d2d785cede7b7288e55ca Mon Sep 17 00:00:00 2001

+ From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>

+ Date: Tue, 14 Sep 2021 16:36:20 +0200

+ Subject: [PATCH] Make tests detected by pytest

+ 

+ Do not require explicit running of each test, locate tests just from

+ pytest.

+ 

+ Change also travis test paths.

+ ---

+  tests/{dnsviz_graph_options.py => test_dnsviz_graph_options.py}   | 0

+  tests/{dnsviz_graph_run.py => test_dnsviz_graph_run.py}           | 0

+  tests/{dnsviz_grok_options.py => test_dnsviz_grok_options.py}     | 0

+  tests/{dnsviz_grok_run.py => test_dnsviz_grok_run.py}             | 0

+  tests/{dnsviz_print_options.py => test_dnsviz_print_options.py}   | 0

+  tests/{dnsviz_print_run.py => test_dnsviz_print_run.py}           | 0

+  tests/{dnsviz_probe_options.py => test_dnsviz_probe_options.py}   | 0

+  ...sviz_probe_run_offline.py => test_dnsviz_probe_run_offline.py} | 0

+  ...dnsviz_probe_run_online.py => test_dnsviz_probe_run_online.py} | 0

+  9 files changed, 0 insertions(+), 0 deletions(-)

+  rename tests/{dnsviz_graph_options.py => test_dnsviz_graph_options.py} (100%)

+  rename tests/{dnsviz_graph_run.py => test_dnsviz_graph_run.py} (100%)

+  rename tests/{dnsviz_grok_options.py => test_dnsviz_grok_options.py} (100%)

+  rename tests/{dnsviz_grok_run.py => test_dnsviz_grok_run.py} (100%)

+  rename tests/{dnsviz_print_options.py => test_dnsviz_print_options.py} (100%)

+  rename tests/{dnsviz_print_run.py => test_dnsviz_print_run.py} (100%)

+  rename tests/{dnsviz_probe_options.py => test_dnsviz_probe_options.py} (100%)

+  rename tests/{dnsviz_probe_run_offline.py => test_dnsviz_probe_run_offline.py} (100%)

+  rename tests/{dnsviz_probe_run_online.py => test_dnsviz_probe_run_online.py} (100%)

+ 

+ diff --git a/tests/dnsviz_graph_options.py b/tests/test_dnsviz_graph_options.py

+ similarity index 100%

+ rename from tests/dnsviz_graph_options.py

+ rename to tests/test_dnsviz_graph_options.py

+ diff --git a/tests/dnsviz_graph_run.py b/tests/test_dnsviz_graph_run.py

+ similarity index 100%

+ rename from tests/dnsviz_graph_run.py

+ rename to tests/test_dnsviz_graph_run.py

+ diff --git a/tests/dnsviz_grok_options.py b/tests/test_dnsviz_grok_options.py

+ similarity index 100%

+ rename from tests/dnsviz_grok_options.py

+ rename to tests/test_dnsviz_grok_options.py

+ diff --git a/tests/dnsviz_grok_run.py b/tests/test_dnsviz_grok_run.py

+ similarity index 100%

+ rename from tests/dnsviz_grok_run.py

+ rename to tests/test_dnsviz_grok_run.py

+ diff --git a/tests/dnsviz_print_options.py b/tests/test_dnsviz_print_options.py

+ similarity index 100%

+ rename from tests/dnsviz_print_options.py

+ rename to tests/test_dnsviz_print_options.py

+ diff --git a/tests/dnsviz_print_run.py b/tests/test_dnsviz_print_run.py

+ similarity index 100%

+ rename from tests/dnsviz_print_run.py

+ rename to tests/test_dnsviz_print_run.py

+ diff --git a/tests/dnsviz_probe_options.py b/tests/test_dnsviz_probe_options.py

+ similarity index 100%

+ rename from tests/dnsviz_probe_options.py

+ rename to tests/test_dnsviz_probe_options.py

+ diff --git a/tests/dnsviz_probe_run_offline.py b/tests/test_dnsviz_probe_run_offline.py

+ similarity index 100%

+ rename from tests/dnsviz_probe_run_offline.py

+ rename to tests/test_dnsviz_probe_run_offline.py

+ diff --git a/tests/dnsviz_probe_run_online.py b/tests/test_dnsviz_probe_run_online.py

+ similarity index 100%

+ rename from tests/dnsviz_probe_run_online.py

+ rename to tests/test_dnsviz_probe_run_online.py

+ -- 

+ 2.31.1

+ 

@@ -0,0 +1,214 @@ 

+ From 7a00a9d51d5af19edeccda4b7c50d07a57d2efd4 Mon Sep 17 00:00:00 2001

+ From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>

+ Date: Tue, 14 Sep 2021 20:02:14 +0200

+ Subject: [PATCH] Skip probe tests on empty resolv.conf

+ MIME-Version: 1.0

+ Content-Type: text/plain; charset=UTF-8

+ Content-Transfer-Encoding: 8bit

+ 

+ Return different return code from probe in case no resolvers were found.

+ Use that return code to detect this problem in tests and mark test case

+ skipped instead of failed. Helps avoiding failures in networkless build

+ environment in Fedora mock.

+ 

+ Signed-off-by: Petr Menšík <pemensik@redhat.com>

+ PatchNumber: 3

+ ---

+  dnsviz/commands/probe.py               |  7 ++++++-

+  doc/man/dnsviz-probe.1                 |  2 ++

+  tests/test_dnsviz_probe_options.py     |  7 +++++--

+  tests/test_dnsviz_probe_run_offline.py | 27 +++++++++++++++++---------

+  tests/test_dnsviz_probe_run_online.py  | 16 ++++++++++-----

+  5 files changed, 42 insertions(+), 17 deletions(-)

+ 

+ diff --git a/dnsviz/commands/probe.py b/dnsviz/commands/probe.py

+ index d317a45..5d90c93 100644

+ --- a/dnsviz/commands/probe.py

+ +++ b/dnsviz/commands/probe.py

+ @@ -1451,7 +1451,7 @@ def build_helper(logger, cmd, subcmd):

+          resolver = Resolver.from_file(RESOLV_CONF, StandardRecursiveQueryCD, transport_manager=tm)

+      except ResolvConfError:

+          sys.stderr.write('File %s not found or contains no nameserver entries.\n' % RESOLV_CONF)

+ -        sys.exit(1)

+ +        sys.exit(5)

+  

+      arghelper = ArgHelper(resolver, logger)

+      arghelper.build_parser('%s %s' % (cmd, subcmd))

+ @@ -1481,6 +1481,11 @@ def main(argv):

+              arghelper.serve_zones()

+          except argparse.ArgumentTypeError as e:

+              arghelper.parser.error(str(e))

+ +        except ResolvConfError as e:

+ +            arghelper.parser.print_usage(sys.stderr)

+ +            sys.stderr.write("%(prog)s: error: %(errmsg)s\n" % {

+ +                             'prog': arghelper.parser.prog, 'errmsg': str(e) })

+ +            sys.exit(5)

+          except (ZoneFileServiceError, MissingExecutablesError) as e:

+              s = str(e)

+              if s:

+ diff --git a/doc/man/dnsviz-probe.1 b/doc/man/dnsviz-probe.1

+ index 71a9e7d..17c66da 100644

+ --- a/doc/man/dnsviz-probe.1

+ +++ b/doc/man/dnsviz-probe.1

+ @@ -326,6 +326,8 @@ The network was unavailable for diagnostic queries.

+  There was an error processing the input or saving the output.

+  .IP 4

+  Program execution was interrupted, or an unknown error occurred.

+ +.IP 5

+ +No recursive resolvers found in resolv.conf nor given on command line.

+  .SH SEE ALSO

+  .BR dnsviz(1),

+  .BR dnsviz-grok(1),

+ diff --git a/tests/test_dnsviz_probe_options.py b/tests/test_dnsviz_probe_options.py

+ index 4519160..2f7140d 100644

+ --- a/tests/test_dnsviz_probe_options.py

+ +++ b/tests/test_dnsviz_probe_options.py

+ @@ -13,7 +13,7 @@ import dns.name, dns.rdatatype, dns.rrset, dns.zone

+  

+  from dnsviz.commands.probe import ZoneFileToServe, ArgHelper, DomainListArgHelper, StandardRecursiveQueryCD, WILDCARD_EXPLICIT_DELEGATION, AnalysisInputError, CustomQueryMixin

+  from dnsviz import transport

+ -from dnsviz.resolver import Resolver

+ +from dnsviz.resolver import Resolver, ResolvConfError

+  from dnsviz.ipaddr import IPAddr

+  

+  DATA_DIR = os.path.dirname(__file__)

+ @@ -24,7 +24,10 @@ EXAMPLE_AUTHORITATIVE = os.path.join(DATA_DIR, 'data', 'example-authoritative.js

+  class DNSVizProbeOptionsTestCase(unittest.TestCase):

+      def setUp(self):

+          self.tm = transport.DNSQueryTransportManager()

+ -        self.resolver = Resolver.from_file('/etc/resolv.conf', StandardRecursiveQueryCD, transport_manager=self.tm)

+ +        try:

+ +            self.resolver = Resolver.from_file('/etc/resolv.conf', StandardRecursiveQueryCD, transport_manager=self.tm)

+ +        except ResolvConfError:

+ +            self.skipTest("No resolvers found")

+          self.helper = DomainListArgHelper(self.resolver)

+          self.logger = logging.getLogger()

+          for handler in self.logger.handlers:

+ diff --git a/tests/test_dnsviz_probe_run_offline.py b/tests/test_dnsviz_probe_run_offline.py

+ index b0705d3..068e6bf 100644

+ --- a/tests/test_dnsviz_probe_run_offline.py

+ +++ b/tests/test_dnsviz_probe_run_offline.py

+ @@ -42,19 +42,27 @@ class DNSProbeRunOfflineTestCase(unittest.TestCase):

+          os.remove(self.output.name)

+          subprocess.check_call(['rm', '-rf', self.run_cwd])

+  

+ +    def assertReturnCode(self, retcode):

+ +        if retcode == 5:

+ +            self.skipTest("No resolvers available")

+ +        else:

+ +            self.assertEqual(retcode, 0)

+ +

+ +

+      def test_dnsviz_probe_input(self):

+          with io.open(self.output.name, 'wb') as fh_out:

+              with gzip.open(EXAMPLE_AUTHORITATIVE) as fh_in:

+                  p = subprocess.Popen([self.dnsviz_bin, 'probe', '-d', '0', '-r', '-', 'example.com'], stdin=subprocess.PIPE, stdout=fh_out)

+                  p.communicate(fh_in.read())

+ -                self.assertEqual(p.returncode, 0)

+ +                self.assertReturnCode(p.returncode)

+  

+          with io.open(self.output.name, 'wb') as fh:

+              self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-r', self.example_auth_out.name, 'example.com'], stdout=fh), 0)

+  

+      def test_dnsviz_probe_names_input(self):

+          with io.open(self.output.name, 'wb') as fh:

+ -            self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-r', self.example_auth_out.name, '-f', self.names_file.name], stdout=fh), 0)

+ +            ret = subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-r', self.example_auth_out.name, '-f', self.names_file.name], stdout=fh)

+ +            self.assertReturnCode(ret)

+  

+          with io.open(self.output.name, 'wb') as fh_out:

+              with io.open(self.names_file.name, 'rb') as fh_in:

+ @@ -64,7 +72,8 @@ class DNSProbeRunOfflineTestCase(unittest.TestCase):

+  

+      def test_dnsviz_probe_output(self):

+          with io.open(self.output.name, 'wb') as fh:

+ -            self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-r', self.example_auth_out.name, 'example.com'], cwd=self.run_cwd, stdout=fh), 0)

+ +            ret = subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-r', self.example_auth_out.name, 'example.com'], cwd=self.run_cwd, stdout=fh)

+ +            self.assertReturnCode(ret)

+  

+          with io.open(self.output.name, 'wb') as fh:

+              self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-r', self.example_auth_out.name, '-o', '-', 'example.com'], cwd=self.run_cwd, stdout=fh), 0)

+ @@ -78,35 +87,35 @@ class DNSProbeRunOfflineTestCase(unittest.TestCase):

+              with gzip.open(EXAMPLE_AUTHORITATIVE) as fh_in:

+                  p = subprocess.Popen([self.dnsviz_bin, 'probe', '-d', '0', '-r', '-', 'example.com'], stdin=subprocess.PIPE, stdout=fh_out)

+                  p.communicate(fh_in.read())

+ -                self.assertEqual(p.returncode, 0)

+ +                self.assertReturnCode(p.returncode)

+  

+          with io.open(self.output.name, 'wb') as fh_out:

+              with gzip.open(ROOT_AUTHORITATIVE) as fh_in:

+                  p = subprocess.Popen([self.dnsviz_bin, 'probe', '-d', '0', '-r', '-', '.'], stdin=subprocess.PIPE, stdout=fh_out)

+                  p.communicate(fh_in.read())

+ -                self.assertEqual(p.returncode, 0)

+ +                self.assertReturnCode(p.returncode)

+  

+      def test_dnsviz_probe_rec(self):

+          with io.open(self.output.name, 'wb') as fh_out:

+              with gzip.open(EXAMPLE_RECURSIVE) as fh_in:

+                  p = subprocess.Popen([self.dnsviz_bin, 'probe', '-d', '0', '-r', '-', 'example.com'], stdin=subprocess.PIPE, stdout=fh_out)

+                  p.communicate(fh_in.read())

+ -                self.assertEqual(p.returncode, 0)

+ +                self.assertReturnCode(p.returncode)

+  

+          with io.open(self.output.name, 'wb') as fh_out:

+              with gzip.open(ROOT_RECURSIVE) as fh_in:

+                  p = subprocess.Popen([self.dnsviz_bin, 'probe', '-d', '0', '-r', '-', '.'], stdin=subprocess.PIPE, stdout=fh_out)

+                  p.communicate(fh_in.read())

+ -                self.assertEqual(p.returncode, 0)

+ +                self.assertReturnCode(p.returncode)

+  

+      def test_dnsviz_probe_auth_local(self):

+          with io.open(self.output.name, 'wb') as fh:

+ -            self.assertEqual(subprocess.call(

+ +            self.assertReturnCode(subprocess.call(

+                  [self.dnsviz_bin, 'probe', '-d', '0', '-A',

+                      '-x' 'example.com:%s' % EXAMPLE_COM_SIGNED,

+                      '-N' 'example.com:%s' % EXAMPLE_COM_DELEGATION,

+                      '-D' 'example.com:%s' % EXAMPLE_COM_DELEGATION,

+ -                    'example.com'], stdout=fh), 0)

+ +                    'example.com'], stdout=fh))

+  

+  if __name__ == '__main__':

+      unittest.main()

+ diff --git a/tests/test_dnsviz_probe_run_online.py b/tests/test_dnsviz_probe_run_online.py

+ index 8533d48..c74f5d6 100644

+ --- a/tests/test_dnsviz_probe_run_online.py

+ +++ b/tests/test_dnsviz_probe_run_online.py

+ @@ -15,23 +15,29 @@ class DNSVizProbeRunOnlineTestCase(unittest.TestCase):

+      def tearDown(self):

+          os.remove(self.output.name)

+  

+ +    def assertReturnCode(self, retcode):

+ +        if retcode == 5:

+ +            self.skipTest("No recursive resolves found nor given")

+ +        else:

+ +            self.assertEqual(retcode, 0)

+ +

+      def test_dnsviz_probe_auth(self):

+          with io.open(self.output.name, 'wb') as fh:

+ -            self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-A', '.'], stdout=fh), 0)

+ +            self.assertReturnCode(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-A', '.'], stdout=fh))

+  

+          with io.open(self.output.name, 'wb') as fh:

+ -            self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-A', 'example.com'], stdout=fh), 0)

+ +            self.assertReturnCode(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-A', 'example.com'], stdout=fh))

+  

+      def test_dnsviz_probe_rec(self):

+          with io.open(self.output.name, 'wb') as fh:

+ -            self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '.'], stdout=fh), 0)

+ +            self.assertReturnCode(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '.'], stdout=fh))

+  

+          with io.open(self.output.name, 'wb') as fh:

+ -            self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', 'example.com'], stdout=fh), 0)

+ +            self.assertReturnCode(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', 'example.com'], stdout=fh))

+  

+      def test_dnsviz_probe_rec_multi(self):

+          with io.open(self.output.name, 'wb') as fh:

+ -            self.assertEqual(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-t', '3', '.', 'example.com', 'example.net'], stdout=fh), 0)

+ +            self.assertReturnCode(subprocess.call([self.dnsviz_bin, 'probe', '-d', '0', '-t', '3', '.', 'example.com', 'example.net'], stdout=fh))

+  

+  

+  if __name__ == '__main__':

+ -- 

+ 2.31.1

+ 

@@ -0,0 +1,34 @@ 

+ From 3625483996252eab9f90ac4eb2f60c915488d8b7 Mon Sep 17 00:00:00 2001

+ From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>

+ Date: Tue, 14 Sep 2021 20:27:35 +0200

+ Subject: [PATCH 4/4] Allow overriding of share path by environment

+ MIME-Version: 1.0

+ Content-Type: text/plain; charset=UTF-8

+ Content-Transfer-Encoding: 8bit

+ 

+ It might be useful to test installed code before it is installed to

+ permanent destination. Allow overriding of path to shared data by

+ environment. Intented to make possible testing with prefix=/usr, but

+ installed into subdirectory similar to make install DESTDIR= variable.

+ 

+ Signed-off-by: Petr Menšík <pemensik@redhat.com>

+ ---

+  dnsviz/config.py.in | 2 +-

+  1 file changed, 1 insertion(+), 1 deletion(-)

+ 

+ diff --git a/dnsviz/config.py.in b/dnsviz/config.py.in

+ index 373fde2..6c12029 100644

+ --- a/dnsviz/config.py.in

+ +++ b/dnsviz/config.py.in

+ @@ -32,7 +32,7 @@ if (hasattr(sys, 'real_prefix') or hasattr(sys, 'base_prefix')) and \

+      DNSVIZ_INSTALL_PREFIX = sys.prefix

+  else:

+      DNSVIZ_INSTALL_PREFIX = _prefix

+ -DNSVIZ_SHARE_PATH = os.path.join(DNSVIZ_INSTALL_PREFIX, 'share', 'dnsviz')

+ +DNSVIZ_SHARE_PATH = os.getenv('DNSVIZ_SHARE_PATH', os.path.join(DNSVIZ_INSTALL_PREFIX, 'share', 'dnsviz'))

+  JQUERY_PATH = __JQUERY_PATH__

+  JQUERY_UI_PATH = __JQUERY_UI_PATH__

+  JQUERY_UI_CSS_PATH = __JQUERY_UI_CSS_PATH__

+ -- 

+ 2.31.1

+ 

file modified
+11 -14
@@ -7,6 +7,13 @@ 

  URL:            https://github.com/dnsviz/dnsviz

  Source0:        https://github.com/dnsviz/dnsviz/releases/download/v%{version}/%{name}-%{version}.tar.gz

  

+ # https://github.com/dnsviz/dnsviz/pull/87

+ Patch1:         0001-Do-not-require-working-fileno-in-tests.patch

+ Patch2:         0002-Make-tests-detected-by-pytest.patch

+ # https://github.com/dnsviz/dnsviz/pull/88

+ Patch3:         0003-Skip-probe-tests-on-empty-resolv.conf.patch

+ Patch4:         0004-Allow-overriding-of-share-path-by-environment.patch

+ 

  BuildArch:      noarch

  BuildRequires:  python3-devel

  BuildRequires:  graphviz
@@ -14,6 +21,7 @@ 

  BuildRequires:  python3-pygraphviz >= 1.3

  BuildRequires:  python3-m2crypto >= 0.28.0

  BuildRequires:  python3-dns >= 1.13

+ BuildRequires:  python3-pytest

  Requires:       python3-pygraphviz >= 1.3

  Requires:       python3-m2crypto >= 0.28.0

  Requires:       python3-dns >= 1.13
@@ -24,7 +32,7 @@ 

  powers the Web-based analysis available at http://dnsviz.net/

  

  %prep

- %autosetup

+ %autosetup -p1

  

  %build

  %py3_build
@@ -41,19 +49,8 @@ 

  pushd tests

  mkdir bin

  ln -s %{buildroot}%{_bindir}/%{name} bin/%{name}

- export PYTHONPATH="%{buildroot}%{python3_sitelib}"

- %{__python3} dnsviz_graph_options.py

- # Cannot cope with not yet working DNSVIZ_SHARE_PATH

- #%{__python3} dnsviz_graph_run.py

- %{__python3} dnsviz_grok_options.py

- %{__python3} dnsviz_grok_run.py

- %{__python3} dnsviz_print_options.py

- %{__python3} dnsviz_print_run.py

- # Fails with dnsviz.resolver.ResolvConfError: No servers found in /etc/resolv.conf

- #%{__python3} dnsviz_probe_options.py

- #%{__python3} dnsviz_probe_run_offline.py

- # No online tests in mock

- #%{__python3} dnsviz_probe_run_online.py

+ export DNSVIZ_SHARE_PATH="%{buildroot}%{_datadir}/%{name}"

+ %pytest

  popd

  

  %files

Multiple changes to be able to use %pytest macro.

It skips tests requiring working resolv.conf, which is not available during build in mock.

I found a problem with hang after tests. It does not happen on fedpkg local, but happens on fedpkg --release rawhide mockbuild on my machine. It might be some threads are started but not terminated.

Any ideas, what might be wrong, @cdeccio ?

It's been a while since you submitted this. I took over this package a while back and am working to get it cleaned up.

Will you rebase your PR against the current rawhide branch so I can merge it?

Perhaps look into the -k option for pytest as well instead of patching out some tests.