[jhbuild] make check: run Python tests



commit bc139b1e0b8d6d66d54e323cd22a6ef22c322a58
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Sat Sep 21 18:31:41 2019 +0200

    make check: run Python tests
    
    make check only did xmllint runs until now. This moves the xmllint
    code into the Python test suite and we now run the Python tests
    during 'make check'.
    
    To get 'make distcheck' to pass we also need to dist all Python related test files.

 .gitlab-ci.yml     |  1 -
 Makefile.am        | 36 +++++++++++++++++------------
 tests/test_main.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 87 insertions(+), 16 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 062e76a1..3380f855 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -11,7 +11,6 @@ test:
     - make install
     - make distcheck
     - cd ..
-    - python2 -m pytest
     - python2 -m flake8 .
     - python3 -m flake8 .
     - mkdir public
diff --git a/Makefile.am b/Makefile.am
index b7817bd5..600dd8c4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -27,7 +27,25 @@ EXTRA_DIST = $(PATCHES) $(MODULESETS) $(DTDS) \
        README.rst \
        modulesets/moduleset.xsl \
        autogen.sh \
-       jhbuild.desktop.in.in jhbuild.desktop.in
+       jhbuild.desktop.in.in jhbuild.desktop.in \
+       tests/test_main.py \
+       tests/mock.py \
+       tests/autotools/autogen.sh \
+       tests/autotools/configure.in \
+       tests/autotools/hello.c \
+       tests/autotools/Makefile.am \
+       tests/distutils/hello \
+       tests/distutils/setup.py \
+       tests/hello/autogen.sh \
+       tests/hello/configure.in \
+       tests/hello/hello-frontend.c \
+       tests/hello/Makefile.am \
+       tests/libhello/autogen.sh \
+       tests/libhello/configure.in \
+       tests/libhello/libhello.c \
+       tests/libhello/libhello.h \
+       tests/libhello/libhello.pc.in \
+       tests/libhello/Makefile.am
 
 CLEANFILES = \
        $(desktop_DATA)
@@ -38,17 +56,7 @@ MAINTAINERCLEANFILES = \
 install-exec-local:
        $(srcdir)/scripts/debian-python2-postinstall-hook.sh $(DESTDIR)$(bindir)
 
-# Check the modulesets for validity.
-# This is a lower-level check than `jhbuild checkmodulesets` (which analyses the
-# module graph), and doesn't require jhbuild to be built and installed.
-#
-# This will fail if xmllint or trang isn't installed.
-check-modulesets:
-       xmllint --noout --dtdvalid $(srcdir)/modulesets/moduleset.dtd $(MODULESETS)
-       trang $(srcdir)/modulesets/moduleset.rnc $(builddir)/moduleset.rng
-       xmllint --noout --relaxng $(builddir)/moduleset.rng $(MODULESETS)
-       rm -f $(builddir)/moduleset.rng
-.PHONY: check-modulesets
-
-check: check-modulesets
+check:
+       $(PYTHON) -m unittest discover -v -s $(top_srcdir)/tests
+
 .PHONY: check
diff --git a/tests/test_main.py b/tests/test_main.py
index bd3cf636..bcab1525 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -26,6 +26,7 @@ import shutil
 import logging
 import subprocess
 import sys
+import glob
 import tempfile
 import unittest
 
@@ -33,9 +34,11 @@ import __builtin__
 __builtin__.__dict__['_'] = lambda x: x
 __builtin__.__dict__['N_'] = lambda x: x
 
+SRCDIR = os.path.join(os.path.dirname(__file__), '..')
+
 __builtin__.__dict__['PKGDATADIR'] = None
 __builtin__.__dict__['DATADIR'] = None
-__builtin__.__dict__['SRCDIR'] = os.path.join(os.path.dirname(__file__), '..')
+__builtin__.__dict__['SRCDIR'] = SRCDIR
 
 sys.path.insert(0, SRCDIR)
 
@@ -84,6 +87,64 @@ if sys.platform.startswith('win'):
             cmd_list = subprocess_win32.cmdline2list (cmdline)
             self.assertEqual (cmd_list, ['test', 'no quotes', '!=', '"no\\ quotes"'])
 
+
+def has_xmllint():
+    try:
+        subprocess.check_output(['xmllint'], stderr=subprocess.STDOUT)
+    except OSError:
+        return False
+    except subprocess.CalledProcessError:
+        pass
+    return True
+
+
+def has_trang():
+    try:
+        subprocess.check_output(['trang'], stderr=subprocess.STDOUT)
+    except OSError:
+        return False
+    except subprocess.CalledProcessError:
+        pass
+    return True
+
+
+class ModulesetXMLTest(unittest.TestCase):
+    """Check the modulesets for validity.
+
+    This is a lower-level check than `jhbuild checkmodulesets` (which analyses the
+    module graph), and doesn't require jhbuild to be built and installed.
+    """
+
+    @unittest.skipUnless(has_xmllint(), "no xmllint")
+    def test_dtd(self):
+        modulesets = os.path.join(SRCDIR, 'modulesets')
+        modules = glob.glob(os.path.join(modulesets, '*.modules'))
+        dtd = os.path.join(modulesets, 'moduleset.dtd')
+        try:
+            subprocess.check_output(
+                ['xmllint', '--noout', '--dtdvalid', dtd] + modules, stderr=subprocess.STDOUT)
+        except subprocess.CalledProcessError as e:
+            raise Exception(e.output)
+
+    @unittest.skipUnless(has_xmllint(), "no xmllint")
+    @unittest.skipUnless(has_trang(), "no trang")
+    def test_relaxng(self):
+        modulesets = os.path.join(SRCDIR, 'modulesets')
+        modules = glob.glob(os.path.join(modulesets, '*.modules'))
+        rnc = os.path.join(modulesets, 'moduleset.rnc')
+        temp_dir = tempfile.mkdtemp()
+        rng = os.path.join(temp_dir, 'moduleset.rng')
+        try:
+            subprocess.check_output(
+                ['trang', rnc, rng], stderr=subprocess.STDOUT)
+            subprocess.check_output(
+                ['xmllint', '--noout', '--relaxng', rng] + modules, stderr=subprocess.STDOUT)
+        except subprocess.CalledProcessError as e:
+            raise Exception(e.output)
+        finally:
+            shutil.rmtree(temp_dir)
+
+
 class _TestConfig(jhbuild.config.Config):
 
     # The Config base class calls setup_env() in the constructor, but
@@ -132,6 +193,9 @@ class JhbuildConfigTestCase(unittest.TestCase):
         branch_dir = os.path.join(config.checkoutroot, src_name)
         shutil.copytree(os.path.join(os.path.dirname(__file__), src_name),
                         branch_dir)
+        # With 'make distcheck' the source is read only, so we need to chmod
+        # after copying
+        os.chmod(branch_dir, 0o777)
         return SimpleBranch(src_name, branch_dir)
 
     def make_terminal_buildscript(self, config, module_list):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]