Skip to content

Commit 26c33f6

Browse files
pre-commit-ci[bot]VeckoTheGecko
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 6c3b92e commit 26c33f6

File tree

6 files changed

+85
-64
lines changed

6 files changed

+85
-64
lines changed

src/virtualship/cli/_fetch.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88

99
from pydantic import BaseModel
1010

11-
from virtualship.utils import _dump_yaml, _generic_load_yaml, _get_schedule, _get_ship_config
11+
from virtualship.utils import (
12+
_dump_yaml,
13+
_generic_load_yaml,
14+
_get_schedule,
15+
_get_ship_config,
16+
)
1217

1318
if TYPE_CHECKING:
1419
from virtualship.expedition.space_time_region import SpaceTimeRegion
@@ -18,7 +23,6 @@
1823
from copernicusmarine.core_functions.credentials_utils import InvalidUsernameOrPassword
1924

2025
import virtualship.cli._creds as creds
21-
2226
from virtualship.utils import SCHEDULE
2327

2428
DOWNLOAD_METADATA = "download_metadata.yaml"
@@ -49,7 +53,7 @@ def _fetch(path: str | Path, username: str | None, password: str | None) -> None
4953
ship_config.ship_speed_knots,
5054
input_data=None,
5155
check_space_time_region=True,
52-
ignore_missing_fieldsets=True
56+
ignore_missing_fieldsets=True,
5357
)
5458

5559
space_time_region_hash = get_space_time_region_hash(schedule.space_time_region)
@@ -80,7 +84,10 @@ def _fetch(path: str | Path, username: str | None, password: str | None) -> None
8084
shutil.copyfile(path / SCHEDULE, download_folder / SCHEDULE)
8185

8286
if (
83-
({"XBT", "CTD", "SHIP_UNDERWATER_ST"} & set(instrument.name for instrument in instruments_in_schedule))
87+
(
88+
{"XBT", "CTD", "SHIP_UNDERWATER_ST"}
89+
& set(instrument.name for instrument in instruments_in_schedule)
90+
)
8491
or hasattr(ship_config, "ship_underwater_st_config")
8592
or hasattr(ship_config, "adcp_config")
8693
):

src/virtualship/cli/commands.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
from virtualship.utils import (
99
SCHEDULE,
1010
SHIP_CONFIG,
11-
_get_schedule,
12-
_get_ship_config,
1311
mfp_to_yaml,
1412
)
15-
from virtualship.utils import SCHEDULE, SHIP_CONFIG, mfp_to_yaml
1613

1714

