Skip to content

Commit

Permalink
Merge pull request #158 from MetOffice/general-cleanup
Browse files Browse the repository at this point in the history
General cleanup
  • Loading branch information
jfrost-mo authored Jul 14, 2023
2 parents 02e22a5 + a237257 commit 878cf8f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 60 deletions.
9 changes: 0 additions & 9 deletions development.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ classifiers = [
]
dependencies = [
"numpy",
"scitools-iris",
"scitools-iris >= 3.6",
"ruamel.yaml >= 0.17",
"importlib_resources >= 3.0.0 ; python_version < '3.9'",
"pygraphviz >= 1.11"
]

[project.urls]
Expand Down
2 changes: 1 addition & 1 deletion src/CSET/operators/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def generate_stash_constraint(stash: str, **kwargs) -> iris.AttributeConstraint:
Arguments
---------
stash: str
stash code to build iris constraint, currently using "m01s03i236"
stash code to build iris constraint, such as "m01s03i236"
Returns
-------
Expand Down
14 changes: 8 additions & 6 deletions src/CSET/operators/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,35 @@

import iris
import iris.cube
from typing import Union


def filter_cubes(
cubelist: iris.cube.CubeList, constraint: iris.Constraint, **kwargs
cube: Union[iris.cube.Cube, iris.cube.CubeList],
constraint: iris.Constraint,
**kwargs,
) -> iris.cube.Cube:
"""
Filters a cubelist down to a single cube based on a constraint.
Arguments
---------
cubelist: iris.cube.CubeList
Cubes to iterate over
cube: iris.cube.Cube | iris.cube.CubeList
Cube(s) to iterate over
constraint: iris.Constraint
Constraint to extract
Returns
-------
cube: iris.cube.Cube
Single variable
iris.cube.Cube
Raises
------
ValueError
If the constraint doesn't produce a single cube.
"""

filtered_cubes = cubelist.extract(constraint)
filtered_cubes = cube.extract(constraint)

# Check filtered cubes is a CubeList containing one cube.
if len(filtered_cubes) == 1:
Expand Down
2 changes: 1 addition & 1 deletion src/CSET/recipes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _unpack_recipes_from_dir(input_dir: Path, output_dir: Path):
output_dir.mkdir(parents=True, exist_ok=True)
if file.is_file() and file.suffix == ".yaml":
if output_dir.joinpath(file.name).exists():
logging.warn(
logging.warning(
"%s already exists in target directory, skipping.", file.name
)
else:
Expand Down
42 changes: 0 additions & 42 deletions tests/operators/test_write.py

This file was deleted.

28 changes: 28 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@


def test_command_line_help():
"""Check that help commands work."""

subprocess.run(["cset", "--help"], check=True)
# test verbose options. This is really just to up the coverage number.
subprocess.run(["cset", "-v"], check=True)
subprocess.run(["cset", "-vv"], check=True)
subprocess.run(["cset", "--version"], check=True)
# Gain coverage of __main__.py
subprocess.run(["python3", "-m", "CSET", "-h"], check=True)


def test_recipe_execution():
"""Test running CSET recipe from the command line."""

subprocess.run(
[
"cset",
Expand All @@ -48,6 +53,7 @@ def test_recipe_execution():

def test_environ_var_recipe():
"""Test recipe coming from environment variable."""

os.environ[
"CSET_RECIPE"
] = """
Expand Down Expand Up @@ -82,8 +88,28 @@ def test_graph_creation():
output_file.unlink()


def test_graph_creation_env_var():
"""
Generates a graph with the command line interface from an environment
variable.
"""

os.environ[
"CSET_RECIPE"
] = """
steps:
- operator: misc.noop
"""
# Run with output path specified
output_file = Path(tempfile.gettempdir(), f"{uuid4()}.svg")
subprocess.run(("cset", "graph", "-o", str(output_file)), check=True)
assert output_file.exists()
output_file.unlink()


def test_graph_details():
"""Generate a graph with details with details."""

output_file = Path(tempfile.gettempdir(), f"{uuid4()}.svg")
subprocess.run(
(
Expand All @@ -102,13 +128,15 @@ def test_graph_details():

def test_cookbook_cwd():
"""Unpacking the recipes into the current working directory."""

subprocess.run(["cset", "cookbook"], check=True)
assert Path.cwd().joinpath("recipes/extract_instant_air_temp.yaml").exists()
shutil.rmtree(Path.cwd().joinpath("recipes"))


def test_cookbook_path():
"""Unpacking the recipes into a specified directory."""

with tempfile.TemporaryDirectory() as tmpdir:
subprocess.run(["cset", "cookbook", tmpdir], check=True)
assert Path(tmpdir, "extract_instant_air_temp.yaml").exists()

0 comments on commit 878cf8f

Please sign in to comment.