Skip to content

Commit 91d0b38

Browse files
Handle instruments: null at waypoints (#300)
* handle null for instruments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add test that empty list and null are equivalent and return no time * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent fcd130c commit 91d0b38

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/virtualship/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,9 @@ def _calc_wp_stationkeeping_time(
619619
"""For a given waypoint (and the instruments present at this waypoint), calculate how much time is required to carry out all instrument deployments."""
620620
from virtualship.instruments.types import InstrumentType # avoid circular imports
621621

622-
assert isinstance(wp_instrument_types, list), (
623-
"waypoint instruments must be provided as a list, even if empty."
624-
)
622+
# to empty list if wp instruments set to 'null'
623+
if not wp_instrument_types:
624+
wp_instrument_types = []
625625

626626
# TODO: this can be removed if/when CTD and CTD_BGC are merged to a single instrument
627627
both_ctd_and_bgc = (

tests/test_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,16 @@ class DrifterConfig:
347347
assert stationkeeping_time_xbt == datetime.timedelta(0), (
348348
"XBT should have zero stationkeeping time"
349349
)
350+
351+
352+
def test_calc_wp_stationkeeping_time_no_instruments(expedition):
353+
"""Test calc_wp_stationkeeping_time handles no instruments, either marked as 'null' or empty list."""
354+
stationkeeping_emptylist = _calc_wp_stationkeeping_time(
355+
[], expedition.instruments_config
356+
)
357+
stationkeeping_null = _calc_wp_stationkeeping_time(
358+
None, expedition.instruments_config
359+
) # "null" in YAML translates to None in Python
360+
361+
assert stationkeeping_null == stationkeeping_emptylist # are equivalent
362+
assert stationkeeping_null == datetime.timedelta(0) # at least one is 0 time

0 commit comments

Comments
 (0)