Skip to content

Commit 524c650

Browse files
committed
Add input_data param for testing
1 parent 18b86ec commit 524c650

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/virtualship/expedition/do_expedition.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
from .verify_schedule import verify_schedule
2020

2121

22-
def do_expedition(expedition_dir: str | Path) -> None:
22+
def do_expedition(expedition_dir: str | Path, input_data: Path | None = None) -> None:
2323
"""
2424
Perform an expedition, providing terminal feedback and file output.
2525
2626
:param expedition_dir: The base directory for the expedition.
27+
:param input_data: Input data folder folder (override used for testing).
2728
"""
2829
if isinstance(expedition_dir, str):
2930
expedition_dir = Path(expedition_dir)
@@ -51,7 +52,10 @@ def do_expedition(expedition_dir: str | Path) -> None:
5152

5253
# load fieldsets
5354
input_data = _load_input_data(
54-
expedition_dir=expedition_dir, schedule=schedule, ship_config=ship_config
55+
expedition_dir=expedition_dir,
56+
schedule=schedule,
57+
ship_config=ship_config,
58+
input_data=input_data,
5559
)
5660

5761
# verify schedule makes sense
@@ -115,13 +119,31 @@ def _get_ship_config(expedition_dir: Path) -> ShipConfig | None:
115119

116120

117121
def _load_input_data(
118-
expedition_dir: Path, schedule: Schedule, ship_config: ShipConfig
122+
expedition_dir: Path,
123+
schedule: Schedule,
124+
ship_config: ShipConfig,
125+
input_data: Path | None,
119126
) -> InputData:
120-
aoi_hash = hash_model(schedule.area_of_interest)
121-
download_directory = get_existing_download(expedition_dir, aoi_hash)
127+
"""
128+
Load the input data.
129+
130+
:param expedition_dir: Directory of the expedition.
131+
:type expedition_dir: Path
132+
:param schedule: Schedule object.
133+
:type schedule: Schedule
134+
:param ship_config: Ship configuration.
135+
:type ship_config: ShipConfig
136+
:param input_data: Folder containing input data.
137+
:type input_data: Path | None
138+
:return: InputData object.
139+
:rtype: InputData
140+
"""
141+
if input_data is None:
142+
aoi_hash = hash_model(schedule.area_of_interest)
143+
input_data = get_existing_download(expedition_dir, aoi_hash)
122144

123145
return InputData.load(
124-
directory=download_directory,
146+
directory=input_data,
125147
load_adcp=ship_config.adcp_config is not None,
126148
load_argo_float=ship_config.argo_float_config is not None,
127149
load_ctd=ship_config.ctd_config is not None,
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from pathlib import Path
2+
13
from pytest import CaptureFixture
24

35
from virtualship.expedition import do_expedition
46

57

68
def test_do_expedition(capfd: CaptureFixture) -> None:
7-
do_expedition("expedition_dir")
9+
do_expedition("expedition_dir", input_data=Path("expedition_dir/input_data"))
810
out, _ = capfd.readouterr()
911
assert "This expedition took" in out, "Expedition did not complete successfully."

0 commit comments

Comments
 (0)