Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to Tools to check that help message works #1034

Merged
merged 2 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions ctapipe/tools/bokeh/file_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class BokehFileViewer(Tool):
max_events='EventSource.max_events',
extractor='BokehFileViewer.extractor_product',
cleaner='BokehFileViewer.cleaner_product',
ped='TargetIOR1Calibrator.pedestal_path',
tf='TargetIOR1Calibrator.tf_path',
pe='TargetIOR1Calibrator.pe_path',
simpleintegrator_t0='SimpleIntegrator.t0',
window_width='WindowIntegrator.window_width',
window_shift='WindowIntegrator.window_shift',
Expand Down
15 changes: 5 additions & 10 deletions ctapipe/tools/extract_charge_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,16 @@ class ChargeResolutionGenerator(Tool):
window_width='WindowIntegrator.window_width',
window_shift='WindowIntegrator.window_shift',
t0='SimpleIntegrator.t0',
sig_amp_cut_HG='PeakFindngIntegrator.sig_amp_cut_HG',
sig_amp_cut_LG='PeakFindngIntegrator.sig_amp_cut_LG',
lwt='NeighbourPeakIntegrator.lwt',
clip_amplitude='CameraDL1Calibrator.clip_amplitude',
radius='CameraDL1Calibrator.radius',
max_pe='ChargeResolutionCalculator.max_pe',
O='ChargeResolutionGenerator.output_path',
))

classes = List(
[
SimTelEventSource,
CameraDL1Calibrator,
ChargeResolutionCalculator
] + tool_utils.classes_with_traits(ChargeExtractor)
)

Expand All @@ -75,20 +71,19 @@ def __init__(self, **kwargs):

def setup(self):
self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"
kwargs = dict(config=self.config, parent=self)

self.eventsource = SimTelEventSource(**kwargs)
self.eventsource = SimTelEventSource(parent=self)

extractor = ChargeExtractor.from_name(
self.extractor_product,
**kwargs
parent=self
)

self.r1 = HESSIOR1Calibrator(**kwargs)
self.r1 = HESSIOR1Calibrator(parent=self)

self.dl0 = CameraDL0Reducer(**kwargs)
self.dl0 = CameraDL0Reducer(parent=self)

self.dl1 = CameraDL1Calibrator(extractor=extractor, **kwargs)
self.dl1 = CameraDL1Calibrator(extractor=extractor, parent=self)

self.calculator = ChargeResolutionCalculator()

Expand Down
50 changes: 44 additions & 6 deletions ctapipe/tools/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,78 @@

def test_muon_reconstruction(tmpdir):
from ctapipe.tools.muon_reconstruction import MuonDisplayerTool
MuonDisplayerTool().run(
tool = MuonDisplayerTool()
tool.run(
argv=shlex.split(
f'--events={GAMMA_TEST_LARGE} '
'--max_events=2 '
)
)

with pytest.raises(SystemExit):
tool.run(['--help-all'])


def test_display_summed_imaged(tmpdir):
from ctapipe.tools.display_summed_images import ImageSumDisplayerTool
mpl.use('Agg')
ImageSumDisplayerTool().run(
tool = ImageSumDisplayerTool()
tool.run(
argv=shlex.split(
f'--infile={GAMMA_TEST_LARGE} '
'--max-events=2 '
)
)

with pytest.raises(SystemExit):
tool.run(['--help-all'])


def test_display_integrator(tmpdir):
from ctapipe.tools.display_integrator import DisplayIntegrator
mpl.use('Agg')
DisplayIntegrator().run(
tool = DisplayIntegrator()
tool.run(
argv=shlex.split(
f'--f={GAMMA_TEST_LARGE} '
'--max_events=1 '
)
)

with pytest.raises(SystemExit):
tool.run(['--help-all'])


def test_display_events_single_tel(tmpdir):
from ctapipe.tools.display_events_single_tel import SingleTelEventDisplay
mpl.use('Agg')
SingleTelEventDisplay().run(
tool = SingleTelEventDisplay()
tool.run(
argv=shlex.split(
f'--infile={GAMMA_TEST_LARGE} '
'--tel=11 '
'--max-events=2 ' # <--- inconsistent!!!
)
)

with pytest.raises(SystemExit):
tool.run(['--help-all'])


def test_display_dl1(tmpdir):
from ctapipe.tools.display_dl1 import DisplayDL1Calib
mpl.use('Agg')
DisplayDL1Calib().run(
tool = DisplayDL1Calib()
tool.run(
argv=shlex.split(
'--max_events=1 '
'--telescope=11 '
)
)

with pytest.raises(SystemExit):
tool.run(['--help-all'])


def test_info():
from ctapipe.tools.info import info
Expand All @@ -84,6 +104,9 @@ def test_dump_triggers(tmpdir):

assert outfile.exists()

with pytest.raises(SystemExit):
tool.run(['--help-all'])


def test_dump_instrument(tmpdir):
from ctapipe.tools.dump_instrument import DumpInstrumentTool
Expand All @@ -100,6 +123,9 @@ def test_dump_instrument(tmpdir):
print(tmpdir.listdir())
assert tmpdir.join('FlashCam.camgeom.fits.gz').exists()

with pytest.raises(SystemExit):
tool.run(['--help-all'])


def test_camdemo():
from ctapipe.tools.camdemo import CameraDemo
Expand All @@ -110,6 +136,9 @@ def test_camdemo():
tool.display = False
tool.run(argv=[])

with pytest.raises(SystemExit):
tool.run(['--help-all'])


def test_bokeh_file_viewer():
from ctapipe.tools.bokeh.file_viewer import BokehFileViewer
Expand All @@ -120,6 +149,9 @@ def test_bokeh_file_viewer():

assert tool.reader.input_url == get_dataset_path("gamma_test_large.simtel.gz")

with pytest.raises(SystemExit):
tool.run(['--help-all'])


def test_extract_charge_resolution(tmpdir):
from ctapipe.tools.extract_charge_resolution import (
Expand All @@ -131,11 +163,14 @@ def test_extract_charge_resolution(tmpdir):
with pytest.raises(KeyError):
tool.run([
'-f', GAMMA_TEST_LARGE,
'-o', output_path,
'-O', output_path,
])
# TODO: Test files do not contain true charge, cannot test tool fully
# assert os.path.exists(output_path)

with pytest.raises(SystemExit):
tool.run(['--help-all'])


def test_plot_charge_resolution(tmpdir):
from ctapipe.tools.plot_charge_resolution import ChargeResolutionViewer
Expand All @@ -150,3 +185,6 @@ def test_plot_charge_resolution(tmpdir):
'-o', output_path,
])
assert os.path.exists(output_path)

with pytest.raises(SystemExit):
tool.run(['--help-all'])