[pyclutter] Add the beginnings of a test suite



commit 7d258707820cb6e43edd49c9d8b3482ebf4e205f
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Apr 30 12:58:41 2015 +0100

    Add the beginnings of a test suite
    
    We can start trying to track regressions, at the very least.

 Makefile.am                   |    2 +-
 configure.ac                  |    1 +
 tests/Makefile.am             |   11 +++++++
 tests/run-tests.py            |   61 +++++++++++++++++++++++++++++++++++++++++
 tests/test_overrides_Color.py |   34 +++++++++++++++++++++++
 5 files changed, 108 insertions(+), 1 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 724dc3b..6be1622 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,3 +1,3 @@
 ACLOCAL_AMFLAGS = -I build/autotools
 
-SUBDIRS = build gi examples
+SUBDIRS = build gi tests examples
diff --git a/configure.ac b/configure.ac
index 1d5f5fd..e225c2c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -100,6 +100,7 @@ AC_CONFIG_FILES([
     gi/Makefile
     gi/overrides/Makefile
     examples/Makefile
+    tests/Makefile
 ])
 
 AC_OUTPUT
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..ee132c9
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,11 @@
+test_files = \
+       test_overrides_Color.py
+
+TESTS_ENVIRONMENT = \
+       PYTHONPATH=$(PYGI_OVERRIDES_DIR):$(top_builddir):$(top_builddir)/tests:$${PYTHONPATH:+:$$PYTHONPATH} \
+       MALLOC_PERTURB_=85 \
+       MALLOC_CHECK_=3 \
+       G_SLICE=debug-blocks \
+       TESTS_BUILDDIR=$(builddir)
+
+check_SCRIPTS = run-tests.py
diff --git a/tests/run-tests.py b/tests/run-tests.py
new file mode 100755
index 0000000..c21b651
--- /dev/null
+++ b/tests/run-tests.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+# -*- Mode: Python -*-
+
+import os
+import glob
+import sys
+
+import unittest
+
+# this was renamed in Python 3, provide backwards compatible name
+if sys.version_info[:2] == (2, 7):
+    unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
+
+if '--help' in sys.argv:
+    print("Usage: ./run-tests.py <testfiles>")
+    sys.exit(0)
+
+mydir = os.path.dirname(os.path.abspath(__file__))
+tests_builddir = os.path.abspath(os.environ.get('TESTS_BUILDDIR', os.path.dirname(__file__)))
+builddir = os.path.dirname(tests_builddir)
+
+# we have to do this here instead of Makefile.am so that the implicitly added
+# directory for the source file comes after the builddir
+sys.path.insert(0, tests_builddir)
+sys.path.insert(0, builddir)
+
+# force untranslated messages, as we check for them in some tests
+os.environ['LC_MESSAGES'] = 'C'
+os.environ['G_DEBUG'] = 'fatal-warnings fatal-criticals'
+
+# make Gio able to find our gschemas.compiled in tests/. This needs to be set
+# before importing Gio. Support a separate build tree, so look in build dir
+# first.
+os.environ['GSETTINGS_BACKEND'] = 'memory'
+os.environ['GSETTINGS_SCHEMA_DIR'] = tests_builddir
+os.environ['G_FILENAME_ENCODING'] = 'UTF-8'
+
+# Load tests.
+if 'TESTS' in os.environ:
+    names = os.environ['TESTS'].split()
+elif 'TEST_FILES' in os.environ:
+    names = []
+    for filename in os.environ['TEST_FILES'].split():
+        names.append(filename[:-3])
+elif len(sys.argv) > 1:
+    names = []
+    for filename in sys.argv[1:]:
+        names.append(filename.replace('.py', ''))
+else:
+    names = []
+    for filename in glob.iglob(os.path.join(mydir, 'test_*.py')):
+        names.append(os.path.basename(filename)[:-3])
+
+loader = unittest.TestLoader()
+suite = loader.loadTestsFromNames(names)
+
+# Run tests.
+runner = unittest.TextTestRunner(verbosity=2)
+result = runner.run(suite)
+if not result.wasSuccessful():
+    sys.exit(1)  # exit code so "make check" reports error
diff --git a/tests/test_overrides_Color.py b/tests/test_overrides_Color.py
new file mode 100644
index 0000000..91b7be1
--- /dev/null
+++ b/tests/test_overrides_Color.py
@@ -0,0 +1,34 @@
+import unittest
+import warnings
+
+import gi.overrides
+
+try:
+    from gi.repository import Clutter
+    Clutter # pyflakes
+except ImportError as err:
+    print(err)
+    Clutter = None
+
+ unittest skipUnless(Clutter, 'Clutter not available')
+class TestClutterColor(unittest.TestCase):
+    def test_color_empty(self):
+        color = Clutter.Color()
+        self.assertEqual(color.red, 0)
+        self.assertEqual(color.green, 0)
+        self.assertEqual(color.blue, 0)
+        self.assertEqual(color.alpha, 0)
+
+    def test_color_init_flat(self):
+        color = Clutter.Color(32, 64, 128, 255)
+        self.assertEqual(color.red, 32)
+        self.assertEqual(color.green, 64)
+        self.assertEqual(color.blue, 128)
+        self.assertEqual(color.alpha, 255)
+
+    def test_color_init_named(self):
+        color = Clutter.Color(red=64, alpha=128)
+        self.assertEqual(color.red, 64)
+        self.assertEqual(color.green, 0)
+        self.assertEqual(color.blue, 0)
+        self.assertEqual(color.alpha, 128)


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