Skip to content

Test FSP parse errors, velocity edge cases and Segment.as_plane - #168

Open
claude[bot] wants to merge 1 commit into
mainfrom
ai/tests-fsp
Open

claude[bot] wants to merge 1 commit into
mainfrom
ai/tests-fsp

Conversation

@claude

@claude claude Bot commented Oct 24, 2026

Copy link
Copy Markdown

Summary

Tests-only change to tests/test_fsp.py that pins down the error handling and edge cases of source_modelling/fsp.py. Malformed inputs are built by copying a bundled FSP file into tmp_path and editing one line.

What the new tests check:

  • Segment.as_plane validation. Each required attribute is removed in turn: strike, dip (set to None and to 0), length, width, dtop and top_centre. Each case must raise ValueError with the exact message.
  • Segment.as_plane geometry. For every Darfield segment, the plane's NZTM dip direction must be exactly 90° from its NZTM strike. The plane must keep the segment's dip, length and width, and the segment's top centre must map to fault coordinates (0.5, 0).
  • Parse errors. Each of these must raise FSPParseError with the exact message:
    • a header that can't be parsed
    • a segment numbered out of order ("Expected segment 2 but found segment 3")
    • a missing column header on the last of 8 segments ("... on segment 8.")
    • a missing Nsbfs subfault count
  • Velocity structure that can't be determined. Each of these must give velocity_model is None while the rest of the file still parses:
    • the layer-count line is missing
    • "crustal model unknown" appears with no shear modulus
    • the shear-modulus scale is malformed
    • the shear-modulus significand is malformed

Coverage of source_modelling/fsp.py

  • Before: 96% (lines 116, 468, 516, 570, 620 and 626 not covered)
  • After: 100%

Surviving mutants

Killed. I checked each listed one by applying it locally and confirming the fsp tests then fail:

  • Segment.as_plane mutants 2–6, where an and in the guard becomes or. The parametrised missing-attribute test kills them.
  • Segment.as_plane mutants 9–12, which change the error message. The exact-message match kills them.
  • Segment.as_plane mutant 24 (strike_nztm + 91). The perpendicular dip-direction check kills it.
  • FSPFile.read_from_file mutants 38–41 (header error message).
  • _parse_segment_slip mutants 14–16 (out-of-order segment message), 85–87 (missing-columns message, where the segment number is off by one or two) and 90 (missing-subfault-count message).

Judged equivalent:

  • Segment.as_plane mutants 49 and 56 (dip_dir_nztm=None or the argument dropped). When no dip direction is given, Plane.from_centroid_strike_dip defaults it to strike_nztm + 90, which is exactly the value as_plane passes. I applied mutant 49 locally and it survives, as expected.
  • FSPFile.read_from_file mutant 4 (open(fsp_ffp) without "r"). "r" is the default mode.
  • FSPFile.read_from_file mutant 30 (lstrip("XX% XX")). lstrip takes a set of characters, so the only change is that a leading X would also be stripped. No header line the pattern accepts starts with X after % ("EventTAG", "Loc", "Size", "Mech", "Rupt", "Invs", "SVF"), so parsing is unchanged.

No issues filed: the tests found no incorrect behaviour.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude claude Bot added ai-generated Opened by the scheduled Claude jobs ai-tests AI-written tests that need review labels Oct 24, 2026
@claude
claude Bot requested a review from lispandfound October 24, 2026 13:39

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated Opened by the scheduled Claude jobs ai-tests AI-written tests that need review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants