From d6d26aa8e08ec1e44bc45f9c6e39cb03ba2a71f7 Mon Sep 17 00:00:00 2001 From: Dominik Neise Date: Fri, 11 May 2018 13:28:15 +0200 Subject: [PATCH 1/2] add test regarding event_ids and close files --- protozfits/tests/test_R1_example_file.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/protozfits/tests/test_R1_example_file.py b/protozfits/tests/test_R1_example_file.py index f6cd53f..6ee13c9 100644 --- a/protozfits/tests/test_R1_example_file.py +++ b/protozfits/tests/test_R1_example_file.py @@ -15,7 +15,8 @@ def test_can_open_file(): from protozfits import SimpleFile - SimpleFile(example_file_path) + f = SimpleFile(example_file_path) + f.close() def test_can_iterate_over_events_and_run_header(): @@ -30,3 +31,11 @@ def test_can_iterate_over_events_and_run_header(): assert event.pixel_status.shape == (14,) assert event.lstcam.first_capacitor_id.shape == (16,) assert event.lstcam.counters.shape == (44,) + f.close() + +def test_event_ids(): + from protozfits import SimpleFile + with SimpleFile(example_file_path) as f: + event_ids = [e.event_id for e in f.Events] + + assert (np.array(event_ids) == 1 + np.arange(len(event_ids))).all() From 341b43160bcb7007db75ed05300ebdbcc5d97459 Mon Sep 17 00:00:00 2001 From: Dominik Neise Date: Fri, 11 May 2018 13:59:40 +0200 Subject: [PATCH 2/2] remove one boring test, add test for event_ids into can_iterate --- protozfits/tests/test_R1_example_file.py | 34 ++++++++---------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/protozfits/tests/test_R1_example_file.py b/protozfits/tests/test_R1_example_file.py index 6ee13c9..778a314 100644 --- a/protozfits/tests/test_R1_example_file.py +++ b/protozfits/tests/test_R1_example_file.py @@ -1,8 +1,9 @@ - import numpy as np import pkg_resources import os +from protozfits import SimpleFile + example_file_path = pkg_resources.resource_filename( 'protozfits', os.path.join( @@ -13,29 +14,16 @@ ) -def test_can_open_file(): - from protozfits import SimpleFile - f = SimpleFile(example_file_path) - f.close() - - def test_can_iterate_over_events_and_run_header(): - from protozfits import SimpleFile - f = SimpleFile(example_file_path) - camera_config = next(f.CameraConfig) - assert (camera_config.expected_pixels_id == np.arange(14)).all() - - for event in f.Events: - assert event.waveform.shape == (1120,) - assert event.pixel_status.shape == (14,) - assert event.lstcam.first_capacitor_id.shape == (16,) - assert event.lstcam.counters.shape == (44,) - f.close() - -def test_event_ids(): - from protozfits import SimpleFile with SimpleFile(example_file_path) as f: - event_ids = [e.event_id for e in f.Events] - assert (np.array(event_ids) == 1 + np.arange(len(event_ids))).all() + camera_config = next(f.CameraConfig) + assert (camera_config.expected_pixels_id == np.arange(14)).all() + + for i, event in enumerate(f.Events): + assert event.event_id == i + 1 + assert event.waveform.shape == (1120,) + assert event.pixel_status.shape == (14,) + assert event.lstcam.first_capacitor_id.shape == (16,) + assert event.lstcam.counters.shape == (44,)