changeset 619:75ecbe07abff

Introduct a test context to more easily switch between some unittest configurations
author Franz Glasner <f.glasner@feldmann-mg.com>
date Thu, 13 Jan 2022 11:39:38 +0100
parents 8dc514bd3d5e
children 794082c71f73
files tests/_perf_config.py tests/_test_context.py tests/test.py
diffstat 3 files changed, 22 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/tests/_perf_config.py	Wed Jan 12 13:44:12 2022 +0100
+++ b/tests/_perf_config.py	Thu Jan 13 11:39:38 2022 +0100
@@ -6,10 +6,7 @@
 import sys
 import timeit
 
-sys.path.insert(
-    0,
-    os.path.abspath(
-        os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))))
+from _test_context import TESTDATADIR
 
 
 opts = sys.argv[1:]
@@ -24,6 +21,8 @@
 setup = """
 import os
 
+from _test_context import TESTDATADIR
+
 import configmix
 from configmix.config import _HIER_SEPARATOR, \
                              py_quote, py_unquote, py_pathstr2path, \
@@ -33,12 +32,6 @@
 except ImportError:
     fast_unquote = fast_quote = fast_pathstr2path = _fast_split_ns = None
 
-TESTDATADIR = os.path.join(
-    os.path.abspath(os.path.dirname(configmix.__file__)),
-    "..",
-    "tests",
-    "data")
-
 cfg = configmix.load(os.path.join(TESTDATADIR, "conf_perf.py"))
 
 se = u""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/_test_context.py	Thu Jan 13 11:39:38 2022 +0100
@@ -0,0 +1,17 @@
+# -*- coding: utf-8 -*-
+r"""Automatic unittest context configuration
+
+"""
+
+import sys
+import os
+
+sys.path.insert(
+    0,
+    os.path.abspath(
+        os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))))
+
+
+TESTDATADIR = os.path.join(
+    os.path.abspath(os.path.dirname(__file__)),
+    "data")
--- a/tests/test.py	Wed Jan 12 13:44:12 2022 +0100
+++ b/tests/test.py	Thu Jan 13 11:39:38 2022 +0100
@@ -1,15 +1,11 @@
 # -*- coding: utf-8 -*-
 
-import sys
-import os
 import unittest
 import platform
 import io
+import os
 
-sys.path.insert(
-    0,
-    os.path.abspath(
-        os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))))
+from _test_context import TESTDATADIR
 
 import configmix
 import configmix.ini
@@ -21,11 +17,6 @@
 from configmix.compat import u, PY2
 
 
-TESTDATADIR = os.path.join(
-    os.path.abspath(os.path.dirname(__file__)),
-    "data")
-
-
 class T01Basic(unittest.TestCase):
 
     """Check with low-level internal interfaces"""