Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Elisa-Visentin committed Oct 9, 2023
1 parent 27c7e0c commit 85b393f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 25 deletions.
25 changes: 5 additions & 20 deletions magicctapipe/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def temp_DL1_gamma(tmp_path_factory):
return tmp_path_factory.mktemp("DL1_gammas")


@pytest.fixture(scope="session")
def temp_DL1_gamma_focal_exc(tmp_path_factory):
return tmp_path_factory.mktemp("DL1_gammas_focal_exc")


@pytest.fixture(scope="session")
def temp_DL1_gamma_train(tmp_path_factory):
return tmp_path_factory.mktemp("DL1_gamma_train")
Expand Down Expand Up @@ -904,26 +909,6 @@ def coincidence(dl1_lst, merge_magic, temp_coinc, config):
return temp_coinc


@pytest.fixture(scope="session")
def coincidence_preoffset(dl1_lst, merge_magic, temp_coinc_preoff, config_preoff):
"""
Coincidence
"""

for file in dl1_lst:
subprocess.run(
[
"lst1_magic_event_coincidence",
f"-l{str(file)}",
f"-m{str(merge_magic)}",
f"-o{str(temp_coinc_preoff)}",
f"-c{str(config_preoff)}",
]
)

return temp_coinc_preoff


@pytest.fixture(scope="session")
def coincidence_stereo(coincidence, temp_coinc_stereo, config):
"""
Expand Down
5 changes: 0 additions & 5 deletions magicctapipe/io/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,6 @@ def test_load_magic_dl1_data_files_exc(temp_DL1_M_exc, config_gen):
_, _ = load_magic_dl1_data_files(str(temp_DL1_M_exc), config_gen)


def test_coinc_preoffset(coincidence_preoffset):
"""Check pre-offset search option"""
assert len(glob.glob(f"{coincidence_preoffset}/*.h5"))>0


def test_get_stereo_events_data(coincidence_stereo, config_gen):
"""
Check on stereo data reading
Expand Down
53 changes: 53 additions & 0 deletions magicctapipe/scripts/lst1_magic/tests/test_coincidence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import subprocess
import pytest
import glob


def test_coincidence_preoffset(dl1_lst, merge_magic, temp_coinc_preoff, config_preoff):
"""
Coincidence pre-offset option
"""

for file in dl1_lst:
out = subprocess.run(
[
"lst1_magic_event_coincidence",
f"-l{str(file)}",
f"-m{str(merge_magic)}",
f"-o{str(temp_coinc_preoff)}",
f"-c{str(config_preoff)}",
]
)
if out.returncode != 0:
raise ValueError(

Check warning on line 22 in magicctapipe/scripts/lst1_magic/tests/test_coincidence.py

View check run for this annotation

Codecov / codecov/patch

magicctapipe/scripts/lst1_magic/tests/test_coincidence.py#L22

Added line #L22 was not covered by tests
f"Coincidence script with pre-offset option failed with return code {out.returncode} for file {file}"
)

assert len(glob.glob(f"{temp_coinc_preoff}/*.h5"))==1


def test_coincidence(dl1_lst, merge_magic, temp_coinc, config):
"""
Coincidence
"""

for file in dl1_lst:
out = subprocess.run(
[
"lst1_magic_event_coincidence",
f"-l{str(file)}",
f"-m{str(merge_magic)}",
f"-o{str(temp_coinc)}",
f"-c{str(config)}",
]
)
if out.returncode != 0:
raise ValueError(

Check warning on line 45 in magicctapipe/scripts/lst1_magic/tests/test_coincidence.py

View check run for this annotation

Codecov / codecov/patch

magicctapipe/scripts/lst1_magic/tests/test_coincidence.py#L45

Added line #L45 was not covered by tests
f"Coincidence script failed with return code {out.returncode} for file {file}"
)

assert len(glob.glob(f"{temp_coinc}/*.h5"))==1




46 changes: 46 additions & 0 deletions magicctapipe/scripts/lst1_magic/tests/test_mc_dl0_dl1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import subprocess
import pytest
import glob


def test_mc_dl0_dl1(temp_DL1_gamma, dl0_gamma, config):
"""
MC DL0 to DL1
"""

for file in dl0_gamma:
out=subprocess.run(
[
"lst1_magic_mc_dl0_to_dl1",
f"-i{str(file)}",
f"-o{str(temp_DL1_gamma)}",
f"-c{str(config)}",
]
)

if out.returncode != 0:
raise ValueError(

Check warning on line 22 in magicctapipe/scripts/lst1_magic/tests/test_mc_dl0_dl1.py

View check run for this annotation

Codecov / codecov/patch

magicctapipe/scripts/lst1_magic/tests/test_mc_dl0_dl1.py#L22

Added line #L22 was not covered by tests
f"MC DL0 to DL1 script failed with return code {out.returncode} for file {file}"
)

assert len(glob.glob(f"{temp_DL1_gamma}/*.h5"))>0


def test_mc_dl0_dl1_focal_exc(temp_DL1_gamma_focal_exc, dl0_gamma, config):
"""
MC DL0 to DL1 focal length exception
"""

for file in dl0_gamma:
out=subprocess.run(
[
"lst1_magic_mc_dl0_to_dl1",
f"-i{str(file)}",
f"-o{str(temp_DL1_gamma_focal_exc)}",
f"-c{str(config)}",
"-f abc",
]
)
assert len(glob.glob(f"{temp_DL1_gamma_focal_exc}/*.h5"))==0


0 comments on commit 85b393f

Please sign in to comment.