Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandratrapani committed Jul 30, 2024
1 parent 213f009 commit 0845258
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import pytest

import numpy as np

def test_format_byte_size():
assert format_byte_size(byte_size=12345) == "12.35KB"
Expand Down Expand Up @@ -145,6 +146,7 @@ def test_calculate_number_of_cpu_negative_value(self):
def test_is_ascending_series():
assert is_ascending_series(series=[1, 1, 1])
assert is_ascending_series(series=[1, 2, 3])
assert is_ascending_series(series=[1, np.nan, 3])
assert not is_ascending_series(series=[1, 2, 1])


Expand Down
29 changes: 29 additions & 0 deletions tests/unit_tests/test_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
check_data_orientation,
check_timestamps_match_first_dimension,
check_timestamps_ascending,
check_timestamps_with_nans,
check_missing_unit,
check_resolution,
check_timestamp_of_the_first_sample_is_not_negative,
Expand Down Expand Up @@ -226,6 +227,9 @@ def test_pass_check_timestamps_ascending_pass():
time_series = pynwb.TimeSeries(name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[1, 2, 3])
assert check_timestamps_ascending(time_series) is None

def test_pass_check_timestamps_ascending_with_nans_pass():
time_series = pynwb.TimeSeries(name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[1, np.nan, 3])
assert check_timestamps_ascending(time_series) is None

def test_check_timestamps_ascending_fail():
time_series = pynwb.TimeSeries(name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[1, 3, 2])
Expand All @@ -238,6 +242,31 @@ def test_check_timestamps_ascending_fail():
location="/",
)

def test_check_timestamps_ascending_with_nans_fail():
time_series = pynwb.TimeSeries(name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[np.nan, 3, 2])
assert check_timestamps_ascending(time_series) == InspectorMessage(
message="test_time_series timestamps are not ascending.",
importance=Importance.BEST_PRACTICE_VIOLATION,
check_function_name="check_timestamps_ascending",
object_type="TimeSeries",
object_name="test_time_series",
location="/",
)

def test_check_timestamps_with_nans_pass():
time_series = pynwb.TimeSeries(name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[1, 2, 3])
assert check_timestamps_with_nans(time_series) is None

def test_check_timestamps_with_nans_fail():
time_series = pynwb.TimeSeries(name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[np.nan, 2, 3])
assert check_timestamps_with_nans(time_series) == InspectorMessage(
message="test_time_series timestamps contain NaN values.",
importance=Importance.BEST_PRACTICE_VIOLATION,
check_function_name="check_timestamps_with_nans",
object_type="TimeSeries",
object_name="test_time_series",
location="/",
)

def test_check_timestamp_of_the_first_sample_is_not_negative_with_timestamps_fail():
time_series = pynwb.TimeSeries(name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[-1, 0, 1])
Expand Down

0 comments on commit 0845258

Please sign in to comment.