1815
@click.command()
@@ -96,7 +93,6 @@ def fetch(path: str | Path, username: str | None, password: str | None) -> None:
9693
be provided on prompt, via command line arguments, or via a YAML config file. Run
9794
`virtualship fetch` on a expedition for more info.
9895
"""
99-
10096
_fetch(path, username, password)
10197

10298

tests/cli/test_cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ def copernicus_subset_no_download(monkeypatch):
1414
def fake_download(output_filename, output_directory, **_):
1515
Path(output_directory).joinpath(output_filename).touch()
1616

17-
monkeypatch.setattr(
18-
"virtualship.cli._fetch.copernicusmarine.subset", fake_download
19-
)
17+
monkeypatch.setattr("virtualship.cli._fetch.copernicusmarine.subset", fake_download)
2018
yield
2119

2220

tests/cli/test_fetch.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
DOWNLOAD_METADATA,
88
DownloadMetadata,
99
IncompleteDownloadError,
10+
_fetch,
1011
assert_complete_download,
1112
complete_download,
1213
create_hash,
@@ -15,17 +16,9 @@
1516
hash_model,
1617
hash_to_filename,
1718
)
18-
19-
20-
from pathlib import Path
21-
22-
import pytest
23-
24-
from virtualship.cli._fetch import _fetch
25-
from virtualship.expedition.ship_config import ShipConfig
2619
from virtualship.expedition.schedule import Schedule
27-
from virtualship.utils import get_example_schedule, get_example_config
28-
20+
from virtualship.expedition.ship_config import ShipConfig
21+
from virtualship.utils import get_example_config, get_example_schedule
2922

3023

3124
@pytest.fixture
@@ -35,9 +28,7 @@ def copernicus_subset_no_download(monkeypatch):
3528
def fake_download(output_filename, output_directory, **_):
3629
Path(output_directory).joinpath(output_filename).touch()
3730

38-
monkeypatch.setattr(
39-
"virtualship.cli._fetch.copernicusmarine.subset", fake_download
40-
)
31+
monkeypatch.setattr("virtualship.cli._fetch.copernicusmarine.subset", fake_download)
4132
yield
4233

4334

tests/expedition/test_schedule.py

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
from virtualship import Location
88
from virtualship.expedition import Waypoint
99
from virtualship.expedition.do_expedition import _load_input_data
10+
from virtualship.expedition.schedule import Schedule, ScheduleError
1011
from virtualship.utils import _get_ship_config
11-
from virtualship.expedition.schedule import ScheduleError, Schedule
12-
1312

1413
projection = pyproj.Geod(ellps="WGS84")
1514

@@ -56,81 +55,107 @@ def test_get_instruments() -> None:
5655
waypoints=[
5756
Waypoint(location=Location(0, 0), instrument=["CTD"]),
5857
Waypoint(location=Location(1, 0), instrument=["XBT", "ARGO_FLOAT"]),
59-
Waypoint(location=Location(1, 0), instrument=["CTD"])
58+
Waypoint(location=Location(1, 0), instrument=["CTD"]),
6059
]
6160
)
6261

63-
assert set(instrument.name for instrument in schedule.get_instruments()) == {"CTD", "XBT", "ARGO_FLOAT"}
62+
assert set(instrument.name for instrument in schedule.get_instruments()) == {
63+
"CTD",
64+
"XBT",
65+
"ARGO_FLOAT",
66+
}
6467

6568

6669
@pytest.mark.parametrize(
6770
"schedule,check_space_time_region,error,match",
6871
[
6972
pytest.param(
70-
Schedule(
71-
waypoints=[]
72-
),
73+
Schedule(waypoints=[]),
7374
False,
7475
ScheduleError,
7576
"At least one waypoint must be provided.",
76-
id="NoWaypoints"
77+
id="NoWaypoints",
7778
),
7879
pytest.param(
7980
Schedule(
8081
waypoints=[
8182
Waypoint(location=Location(0, 0)),
82-
Waypoint(location=Location(1, 0), time=datetime(2022, 1, 1, 1, 0, 0)),
83+
Waypoint(
84+
location=Location(1, 0), time=datetime(2022, 1, 1, 1, 0, 0)
85+
),
8386
]
8487
),
8588
False,
8689
ScheduleError,
8790
"First waypoint must have a specified time.",
88-
id="FirstWaypointHasTime"
91+
id="FirstWaypointHasTime",
8992
),
9093
pytest.param(
9194
Schedule(
9295
waypoints=[
93-
Waypoint(location=Location(0, 0), time=datetime(2022, 1, 2, 1, 0, 0)),
96+
Waypoint(
97+
location=Location(0, 0), time=datetime(2022, 1, 2, 1, 0, 0)
98+
),
9499
Waypoint(location=Location(0, 0)),
95-
Waypoint(location=Location(1, 0), time=datetime(2022, 1, 1, 1, 0, 0)),
100+
Waypoint(
101+
location=Location(1, 0), time=datetime(2022, 1, 1, 1, 0, 0)
102+
),
96103
]
97104
),
98105
False,
99106
ScheduleError,
100107
"Each waypoint should be timed after all previous waypoints",
101-
id="SequentialWaypoints"
108+
id="SequentialWaypoints",
102109
),
103110
pytest.param(
104111
Schedule(
105112
waypoints=[
106-
Waypoint(location=Location(0, 0), time=datetime(2022, 1, 1, 1, 0, 0)),
107-
Waypoint(location=Location(1, 0), time=datetime(2022, 1, 1, 1, 1, 0)),
113+
Waypoint(
114+
location=Location(0, 0), time=datetime(2022, 1, 1, 1, 0, 0)
115+
),
116+
Waypoint(
117+
location=Location(1, 0), time=datetime(2022, 1, 1, 1, 1, 0)
118+
),
108119
]
109120
),
110121
False,
111122
ScheduleError,
112123
"Waypoint planning is not valid: would arrive too late at waypoint number 2...",
113-
id="NotEnoughTime"
124+
id="NotEnoughTime",
114125
),
115126
pytest.param(
116127
Schedule(
117128
waypoints=[
118-
Waypoint(location=Location(0, 0), time=datetime(2022, 1, 1, 1, 0, 0)),
119-
Waypoint(location=Location(1, 0), time=datetime(2022, 1, 2, 1, 1, 0)),
129+
Waypoint(
130+
location=Location(0, 0), time=datetime(2022, 1, 1, 1, 0, 0)
131+
),
132+
Waypoint(
133+
location=Location(1, 0), time=datetime(2022, 1, 2, 1, 1, 0)
134+
),
120135
]
121136
),
122137
True,
123138
ScheduleError,
124139
"space_time_region not found in schedule, please define it to fetch the data.",
125-
id="NoSpaceTimeRegion"
140+
id="NoSpaceTimeRegion",
126141
),
127-
]
142+
],
128143
)
129-
def test_verify_schedule_errors(schedule: Schedule, check_space_time_region: bool, error, match) -> None:
130-
144+
def test_verify_schedule_errors(
145+
schedule: Schedule, check_space_time_region: bool, error, match
146+
) -> None:
131147
ship_config = _get_ship_config(expedition_dir)
132148

133-
input_data = _load_input_data(expedition_dir, schedule, ship_config, input_data=Path("expedition_dir/input_data"))
149+
input_data = _load_input_data(
150+
expedition_dir,
151+
schedule,
152+
ship_config,
153+
input_data=Path("expedition_dir/input_data"),
154+
)
134155

135156
with pytest.raises(error, match=match):
136-
schedule.verify(ship_config.ship_speed_knots, input_data, check_space_time_region=check_space_time_region)
157+
schedule.verify(
158+
ship_config.ship_speed_knots,
159+
input_data,
160+
check_space_time_region=check_space_time_region,
161+
)

tests/expedition/test_ship_config.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
from virtualship.expedition.schedule import Schedule
66
from virtualship.expedition.ship_config import ConfigError, ShipConfig
7-
87
from virtualship.utils import get_example_config, get_example_schedule
98

10-
119
expedition_dir = Path("expedition_dir")
1210

1311

@@ -21,8 +19,14 @@ def schedule(tmp_file):
2119
@pytest.fixture
2220
def schedule_no_xbt(schedule):
2321
for waypoint in schedule.waypoints:
24-
if waypoint.instrument and any(instrument.name == "XBT" for instrument in waypoint.instrument):
25-
waypoint.instrument = [instrument for instrument in waypoint.instrument if instrument.name != 'XBT']
22+
if waypoint.instrument and any(
23+
instrument.name == "XBT" for instrument in waypoint.instrument
24+
):
25+
waypoint.instrument = [
26+
instrument
27+
for instrument in waypoint.instrument
28+
if instrument.name != "XBT"
29+
]
2630

2731
return schedule
2832

@@ -36,25 +40,25 @@ def ship_config(tmp_file):
3640

3741
@pytest.fixture
3842
def ship_config_no_xbt(ship_config):
39-
delattr(ship_config, 'xbt_config')
43+
delattr(ship_config, "xbt_config")
4044
return ship_config
4145

4246

4347
@pytest.fixture
4448
def ship_config_no_ctd(ship_config):
45-
delattr(ship_config, 'ctd_config')
49+
delattr(ship_config, "ctd_config")
4650
return ship_config
4751

4852

4953
@pytest.fixture
5054
def ship_config_no_argo_float(ship_config):
51-
delattr(ship_config, 'argo_float_config')
55+
delattr(ship_config, "argo_float_config")
5256
return ship_config
5357

5458

5559
@pytest.fixture
5660
def ship_config_no_drifter(ship_config):
57-
delattr(ship_config, 'drifter_config')
61+
delattr(ship_config, "drifter_config")
5862
return ship_config
5963

6064

@@ -65,12 +69,10 @@ def test_import_export_ship_config(ship_config, tmp_file) -> None:
6569

6670

6771
def test_verify_ship_config(ship_config, schedule) -> None:
68-
6972
ship_config.verify(schedule)
7073

7174

7275
def test_verify_ship_config_no_instrument(ship_config, schedule_no_xbt) -> None:
73-
7476
ship_config.verify(schedule_no_xbt)
7577

7678

@@ -81,29 +83,31 @@ def test_verify_ship_config_no_instrument(ship_config, schedule_no_xbt) -> None:
8183
"ship_config_no_xbt",
8284
ConfigError,
8385
"Planning has a waypoint with XBT instrument, but configuration does not configure XBT.",
84-
id="ShipConfigNoXBT"
86+
id="ShipConfigNoXBT",
8587
),
8688
pytest.param(
8789
"ship_config_no_ctd",
8890
ConfigError,
8991
"Planning has a waypoint with CTD instrument, but configuration does not configure CTD.",
90-
id="ShipConfigNoCTD"
92+
id="ShipConfigNoCTD",
9193
),
9294
pytest.param(
9395
"ship_config_no_argo_float",
9496
ConfigError,
9597
"Planning has a waypoint with Argo float instrument, but configuration does not configure Argo floats.",
96-
id="ShipConfigNoARGO_FLOAT"
98+
id="ShipConfigNoARGO_FLOAT",
9799
),
98100
pytest.param(
99101
"ship_config_no_drifter",
100102
ConfigError,
101103
"Planning has a waypoint with drifter instrument, but configuration does not configure drifters.",
102-
id="ShipConfigNoDRIFTER"
104+
id="ShipConfigNoDRIFTER",
103105
),
104-
]
106+
],
105107
)
106-
def test_verify_ship_config_errors(request, schedule, ship_config_fixture, error, match) -> None:
108+
def test_verify_ship_config_errors(
109+
request, schedule, ship_config_fixture, error, match
110+
) -> None:
107111
ship_config = request.getfixturevalue(ship_config_fixture)
108112

109113
with pytest.raises(error, match=match):

0 commit comments

Comments
 (0)