Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![publish_conda](https://github.com/ilaflott/fremorizer/actions/workflows/publish_conda.yml/badge.svg?branch=main)](https://github.com/ilaflott/fremorizer/actions/workflows/publish_conda.yml)

[![pylint](https://github.com/ilaflott/fremorizer/actions/workflows/pylint.yml/badge.svg?branch=main)](https://github.com/ilaflott/fremorizer/actions/workflows/pylint.yml)
[![pylint](https://img.shields.io/badge/pylint-%E2%89%A58.1-brightgreen)](https://github.com/NOAA-GFDL/epmt/actions/workflows/build_and_test_epmt.yml)
[![pylint](https://img.shields.io/badge/pylint-%E2%89%A59.4-brightgreen)](https://github.com/NOAA-GFDL/epmt/actions/workflows/build_and_test_epmt.yml)

[![codecov](https://codecov.io/gh/ilaflott/fremorizer/branch/main/graph/badge.svg)](https://codecov.io/gh/ilaflott/fremorizer)
[![readthedocs](https://app.readthedocs.org/projects/fremorizer/badge/?version=latest&style=flat)](https://fremorizer.readthedocs.io/en/latest/)
Expand Down
67 changes: 67 additions & 0 deletions fremorizer/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'''
Shared fixtures for fremorizer/tests CLI integration tests.
'''

from datetime import date
from pathlib import Path
import shutil
import subprocess

import pytest

import fremorizer


# ── path constants ──────────────────────────────────────────────────────────
ROOTDIR = Path(fremorizer.__file__).parent / 'tests' / 'test_files'

CMIP6_TABLE_CONFIG = ROOTDIR / 'cmip6-cmor-tables' / 'Tables' / 'CMIP6_Omon.json'
CMIP7_TABLE_CONFIG = ROOTDIR / 'cmip7-cmor-tables' / 'tables' / 'CMIP7_ocean.json'

INDIR = ROOTDIR / 'ocean_sos_var_file'
VARLIST = ROOTDIR / 'varlist'
VARLIST_DIFF = ROOTDIR / 'varlist_local_target_vars_differ'
EXP_CONFIG = ROOTDIR / 'CMOR_input_example.json'
EXP_CONFIG_CMIP7 = ROOTDIR / 'CMOR_CMIP7_input_example.json'

SOS_NC_FILENAME = 'reduced_ocean_monthly_1x1deg.199301-199302.sos.nc'
SOSV2_NC_FILENAME = 'reduced_ocean_monthly_1x1deg.199301-199302.sosV2.nc'

YYYYMMDD = date.today().strftime('%Y%m%d')


# ── ncgen helper ────────────────────────────────────────────────────────────
def _ncgen(cdl_name, nc_path):
"""Run ncgen3 to convert a CDL file into a NetCDF-4 file."""
cdl_path = ROOTDIR / 'reduced_ascii_files' / cdl_name
assert cdl_path.exists(), f'CDL file not found: {cdl_path}'

if nc_path.exists():
nc_path.unlink()

subprocess.run(
['ncgen3', '-k', 'netCDF-4', '-o', str(nc_path), str(cdl_path)],
check=True,
)
assert nc_path.exists(), f'ncgen3 failed to create {nc_path}'


# ── session-scoped fixtures ─────────────────────────────────────────────────
@pytest.fixture(scope='session')
def cli_sos_nc_file():
"""Generate the sos NetCDF file from CDL (session-scoped)."""
INDIR.mkdir(parents=True, exist_ok=True)
nc_path = INDIR / SOS_NC_FILENAME
_ncgen('reduced_ocean_monthly_1x1deg.199301-199302.sos.cdl', nc_path)
return str(nc_path)


@pytest.fixture(scope='session')
def cli_sosv2_nc_file(cli_sos_nc_file):
"""Create a copy of the sos file as sosV2 (session-scoped)."""
nc_path = INDIR / SOSV2_NC_FILENAME
if nc_path.exists():
nc_path.unlink()
shutil.copy(cli_sos_nc_file, str(nc_path))
assert nc_path.exists()
return str(nc_path)
Loading
Loading