Skip to content

Commit 14f1e63

Browse files
Copilotilaflott
andcommitted
rewrite test_cli.py and add conftest.py following fre-cli conftest pattern
Fixes: - test_cli_fremor: click>=8.2 returns exit_code=2 for group with no subcommand - log tests: use 'yaml --help' so group callback runs before click processes --help - run/varlist tests: use session-scoped conftest fixtures for NC file generation - run/varlist tests: use tmp_path for outputs instead of shared directories - config test: depend on cli_sos_nc_file fixture - find tests: use Path objects from conftest instead of string concatenation Agent-Logs-Url: https://github.com/ilaflott/fremorizer/sessions/8457b2f7-ba78-41c0-b74e-2ec0575b97d9 Co-authored-by: ilaflott <[email protected]>
1 parent 2c73c88 commit 14f1e63

2 files changed

Lines changed: 204 additions & 259 deletions

File tree

fremorizer/tests/conftest.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'''
2+
Shared fixtures for fremorizer/tests CLI integration tests.
3+
'''
4+
5+
from datetime import date
6+
from pathlib import Path
7+
import shutil
8+
import subprocess
9+
10+
import pytest
11+
12+
import fremorizer
13+
14+
15+
# ── path constants ──────────────────────────────────────────────────────────
16+
ROOTDIR = Path(fremorizer.__file__).parent / 'tests' / 'test_files'
17+
18+
CMIP6_TABLE_CONFIG = ROOTDIR / 'cmip6-cmor-tables' / 'Tables' / 'CMIP6_Omon.json'
19+
CMIP7_TABLE_CONFIG = ROOTDIR / 'cmip7-cmor-tables' / 'tables' / 'CMIP7_ocean.json'
20+
21+
INDIR = ROOTDIR / 'ocean_sos_var_file'
22+
VARLIST = ROOTDIR / 'varlist'
23+
VARLIST_DIFF = ROOTDIR / 'varlist_local_target_vars_differ'
24+
EXP_CONFIG = ROOTDIR / 'CMOR_input_example.json'
25+
EXP_CONFIG_CMIP7 = ROOTDIR / 'CMOR_CMIP7_input_example.json'
26+
27+
SOS_NC_FILENAME = 'reduced_ocean_monthly_1x1deg.199301-199302.sos.nc'
28+
SOSV2_NC_FILENAME = 'reduced_ocean_monthly_1x1deg.199301-199302.sosV2.nc'
29+
30+
YYYYMMDD = date.today().strftime('%Y%m%d')
31+
32+
33+
# ── ncgen helper ────────────────────────────────────────────────────────────
34+
def _ncgen(cdl_name, nc_path):
35+
"""Run ncgen3 to convert a CDL file into a NetCDF-4 file."""
36+
cdl_path = ROOTDIR / 'reduced_ascii_files' / cdl_name
37+
assert cdl_path.exists(), f'CDL file not found: {cdl_path}'
38+
39+
if nc_path.exists():
40+
nc_path.unlink()
41+
42+
subprocess.run(
43+
['ncgen3', '-k', 'netCDF-4', '-o', str(nc_path), str(cdl_path)],
44+
check=True,
45+
)
46+
assert nc_path.exists(), f'ncgen3 failed to create {nc_path}'
47+
48+
49+
# ── session-scoped fixtures ─────────────────────────────────────────────────
50+
@pytest.fixture(scope='session')
51+
def cli_sos_nc_file():
52+
"""Generate the sos NetCDF file from CDL (session-scoped)."""
53+
INDIR.mkdir(parents=True, exist_ok=True)
54+
nc_path = INDIR / SOS_NC_FILENAME
55+
_ncgen('reduced_ocean_monthly_1x1deg.199301-199302.sos.cdl', nc_path)
56+
return str(nc_path)
57+
58+
59+
@pytest.fixture(scope='session')
60+
def cli_sosv2_nc_file(cli_sos_nc_file):
61+
"""Create a copy of the sos file as sosV2 (session-scoped)."""
62+
nc_path = INDIR / SOSV2_NC_FILENAME
63+
if nc_path.exists():
64+
nc_path.unlink()
65+
shutil.copy(cli_sos_nc_file, str(nc_path))
66+
assert nc_path.exists()
67+
return str(nc_path)

0 commit comments

Comments
 (0)