# HG changeset patch # User Franz Glasner # Date 1642070378 -3600 # Node ID 75ecbe07abffe65cb3c69242f4f8d6bdd9c17d01 # Parent 8dc514bd3d5e97c6e125d7b90316f0ebfd89f265 Introduct a test context to more easily switch between some unittest configurations diff -r 8dc514bd3d5e -r 75ecbe07abff tests/_perf_config.py --- 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"" diff -r 8dc514bd3d5e -r 75ecbe07abff tests/_test_context.py --- /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") diff -r 8dc514bd3d5e -r 75ecbe07abff tests/test.py --- 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"""