Skip to content

Commit

Permalink
simplify unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RasmusOrsoe committed Sep 26, 2023
1 parent 1ca3e87 commit 2b22ce7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 126 deletions.
46 changes: 8 additions & 38 deletions tests/examples/01_icetray/test_icetray_examples.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,17 @@
"""Test for examples in 01_icetray."""
import runpy
import os
import pytest
from glob import glob

from graphnet.constants import GRAPHNET_ROOT_DIR

EXAMPLE_PATH = os.path.join(GRAPHNET_ROOT_DIR, "examples/01_icetray")


def test_01_convert_i3_files() -> None:
"""Test for 01_convert_i3_files."""
runpy.run_path(
os.path.join(EXAMPLE_PATH, "01_convert_i3_files.py"),
run_name="__main__",
)


def test_02_compare_sqlite_and_parquet() -> None:
"""Test for 02_compare_sqlite_and_parquet."""
runpy.run_path(
os.path.join(EXAMPLE_PATH, "02_compare_sqlite_and_parquet.py"),
run_name="__main__",
)


def test_03_i3_deployer_example() -> None:
"""Test for 03_i3_deployer_example."""
runpy.run_path(
os.path.join(EXAMPLE_PATH, "03_i3_deployer_example.py"),
run_name="__main__",
)


def test_04_i3_module_in_native_icetray_example() -> None:
"""Test for 04_i3_module_in_native_icetray_example."""
runpy.run_path(
os.path.join(
EXAMPLE_PATH, "04_i3_module_in_native_icetray_example.py"
),
run_name="__main__",
)
examples = glob(EXAMPLE_PATH + "/*.py")


if __name__ == "__main__":
test_01_convert_i3_files()
test_02_compare_sqlite_and_parquet()
test_03_i3_deployer_example()
test_04_i3_module_in_native_icetray_example()
@pytest.mark.parametrize("example", examples)
def test_script_execution(example: str) -> None:
"""Test function that executes example."""
runpy.run_path(os.path.join(EXAMPLE_PATH, example))
44 changes: 8 additions & 36 deletions tests/examples/02_data/test_data_examples.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,16 @@
"""Tests for examples in 02_data."""
import runpy
import os
import pytest
from glob import glob

from graphnet.constants import GRAPHNET_ROOT_DIR

EXAMPLE_PATH = os.path.join(GRAPHNET_ROOT_DIR, "examples/02_data")
examples = glob(EXAMPLE_PATH + "/*.py")


def test_01_read_dataset() -> None:
"""Test for 01_read_dataset."""
runpy.run_path(
os.path.join(EXAMPLE_PATH, "01_read_dataset.py"), run_name="__main__"
)


def test_02_plot_feature_distribution() -> None:
"""Test for 02_plot_feature_distribution."""
runpy.run_path(
os.path.join(EXAMPLE_PATH, "02_plot_feature_distributions.py"),
run_name="__main__",
)


def test_03_convert_parquet_to_sqlite() -> None:
"""Test for 03_convert_parquet_to_sqlite."""
runpy.run_path(
os.path.join(EXAMPLE_PATH, "03_convert_parquet_to_sqlite.py"),
run_name="__main__",
)


def test_04_ensemble_dataset() -> None:
"""Test for 04_ensemble_dataset."""
runpy.run_path(
os.path.join(EXAMPLE_PATH, "04_ensemble_dataset.py"),
run_name="__main__",
)


if __name__ == "__main__":
test_01_read_dataset()
test_02_plot_feature_distribution()
test_03_convert_parquet_to_sqlite()
test_04_ensemble_dataset()
@pytest.mark.parametrize("example", examples)
def test_script_execution(example: str) -> None:
"""Test function that executes example."""
runpy.run_path(os.path.join(EXAMPLE_PATH, example))
25 changes: 7 additions & 18 deletions tests/examples/03_weights/test_weights_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,15 @@
import runpy
import os
from graphnet.constants import GRAPHNET_ROOT_DIR
from glob import glob
import pytest

EXAMPLE_PATH = os.path.join(GRAPHNET_ROOT_DIR, "examples/03_weights")

examples = glob(EXAMPLE_PATH + "/*.py")

def test_01_fit_uniform_weights() -> None:
"""Test for 01_fit_uniform_weights."""
runpy.run_path(
os.path.join(EXAMPLE_PATH, "01_fit_uniform_weights.py"),
run_name="__main__",
)


def test_02_fit_bjoern_low_weights() -> None:
"""Test for 02_fit_bjoern_low_weights."""
runpy.run_path(
os.path.join(EXAMPLE_PATH, "02_fit_bjoern_low_weights.py"),
run_name="__main__",
)


if __name__ == "__main__":
test_01_fit_uniform_weights()
test_02_fit_bjoern_low_weights()
@pytest.mark.parametrize("example", examples)
def test_script_execution(example: str) -> None:
"""Test function that executes example."""
runpy.run_path(os.path.join(EXAMPLE_PATH, example))
42 changes: 8 additions & 34 deletions tests/examples/04_training/test_training_examples.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,18 @@
"""Test for examples in 04_training."""
import runpy
import os
from glob import glob
import pytest

from graphnet.constants import GRAPHNET_ROOT_DIR

EXAMPLE_PATH = os.path.join(GRAPHNET_ROOT_DIR, "examples/04_training")


def test_01_train_dynedge() -> None:
"""Test for 01_train_dynedge."""
runpy.run_path(
os.path.join(EXAMPLE_PATH, "01_train_dynedge.py"), run_name="__main__"
)


def test_02_train_tito_model() -> None:
"""Test for 02_train_tito_model."""
runpy.run_path(
os.path.join(EXAMPLE_PATH, "02_train_tito_model.py"),
run_name="__main__",
)


def test_03_train_dynedge_from_config() -> None:
"""Test for 03_train_dynedge_from_config."""
runpy.run_path(
os.path.join(EXAMPLE_PATH, "03_train_dynedge_from_config.py"),
run_name="__main__",
)


def test_04_train_multiclassifier_from_configs() -> None:
"""Test for 04_train_multiclassifier_from_configs."""
runpy.run_path(
os.path.join(EXAMPLE_PATH, "04_train_multiclassifier_from_configs.py"),
run_name="__main__",
)
examples = glob(EXAMPLE_PATH + "/*.py")


if __name__ == "__main__":
test_01_train_dynedge()
test_02_train_tito_model()
test_03_train_dynedge_from_config()
test_04_train_multiclassifier_from_configs()
@pytest.mark.parametrize("example", examples)
def test_script_execution(example: str) -> None:
"""Test function that executes example."""
runpy.run_path(os.path.join(EXAMPLE_PATH, example))

0 comments on commit 2b22ce7

Please sign in to comment.