From b929194e4228e9818784cd886e1a26f7ad27440b Mon Sep 17 00:00:00 2001 From: Jack Rosenthal Date: Wed, 20 Apr 2022 13:09:39 -0600 Subject: [PATCH] tests: Move tests out of kajiki package This fixes #64. --- .flake8 | 2 +- kajiki/tests/data/__init__.py | 0 tests/conftest.py | 25 +++++++++++++++++++ {kajiki/tests => tests/data}/__init__.py | 0 {kajiki/tests => tests}/data/debug.html | 0 {kajiki/tests => tests}/data/debug.txt | 0 {kajiki/tests => tests}/data/error.html | 0 {kajiki/tests => tests}/data/file_child.html | 0 {kajiki/tests => tests}/data/file_parent.html | 0 .../data/golden/kitchensink1.html | 0 {kajiki/tests => tests}/data/kitchensink.html | 0 {kajiki/tests => tests}/data/simple.html | 0 {kajiki/tests => tests}/test_cli.py | 0 {kajiki/tests => tests}/test_doctype.py | 0 {kajiki/tests => tests}/test_e2e.py | 2 +- {kajiki/tests => tests}/test_ir.py | 0 {kajiki/tests => tests}/test_runtime.py | 0 {kajiki/tests => tests}/test_text.py | 0 {kajiki/tests => tests}/test_xml.py | 2 +- 19 files changed, 28 insertions(+), 3 deletions(-) delete mode 100644 kajiki/tests/data/__init__.py create mode 100644 tests/conftest.py rename {kajiki/tests => tests/data}/__init__.py (100%) rename {kajiki/tests => tests}/data/debug.html (100%) rename {kajiki/tests => tests}/data/debug.txt (100%) rename {kajiki/tests => tests}/data/error.html (100%) rename {kajiki/tests => tests}/data/file_child.html (100%) rename {kajiki/tests => tests}/data/file_parent.html (100%) rename {kajiki/tests => tests}/data/golden/kitchensink1.html (100%) rename {kajiki/tests => tests}/data/kitchensink.html (100%) rename {kajiki/tests => tests}/data/simple.html (100%) rename {kajiki/tests => tests}/test_cli.py (100%) rename {kajiki/tests => tests}/test_doctype.py (100%) rename {kajiki/tests => tests}/test_e2e.py (94%) rename {kajiki/tests => tests}/test_ir.py (100%) rename {kajiki/tests => tests}/test_runtime.py (100%) rename {kajiki/tests => tests}/test_text.py (100%) rename {kajiki/tests => tests}/test_xml.py (99%) diff --git a/.flake8 b/.flake8 index 3c50b42..9d2596c 100644 --- a/.flake8 +++ b/.flake8 @@ -11,4 +11,4 @@ exclude = per-file-ignores = # This file uses names from Kajiki's IR language, and confuses # flake8: - kajiki/tests/test_runtime.py: F821 + tests/test_runtime.py: F821 diff --git a/kajiki/tests/data/__init__.py b/kajiki/tests/data/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..194607a --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,25 @@ +import importlib +import pathlib +import sys + +import pytest + + +@pytest.fixture(scope="session", autouse=True) +def add_test_data_module(): + here = pathlib.Path(__file__).parent + data_package = here / "data" / "__init__.py" + spec = importlib.util.spec_from_file_location("kajiki_test_data", str(data_package)) + + # TODO(Python3.4): below dance can change to + # importlib.util.module_from_spec() when support for Python 3.4 is + # dropped. + module = type(sys)(spec.name) + module.__name__ = spec.name + module.__loader__ = spec.loader + module.__package__ = spec.parent + module.__path__ = spec.submodule_search_locations + module.__file__ = spec.origin + + sys.modules[spec.name] = module + spec.loader.exec_module(module) diff --git a/kajiki/tests/__init__.py b/tests/data/__init__.py similarity index 100% rename from kajiki/tests/__init__.py rename to tests/data/__init__.py diff --git a/kajiki/tests/data/debug.html b/tests/data/debug.html similarity index 100% rename from kajiki/tests/data/debug.html rename to tests/data/debug.html diff --git a/kajiki/tests/data/debug.txt b/tests/data/debug.txt similarity index 100% rename from kajiki/tests/data/debug.txt rename to tests/data/debug.txt diff --git a/kajiki/tests/data/error.html b/tests/data/error.html similarity index 100% rename from kajiki/tests/data/error.html rename to tests/data/error.html diff --git a/kajiki/tests/data/file_child.html b/tests/data/file_child.html similarity index 100% rename from kajiki/tests/data/file_child.html rename to tests/data/file_child.html diff --git a/kajiki/tests/data/file_parent.html b/tests/data/file_parent.html similarity index 100% rename from kajiki/tests/data/file_parent.html rename to tests/data/file_parent.html diff --git a/kajiki/tests/data/golden/kitchensink1.html b/tests/data/golden/kitchensink1.html similarity index 100% rename from kajiki/tests/data/golden/kitchensink1.html rename to tests/data/golden/kitchensink1.html diff --git a/kajiki/tests/data/kitchensink.html b/tests/data/kitchensink.html similarity index 100% rename from kajiki/tests/data/kitchensink.html rename to tests/data/kitchensink.html diff --git a/kajiki/tests/data/simple.html b/tests/data/simple.html similarity index 100% rename from kajiki/tests/data/simple.html rename to tests/data/simple.html diff --git a/kajiki/tests/test_cli.py b/tests/test_cli.py similarity index 100% rename from kajiki/tests/test_cli.py rename to tests/test_cli.py diff --git a/kajiki/tests/test_doctype.py b/tests/test_doctype.py similarity index 100% rename from kajiki/tests/test_doctype.py rename to tests/test_doctype.py diff --git a/kajiki/tests/test_e2e.py b/tests/test_e2e.py similarity index 94% rename from kajiki/tests/test_e2e.py rename to tests/test_e2e.py index aa11c87..42b3461 100644 --- a/kajiki/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -13,7 +13,7 @@ @pytest.mark.parametrize( ["args", "golden_file"], [ - (["-p", "kajiki.tests.data.kitchensink"], "kitchensink1.html"), + (["-p", "kajiki_test_data.kitchensink"], "kitchensink1.html"), ([str(DATA / "kitchensink.html")], "kitchensink1.html"), ], ) diff --git a/kajiki/tests/test_ir.py b/tests/test_ir.py similarity index 100% rename from kajiki/tests/test_ir.py rename to tests/test_ir.py diff --git a/kajiki/tests/test_runtime.py b/tests/test_runtime.py similarity index 100% rename from kajiki/tests/test_runtime.py rename to tests/test_runtime.py diff --git a/kajiki/tests/test_text.py b/tests/test_text.py similarity index 100% rename from kajiki/tests/test_text.py rename to tests/test_text.py diff --git a/kajiki/tests/test_xml.py b/tests/test_xml.py similarity index 99% rename from kajiki/tests/test_xml.py rename to tests/test_xml.py index 5049c1c..73cb748 100644 --- a/kajiki/tests/test_xml.py +++ b/tests/test_xml.py @@ -1006,7 +1006,7 @@ def test_debug(self): class TestPackageLoader(TestCase): def test_pkg_loader(self): loader = PackageLoader() - loader.import_("kajiki.tests.data.debug") + loader.import_("kajiki_test_data.debug") class TestBuiltinFunctions(TestCase):