[gobject-introspection] tests: port offset tests to Python
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] tests: port offset tests to Python
- Date: Thu, 26 Jul 2018 17:30:28 +0000 (UTC)
commit 6c85b1c45460edd74395b119ebbff6a53eacec7e
Author: Christoph Reiter <reiter christoph gmail com>
Date: Thu Jul 26 19:11:51 2018 +0200
tests: port offset tests to Python
Use the test executable to generate files in a temporary location
and use difflib to compare their content.
This removes the requirement on "diff" for the test.
tests/offsets/Makefile.am | 10 ++++-----
tests/offsets/test_offsets.py | 47 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 5 deletions(-)
---
diff --git a/tests/offsets/Makefile.am b/tests/offsets/Makefile.am
index 0df9c151..fa1c1001 100644
--- a/tests/offsets/Makefile.am
+++ b/tests/offsets/Makefile.am
@@ -41,7 +41,9 @@ gitestoffsets_LDADD = $(top_builddir)/libgirepository-1.0.la $(GIREPO_LIBS)
gitestoffsets.c: gen-gitestoffsets offsets.h Offsets-1.0.typelib
$(AM_V_GEN) $(PYTHON) $(srcdir)/gen-gitestoffsets $(srcdir)/offsets.h > $@ || ( rm -f $@ && false )
-EXTRA_DIST += gen-gitestoffsets
+EXTRA_DIST += \
+ gen-gitestoffsets \
+ test_offsets.py
BUILT_SOURCES += gitestoffsets.c
CLEANFILES += gitestoffsets.c $(EXTRA_PROGRAMS)
@@ -50,7 +52,5 @@ CLEANFILES += gitestoffsets.c $(EXTRA_PROGRAMS)
# The trailing "echo" in LOG_COMPILER is used to ignore automake passing
# gitestoffsets as we already run this in the same command line.
TESTS = gitestoffsets
-LOG_COMPILER = env GI_TYPELIB_PATH=:$(top_builddir) ./gitestoffsets$(EXEEXT) offsets.compiled
offsets.introspected && \
- diff -u offsets.compiled offsets.introspected && echo
-
-CLEANFILES += offsets.compiled offsets.introspected
+TESTS_ENVIRONMENT = env top_builddir=$(top_builddir) builddir=$(builddir)
+LOG_COMPILER = $(PYTHON) $(srcdir)/test_offsets.py && echo
diff --git a/tests/offsets/test_offsets.py b/tests/offsets/test_offsets.py
new file mode 100755
index 00000000..db10f1c4
--- /dev/null
+++ b/tests/offsets/test_offsets.py
@@ -0,0 +1,47 @@
+import io
+import os
+import tempfile
+import difflib
+import contextlib
+import subprocess
+import unittest
+
+
+@contextlib.contextmanager
+def temp_filename(*args, **kwargs):
+ fd, name = tempfile.mkstemp(*args, **kwargs)
+ try:
+ os.close(fd)
+ yield name
+ finally:
+ os.unlink(name)
+
+
+class TestOffsets(unittest.TestCase):
+
+ def test_main(self):
+ gitestoffsets = os.path.join(os.environ["builddir"], "gitestoffsets")
+
+ env = os.environ.copy()
+ env["GI_TYPELIB_PATH"] = os.pathsep.join(
+ [os.environ["builddir"], os.environ["top_builddir"]])
+
+ with temp_filename(suffix=".compiled") as compiled_name, \
+ temp_filename(suffix=".introspected") as introspected_name:
+
+ subprocess.check_call(
+ [gitestoffsets, compiled_name, introspected_name], env=env)
+
+ with io.open(compiled_name, encoding="utf-8") as compiled, \
+ io.open(introspected_name, encoding="utf-8") as introspected:
+
+ result = difflib.unified_diff(
+ compiled.readlines(), introspected.readlines(),
+ fromfile=compiled_name, tofile=introspected_name)
+ result = "".join(result)
+ if result:
+ raise AssertionError(result)
+
+
+if __name__ == '__main__':
+ unittest.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]