Skip to content

Commit

Permalink
Validate OBSDIR in merge_rft_ertobs
Browse files Browse the repository at this point in the history
  • Loading branch information
alifbe committed Oct 11, 2023
1 parent b2e414d commit d84fecb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/subscript/merge_rft_ertobs/merge_rft_ertobs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import logging
from os.path import isdir, abspath
from pathlib import Path
from typing import Tuple

Expand Down Expand Up @@ -154,6 +155,8 @@ def get_observations(obsdir: str = "", filepattern: str = "*.obs") -> pd.DataFra
""" # noqa
if "/" in filepattern:
raise ValueError("Do not include paths in filepattern")
if not isdir(obsdir):
raise ValueError(f'Observation directory "{abspath(obsdir)}" doesn\'t exist')

obs_dfs = []
for obsfilename in Path(obsdir).glob(filepattern):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_merge_rft_ertobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def fixture_drogondata(tmp_path):
os.chdir(cwd)


def test_invalid_obsdir():
"""Test exception when obsdir is not valid"""
with pytest.raises(ValueError, match="Observation directory"):
get_observations("/path/to/random/non-existing/directory")


def test_get_observations(drogondata):
"""Try to parse observations"""
dframe = get_observations("rft")
Expand Down

0 comments on commit d84fecb

Please sign in to comment.