Skip to content
Snippets Groups Projects
Commit 559cdfc1 authored by Anders Lindh Olsson's avatar Anders Lindh Olsson :8ball:
Browse files

Add tests for make init

parent 9bbf8ed0
No related branches found
No related tags found
1 merge request!204E3-1746: Add tests for init and clean targets
......@@ -63,6 +63,8 @@ test require:
stage: test
before_script:
- source $(pwd)/epics/base-*/require/*/bin/activate
# We need to allow file:// protocol for all of the tests to work
- git config --global procotol.file.allow always
script:
- make test
needs:
......
......@@ -17,9 +17,3 @@ def test_warning_msg_if_building_from_sitemods(wrapper):
assert (
"It is ill-advised to build a module from the module install location." in errs
)
def test_info_msg_if_local_mode(wrapper):
rc, outs, _ = wrapper.run_make("init")
assert rc == 0
assert "You are in the local source mode" in outs
import shutil
import subprocess
import pytest
def set_up_git_submodule(main, sub) -> None:
# remove local dir with dbd-file and add fake repo as submodule
shutil.rmtree(main.module_dir)
subprocess.run(
["git", "init"],
cwd=main.wrapper_dir,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
# we allow file:// as protocol in order to not get a fatal error like
# fatal: transport 'file' not allowed
# see https://lore.kernel.org/git/000001d91c8b$6a26cd60$3e746820$@nexbridge.com/T/
subprocess.run(
[
"git",
"-c",
"protocol.file.allow=always",
"submodule",
"add",
f"file://{sub.module_dir.as_posix()}",
main.name,
],
cwd=main.wrapper_dir,
)
main.write_var_to_makefile(
main.config_module,
"EPICS_MODULE_TAG",
"fake-tag",
)
def test_error_if_epics_module_tag_set_but_no_submodule(wrapper):
wrapper.write_var_to_makefile(
wrapper.config_module,
"EPICS_MODULE_TAG",
"whatever",
)
rc, _, stderr = wrapper.run_make("init")
assert rc != 0
assert stderr
@pytest.mark.skipif(
subprocess.run(
["git", "config", "get", "protocol.file.allow"], stdout=subprocess.PIPE
)
.stdout.decode()
.strip()
!= "always",
reason="file protocol must be allowed",
)
def test_init_inits_without_error_if_defined(wrapper, module):
set_up_git_submodule(wrapper, module)
rc, *_ = wrapper.run_make("init")
assert rc == 0
def test_init_fetches_submodule_files(wrapper, module):
set_up_git_submodule(wrapper, module)
_ = wrapper.run_make("init")
assert len(list((wrapper.wrapper_dir / wrapper.name).iterdir())) > 0
def test_init_checks_out_version_in_epics_module_tag(wrapper, module):
set_up_git_submodule(wrapper, module)
_ = wrapper.run_make("init")
res = subprocess.run(
["git", "describe", "--tags"], cwd=wrapper.module_dir, stdout=subprocess.PIPE
)
assert res.stdout.decode().strip() == "fake-tag"
def test_info_msg_if_local_mode(wrapper):
rc, outs, _ = wrapper.run_make("init")
assert rc == 0
assert "You are in the local source mode" in outs
......@@ -22,6 +22,34 @@ def wrapper(wrapper_factory):
return wrapper_factory.create()
@pytest.fixture()
def module(tmp_path):
return Module(tmp_path)
class Module:
def __init__(self, tmp_test_dir: Path):
self.name = "module-" + "".join(choice(ascii_lowercase) for _ in range(16))
self.module_dir = tmp_test_dir / self.name
self.module_dir.mkdir()
# set up fake repo
fake_file = self.module_dir / "random-file-to-commit"
fake_file.write_text("whatever")
for cmd in [
"git init",
"git add .",
"git commit -m message -q",
"git tag fake-tag",
]:
subprocess.run(
cmd.split(),
cwd=self.module_dir,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
class Wrapper:
def __init__(
self,
......
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