From 4bb5c829ca06506ecda69611a09563f1e7c3462a Mon Sep 17 00:00:00 2001 From: alessandrofelder Date: Thu, 4 Jun 2020 12:09:29 +0100 Subject: [PATCH 1/2] improve missing start_time error message --- src/silverlabnwb/nwb_file.py | 6 +++++- tests/test_metadata_import.py | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/silverlabnwb/nwb_file.py b/src/silverlabnwb/nwb_file.py index 52bb2b3..498bf74 100644 --- a/src/silverlabnwb/nwb_file.py +++ b/src/silverlabnwb/nwb_file.py @@ -125,7 +125,11 @@ def create_from_metadata(self, metadata_file, user=None, session_id=None): try: start_time = sessions[user]['start_time'] except KeyError: - raise ValueError("Start time for session not found!") + raise ValueError("Start time for session not found! " + "Please add a `start_time` parameter to sessions for user {}, " + "e.g. '10 May 2020 12:34:56.789103'" + .format(user) + ) start_time = pd.to_datetime( start_time, infer_datetime_format=True).tz_localize( timezone('Europe/London')) diff --git a/tests/test_metadata_import.py b/tests/test_metadata_import.py index 34785ed..16ecfb6 100644 --- a/tests/test_metadata_import.py +++ b/tests/test_metadata_import.py @@ -32,7 +32,10 @@ def test_no_start_time_fails(tmpdir, ref_data_dir): with pytest.raises(ValueError) as exc_info: with NwbFile(nwb_path, 'w') as nwb: nwb.create_from_metadata(meta_path, user="A") - assert "Start time for session not found!" == str(exc_info.value) + expected_error_string = "Start time for session not found! " \ + "Please add a `start_time` parameter to sessions for user A, " \ + "e.g. '10 May 2020 12:34:56.789103'" + assert expected_error_string == str(exc_info.value) def test_metadata_import_correct(tmpdir, ref_data_dir): From cdc2b401e812b3257213097b1a54f53982fb5375 Mon Sep 17 00:00:00 2001 From: alessandrofelder Date: Tue, 9 Jun 2020 08:54:09 +0100 Subject: [PATCH 2/2] simplify start_time related assertion and error addresses some review comments --- src/silverlabnwb/nwb_file.py | 2 +- tests/test_metadata_import.py | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/silverlabnwb/nwb_file.py b/src/silverlabnwb/nwb_file.py index 498bf74..c7310a4 100644 --- a/src/silverlabnwb/nwb_file.py +++ b/src/silverlabnwb/nwb_file.py @@ -127,7 +127,7 @@ def create_from_metadata(self, metadata_file, user=None, session_id=None): except KeyError: raise ValueError("Start time for session not found! " "Please add a `start_time` parameter to sessions for user {}, " - "e.g. '10 May 2020 12:34:56.789103'" + "e.g. 'start_time: 10 May 2020 12:34:56'" .format(user) ) start_time = pd.to_datetime( diff --git a/tests/test_metadata_import.py b/tests/test_metadata_import.py index 16ecfb6..4e4e54a 100644 --- a/tests/test_metadata_import.py +++ b/tests/test_metadata_import.py @@ -32,10 +32,7 @@ def test_no_start_time_fails(tmpdir, ref_data_dir): with pytest.raises(ValueError) as exc_info: with NwbFile(nwb_path, 'w') as nwb: nwb.create_from_metadata(meta_path, user="A") - expected_error_string = "Start time for session not found! " \ - "Please add a `start_time` parameter to sessions for user A, " \ - "e.g. '10 May 2020 12:34:56.789103'" - assert expected_error_string == str(exc_info.value) + assert "start_time" in str(exc_info.value) def test_metadata_import_correct(tmpdir, ref_data_dir):