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

First draft of working refactor of wrapper mock class for tests

parent dabc8c1b
No related branches found
No related tags found
No related merge requests found
...@@ -57,14 +57,8 @@ include $(E3_REQUIRE_TOOLS)/driver.makefile ...@@ -57,14 +57,8 @@ include $(E3_REQUIRE_TOOLS)/driver.makefile
@pytest.fixture @pytest.fixture
def wrappers(tmpdir, request): def wrappers(tmpdir, request):
class WrapperFactory: class WrapperFactory:
def get(self): def get(self, **kwargs):
""" return Wrapper(tmpdir, **kwargs)
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
"""
temp_wrapper = Wrapper(tmpdir)
return temp_wrapper.path
yield WrapperFactory() yield WrapperFactory()
......
import pytest
from .utils import run_make from .utils import run_make
@pytest.mark.parametrize(
"wrappers",
[{"E3_MODULE_SRC_PATH": "test-loc"}],
indirect=True,
)
def test_loc(wrappers): def test_loc(wrappers):
wrapper = wrappers.get() wrapper = wrappers.get(E3_MODULE_SRC_PATH="test-loc")
rc, _, errs = run_make(wrapper, "build", E3_MODULE_SRC_PATH="test-loc") rc, _, errs = run_make(wrapper, "build")
assert rc == 2 assert rc == 2
assert 'Local source mode "-loc" has been deprecated' in errs assert 'Local source mode "-loc" has been deprecated' in errs
...@@ -18,7 +11,7 @@ def test_loc(wrappers): ...@@ -18,7 +11,7 @@ def test_loc(wrappers):
def test_sitelibs(wrappers): def test_sitelibs(wrappers):
# Overwrite the default makefile # Overwrite the default makefile
wrapper = wrappers.get() wrapper = wrappers.get()
with open(wrapper / "Makefile", "w") as f: with open(wrapper.path / "Makefile", "w") as f:
f.write( f.write(
""" """
TOP:=$(CURDIR) TOP:=$(CURDIR)
...@@ -40,8 +33,9 @@ include $(REQUIRE_CONFIG)/RULES_DEV ...@@ -40,8 +33,9 @@ include $(REQUIRE_CONFIG)/RULES_DEV
def test_incorrect_module_name(wrappers): def test_incorrect_module_name(wrappers):
wrapper = wrappers.get()
module_name = "ADCore" module_name = "ADCore"
wrapper = wrappers.get(name=module_name)
rc, _, errs = run_make(wrapper, "build", E3_MODULE_NAME=module_name) rc, _, errs = run_make(wrapper, "build", E3_MODULE_NAME=module_name)
assert rc == 2 assert rc == 2
assert f"E3_MODULE_NAME '{module_name}' is not valid" in errs assert f"E3_MODULE_NAME '{module_name}' is not valid" in errs
...@@ -40,14 +40,14 @@ def set_env_vars(env: dict) -> dict: ...@@ -40,14 +40,14 @@ def set_env_vars(env: dict) -> dict:
return env return env
def run_make(path, *args, **kwargs): def run_make(wrapper, *args, **kwargs):
""" """
Attempt to run `make <args>` in the specified path with <kwargs> as environment variables Attempt to run `make <args>` in the specified path with <kwargs> as environment variables
""" """
test_env = set_env_vars(os.environ.copy()) test_env = set_env_vars(os.environ.copy())
for kw in kwargs: for kw in kwargs:
test_env[kw] = kwargs[kw] test_env[kw] = kwargs[kw]
make_cmd = ["make", "-C", path] + list(args) make_cmd = ["make", "-C", wrapper.path] + list(args)
p = subprocess.Popen( p = subprocess.Popen(
make_cmd, make_cmd,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
...@@ -59,11 +59,11 @@ def run_make(path, *args, **kwargs): ...@@ -59,11 +59,11 @@ def run_make(path, *args, **kwargs):
return p.returncode, outs, errs return p.returncode, outs, errs
def get_env_var(path, var: str): def get_env_var(wrapper, var: str):
""" """
Fetch an environment variable from the module build environment Fetch an environment variable from the module build environment
""" """
_, out, _ = run_make(path, "cellvars") _, out, _ = run_make(wrapper, "cellvars")
for line in out.split("\n"): for line in out.split("\n"):
if line.startswith(var): if line.startswith(var):
return line.split("=")[1].strip() return line.split("=")[1].strip()
......
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