Testing & Quality Assurance

The Hudson Bay sea ice pipeline is developed with a mandatory quality gate: every change passes static analysis and the full test suite before it reaches the production branch. This page summarises the test model, the CI gates and the QA validation of the daily pipeline output.

Source code: github.com/Chris010980/hudson_bay_sea_ice_showcase

Snapshot

Static snapshot of the test and analysis state (measured after issue #41, 2026-10-19; the numbers are updated whenever the suite changes).

Tests

291

Test Files

45

Line Coverage

96 %

Lint Findings

0

Test Architecture

The suite is organized into five levels with distinct responsibilities, from isolated pure-function tests to complete end-to-end pipeline runs against real data. Fixture verification tests additionally check the shared test infrastructure itself.

Level Files Responsibility
Unit 20 Pure functions: dates, thresholds, trends, CLI parsing, output validation
Fixture verification 4 Shared pytest fixtures and static fixture data
Component 14 Single components with real I/O on temporary directories
Integration 5 Stage collaboration (download → process → plots → build)
End-to-end 2 Complete workflow and incremental daily update, including the website build

Scientific calculations are verified with hand-computed reference values wherever possible, so that test failures point at actual changes of the scientific semantics.

Unit test: linear trend with hand-calculated values
def test_noisy_fit_matches_hand_calculation() -> None:
    """Least-squares fit of (1,1), (2,2), (3,4).

    slope = 1.5, intercept = -2/3, R² = 27/28 (hand values).
    """
    x = np.array([1.0, 2.0, 3.0])
    y = np.array([1.0, 2.0, 4.0])

    slope, intercept, r_squared = compute_linear_trend(x, y)

    assert slope == pytest.approx(1.5)
    assert intercept == pytest.approx(-2.0 / 3.0)
    assert r_squared == pytest.approx(27.0 / 28.0)

CI Quality Gates

The quality gate workflow runs on every push and pull request. Ruff lint and format checks as well as the test suite with coverage are mandatory and blocking; the dead-code report is advisory. The workflow uses pinned GitHub Actions versions on a fixed Python 3.12.

  • Mandatory: ruff check, ruff format --check, pytest --cov=src
  • Advisory: vulture dead-code report (min-confidence 90, with a documented whitelist)
  • Local only: radon complexity checks — no C-ranked function is allowed in the source tree
Quality gate workflow (excerpt)
- name: Ruff lint (mandatory, blocking)
  run: ruff check .

- name: Ruff format check (mandatory, blocking)
  run: ruff format --check .

- name: Vulture dead-code report (advisory, non-blocking)
  run: >
    vulture src tests tests/vulture_whitelist.py
    --min-confidence 90
  continue-on-error: true

- name: Run tests with coverage (mandatory, blocking)
  run: >
    pytest --cov=src
    --cov-report=term-missing
    --cov-report=xml:coverage.xml

Robust Data Acquisition

Daily unattended operation requires defensive failure handling. GeoTIFF downloads are atomic: files are streamed into temporary .part files and moved into place only after a complete transfer, with up to three attempts per file before the file is skipped and counted as failed. Interrupted downloads therefore never corrupt the local archive.

Atomic download with retries
temp_path = local_dir / f"{filename}.part"

for attempt in range(1, DOWNLOAD_MAX_ATTEMPTS + 1):
    temp_path.unlink(missing_ok=True)

    try:
        if not self._stream_to_file(remote_url, temp_path):
            return False

        os.replace(temp_path, local_path)

        logger.info("Saved %s", local_path)
        return True

    except requests.RequestException as exc:
        logger.warning(
            "Download attempt %d/%d for %s failed: %s",
            attempt,
            DOWNLOAD_MAX_ATTEMPTS,
            remote_url,
            exc,
        )

temp_path.unlink(missing_ok=True)

return False

QA Output Validation

A dedicated QA module validates the complete daily output tree after every pipeline run: schema and consistency of all CSV products, agreement between latest.json and the summary data, completeness of the figure inventory (including PNG magic-number checks) and the deployed website build. The validator runs as a CLI whose exit code equals the number of detected issues, so it can gate any downstream automation.

  • Summary, timeseries, yearly and events CSVs (schema, duplicates, malformed dates, value ranges)
  • latest.json consistency with the summary state
  • Complete plot inventory: six daily products per region, plus yearly products when present
  • Build directory: deployed index.html and matching analysis products
Unit test: latest.json consistency check
def test_latest_json_consistency_is_checked() -> None:
    """A consistent payload passes; mismatches are reported."""
    summary_df = _summary_frame()

    assert (
        validate_latest_json(_latest_payload(summary_df), summary_df)
        == []
    )

    payload = _latest_payload(summary_df)
    payload["date"] = "2020-01-01"
    payload["observations"] = 99

    issues = validate_latest_json(payload, summary_df)

    assert len(issues) == 2
    assert all("match" in issue for issue in issues)

Findings Register

Testing is driven by a documented findings register: dynamic-test findings are numbered F-001 … F-031, static-analysis findings S-001 … S-021. Every finding carries a status (open, partial, fixed, documented) and is only closed by a covering test or a documented decision.

This process has produced measurable results: the static-analysis campaign reduced over 400 initial lint findings to zero — today the source tree contains no lint suppression directives at all — and the end-to-end tests uncovered a real production bug (F-031): plotting crashed with empty yearly CSV files on a first run. The fix is pinned by a regression test and documented in the regression testing guide.

How the Snapshot is Maintained

  • The daily production run executes the pipeline, not the test suite — the numbers on this page are a maintained snapshot, labelled with its date.
  • The snapshot is updated in the same change that alters findings, test counts or coverage, keeping documentation and reality in sync.
  • The full methodology is documented in the repository (docs/testing/): test levels, test strategy, coverage policy, regression testing and QA validation.

← Back to the sea ice project  •  Portfolio overview