Skip to content

Commit

Permalink
Refactor to use textwrap for config file writing
Browse files Browse the repository at this point in the history
This commit introduces the use of `textwrap.dedent` to maintain the
configuration file's content in the tests for the surface current tiles worker
module. Using `textwrap.dedent` makes the inline configuration text more
manageable and readable by removing the initial indentations.
  • Loading branch information
douglatornell committed May 17, 2024
1 parent 2083e21 commit 32d3a94
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions tests/workers/test_make_surface_current_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""Unit tests for SalishSeaCast make_surface_current_tiles worker.
"""
from pathlib import Path
import textwrap
from types import SimpleNamespace
from unittest.mock import Mock, patch

Expand All @@ -35,34 +36,36 @@ def config(base_config):
config_file = Path(base_config.file)
with config_file.open("at") as f:
f.write(
"""
file group: allen
figures:
grid dir: nowcast-sys/grid/
surface current tiles:
storage path: nowcast-sys/figures/surface_currents/
results archive:
nowcast: results/nowcast-blue.201806/
nowcast-green: results/nowcast-green.201806/
forecast: results/forecast.201806/
forecast2: results/forecast2.201806/
run types:
nowcast-green:
coordinates: coordinates_seagrid_SalishSea201702.nc
bathymetry: bathymetry_201702.nc
mesh mask: mesh_mask201702.nc
forecast:
coordinates: coordinates_seagrid_SalishSea201702.nc
bathymetry: bathymetry_201702.nc
mesh mask: mesh_mask201702.nc
forecast2:
coordinates: coordinates_seagrid_SalishSea201702.nc
bathymetry: bathymetry_201702.nc
mesh mask: mesh_mask201702.nc
"""
textwrap.dedent(
"""\
file group: allen
figures:
grid dir: nowcast-sys/grid/
surface current tiles:
storage path: nowcast-sys/figures/surface_currents/
results archive:
nowcast: results/nowcast-blue.201806/
nowcast-green: results/nowcast-green.201806/
forecast: results/forecast.201806/
forecast2: results/forecast2.201806/
run types:
nowcast-green:
coordinates: coordinates_seagrid_SalishSea201702.nc
bathymetry: bathymetry_201702.nc
mesh mask: mesh_mask201702.nc
forecast:
coordinates: coordinates_seagrid_SalishSea201702.nc
bathymetry: bathymetry_201702.nc
mesh mask: mesh_mask201702.nc
forecast2:
coordinates: coordinates_seagrid_SalishSea201702.nc
bathymetry: bathymetry_201702.nc
mesh mask: mesh_mask201702.nc
"""
)
)
config_ = nemo_nowcast.Config()
config_.load(config_file)
Expand Down

0 comments on commit 32d3a94

Please sign in to comment.