Skip to content
Snippets Groups Projects
Commit a34932b0 authored by Simon Rose's avatar Simon Rose
Browse files

Rough refactor of test framework started, need at least two wrappers for this scenario

parent cf66e6d1
No related branches found
No related tags found
No related merge requests found
......@@ -7,34 +7,36 @@ from .utils import TEST_MODULE_NAME
@pytest.fixture
def wrapper(tmpdir, request):
"""
Sets up a wrapper with the minimal necessary configuration in order to build a module
Note that a number of necessary variables are expected to be present in the environment
"""
try:
params = request.param
except AttributeError:
params = {}
wrapper_dir = Path(tmpdir / "wrapper")
TEST_MODULE_PATH = (
TEST_MODULE_NAME
if "E3_MODULE_SRC_PATH" not in params
else params["E3_MODULE_SRC_PATH"]
)
test_dir = wrapper_dir / TEST_MODULE_PATH
test_dir.mkdir(parents=True)
config_file = """
def wrappers(tmpdir, request):
class WrapperFactory:
def get(self):
"""
Sets up a wrapper with the minimal necessary configuration in order to build a module
Note that a number of necessary variables are expected to be present in the environment
"""
try:
params = request.param
except AttributeError:
params = {}
wrapper_dir = Path(tmpdir / "wrapper")
TEST_MODULE_PATH = (
TEST_MODULE_NAME
if "E3_MODULE_SRC_PATH" not in params
else params["E3_MODULE_SRC_PATH"]
)
test_dir = wrapper_dir / TEST_MODULE_PATH
test_dir.mkdir(parents=True)
config_file = """
TOP:=$(CURDIR)
include $(REQUIRE_CONFIG)/CONFIG
include $(REQUIRE_CONFIG)/RULES_SITEMODS
"""
module_makefile = """
module_makefile = """
where_am_I := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
include $(E3_REQUIRE_TOOLS)/driver.makefile
......@@ -44,16 +46,24 @@ DBDS += {dbds}
HEADERS += {headers}
"""
# TODO: This should not be necessary, but it is for patching.
Repo.init(wrapper_dir)
with open(wrapper_dir / "Makefile", "w") as f:
f.write(config_file)
# TODO: This should not be necessary, but it is for patching.
Repo.init(wrapper_dir)
with open(wrapper_dir / "Makefile", "w") as f:
f.write(config_file)
make_vars = {"templates": "", "sources": "", "dbds": "", "headers": ""}
make_vars.update(**params)
with open(wrapper_dir / f"{TEST_MODULE_NAME}.Makefile", "w") as f:
f.write(module_makefile.format(**make_vars))
make_vars = {"templates": "", "sources": "", "dbds": "", "headers": ""}
make_vars.update(**params)
with open(wrapper_dir / f"{TEST_MODULE_NAME}.Makefile", "w") as f:
f.write(module_makefile.format(**make_vars))
with open(wrapper_dir / TEST_MODULE_PATH / "test.dbd", "w") as f:
pass
with open(wrapper_dir / TEST_MODULE_PATH / "test.dbd", "w") as f:
pass
yield wrapper_dir
return wrapper_dir
yield WrapperFactory()
@pytest.fixture
def wrapper(wrappers):
yield wrappers.get()
......@@ -35,11 +35,12 @@ def create_patch_file(path, desc):
@pytest.mark.parametrize(
"wrapper",
"wrappers",
[{"templates": "database.db"}],
indirect=True,
)
def test_patch(wrapper):
def test_patch(wrappers):
wrapper = wrappers.get()
db_path = wrapper / TEST_MODULE_NAME / "database.db"
with open(db_path, "w") as f:
f.write(DB_FILE)
......@@ -106,6 +107,7 @@ def test_missing_source_file(wrapper):
def test_missing_requirement(wrapper):
print(wrapper)
with open(wrapper / f"{TEST_MODULE_NAME}.Makefile", "a") as f:
f.write("REQUIRED += foo")
......
......@@ -4,18 +4,20 @@ from .utils import run_make
@pytest.mark.parametrize(
"wrapper",
"wrappers",
[{"E3_MODULE_SRC_PATH": "test-loc"}],
indirect=True,
)
def test_loc(wrapper):
def test_loc(wrappers):
wrapper = wrappers.get()
rc, _, errs = run_make(wrapper, "build", E3_MODULE_SRC_PATH="test-loc")
assert rc == 2
assert 'Local source mode "-loc" has been deprecated' in errs
def test_sitelibs(wrapper):
def test_sitelibs(wrappers):
# Overwrite the default makefile
wrapper = wrappers.get()
with open(wrapper / "Makefile", "w") as f:
f.write(
"""
......@@ -37,7 +39,8 @@ include $(REQUIRE_CONFIG)/RULES_DEV
assert "RULES_E3 should only be loaded from RULES_SITEMODS" in errs
def test_incorrect_module_name(wrapper):
def test_incorrect_module_name(wrappers):
wrapper = wrappers.get()
module_name = "ADCore"
rc, _, errs = run_make(wrapper, "build", E3_MODULE_NAME=module_name)
assert rc == 2
......
......@@ -9,7 +9,7 @@ RE_MODULE_NOT_LOADED = f"Module {TEST_MODULE_NAME} (not available|version {{requ
@pytest.mark.parametrize(
"wrapper",
"wrappers",
[{"templates": "", "sources": "", "dbds": "test.dbd", "headers": ""}],
indirect=True,
)
......@@ -39,7 +39,8 @@ RE_MODULE_NOT_LOADED = f"Module {TEST_MODULE_NAME} (not available|version {{requ
("", "0.1.0+0", ["0.1.0", "1.0.0-rc1"]),
],
)
def test_version(wrapper, requested, expected, installed):
def test_version(wrappers, requested, expected, installed):
wrapper = wrappers.get()
for version in installed:
returncode, _, _ = run_make(
wrapper,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment