From 43c8d08c5bd33ccf6d4dfd8f72204e03c2ad9fd5 Mon Sep 17 00:00:00 2001 From: Tamas Gal <tgal@km3net.de> Date: Tue, 29 Sep 2020 23:54:28 +0200 Subject: [PATCH] Restructure tests --- km3io/tools.py | 2 +- tests/test_tools.py | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/km3io/tools.py b/km3io/tools.py index d6cff15..69e8806 100644 --- a/km3io/tools.py +++ b/km3io/tools.py @@ -316,7 +316,7 @@ def best_track(tracks, strategy="default", rec_type=None): out = tracks[:, 0] if strategy == "default" and rec_type is None: - raise KeyError( + raise ValueError( "rec_type must be provided when the default strategy is used.") if strategy == "default" and rec_type is not None: diff --git a/tests/test_tools.py b/tests/test_tools.py index 2bd8984..2792228 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -58,8 +58,7 @@ class TestBestTrack(unittest.TestCase): self.events = OFFLINE_FILE.events self.one_event = OFFLINE_FILE.events[0] - def test_best_tracks(self): - # test selection from multiple events + def test_best_track_from_multiple_events(self): events = self.events[self.events.n_tracks > 0] first_tracks = best_track(events.tracks, strategy="first") default_best = best_track(events.tracks, @@ -73,7 +72,7 @@ class TestBestTrack(unittest.TestCase): assert default_best.lik[1] == ak.max(events.tracks.lik[1]) assert default_best.rec_type[0] == 4000 - # test selection from one event + def test_best_track_from_a_single_event(self): first_track = best_track(self.one_event.tracks, strategy="first") best = best_track(self.one_event.tracks, strategy="default", @@ -85,13 +84,13 @@ class TestBestTrack(unittest.TestCase): assert best.lik == ak.max(self.one_event.tracks.lik) assert best.rec_type == 4000 - # test raising ValueError + def test_best_track_raises_when_unknown_strategy(self): with self.assertRaises(ValueError): - best_track(events.tracks, strategy="Zineb") + best_track(self.events.tracks, strategy="Zineb") - # test raising KeyError - with self.assertRaises(KeyError): - best_track(events.tracks) + def test_best_track_raises_when_default_strategy_and_no_rectype(self): + with self.assertRaises(ValueError): + best_track(self.events.tracks) class TestGetMultiplicity(unittest.TestCase): -- GitLab