Skip to content
Snippets Groups Projects
Commit 608ac19b authored by Stefan Reck's avatar Stefan Reck
Browse files

add tests

parent eba0a084
No related branches found
No related tags found
1 merge request!20Parser
# the mode to run orcasong in; either 'graph' or 'image' # the mode to run orcasong in; either 'graph' or 'image'
mode="graph" mode="graph"
# arguments for running orcasong (see FileGraph or FileBinner in orcasong.core). # arguments for FileGraph or FileBinner (see orcasong.core)
max_n_hits = 2000 max_n_hits = 2000
time_window = [-100, 5000] time_window = [-100, 5000]
# can also give the arguments of orcasong.core.BaseProcessor,
# which are shared between modes
chunksize=16
# built-in extractor function to use # built-in extractor function to use
extractor = "neutrino_mc" extractor = "neutrino_mc"
......
import os
import toml import toml
import orcasong.core import orcasong.core
import orcasong.extractors as extractors import orcasong.extractors as extractors
...@@ -31,15 +30,17 @@ def add_parser_run(subparsers): ...@@ -31,15 +30,17 @@ def add_parser_run(subparsers):
def run_orcasong(infile, toml_file, detx_file=None, outfile=None): def run_orcasong(infile, toml_file, detx_file=None, outfile=None):
if outfile is None: setup_processor(infile, toml_file, detx_file).run(
outfile = f"{os.path.splitext(os.path.basename(infile))[0]}_dl.h5" infile=infile, outfile=outfile)
def setup_processor(infile, toml_file, detx_file=None):
cfg = toml.load(toml_file) cfg = toml.load(toml_file)
processor = _get_verbose(cfg["mode"], MODES) processor = _get_verbose(cfg.pop("mode"), MODES)
if "detx_file" in cfg: if "detx_file" in cfg:
if detx_file is not None: if detx_file is not None:
raise ValueError("detx_file passed to function AND defined in toml") raise ValueError("detx_file passed to run AND defined in toml")
detx_file = cfg.pop("detx_file") detx_file = cfg.pop("detx_file")
if "extractor" in cfg: if "extractor" in cfg:
...@@ -48,11 +49,11 @@ def run_orcasong(infile, toml_file, detx_file=None, outfile=None): ...@@ -48,11 +49,11 @@ def run_orcasong(infile, toml_file, detx_file=None, outfile=None):
else: else:
extractor = None extractor = None
processor( return processor(
det_file=detx_file, det_file=detx_file,
extractor=extractor, extractor=extractor,
**cfg, **cfg,
).run(infile=infile, outfile=outfile) )
def _get_verbose(key, d): def _get_verbose(key, d):
......
from unittest import TestCase
import os
import orcasong
import orcasong.from_toml as from_toml
EXAMPLES = os.path.join(
os.path.dirname(os.path.dirname(orcasong.__file__)), "examples"
)
def test_extr(infile):
return infile + "_extr"
orcasong.from_toml.EXTRACTORS["neutrino_mc"] = test_extr
class TestSetupProcessorExampleConfig(TestCase):
def setUp(self):
self.processor = from_toml.setup_processor(
infile="test_in",
toml_file=os.path.join(EXAMPLES, "orcasong_example.toml"),
detx_file="test_det",
)
def test_time_window(self):
self.assertEqual(self.processor.time_window, [-100, 5000])
def test_max_n_hits(self):
self.assertEqual(self.processor.max_n_hits, 2000)
def test_chunksize(self):
self.assertEqual(self.processor.chunksize, 16)
def test_extractor_is_dummy_extractor(self):
self.assertEqual(self.processor.extractor, "test_in_extr")
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