"""バンドルの読み込みと事前検証(`data/bundle.py`)のテスト.
期待値は SPEC_01「データ契約」・SPEC_02「入力の前処理」「学習後の評価」(IoU を定義できない
場合)と `.claude/rules/error-handling.md`(fail fast・個人情報を出さない)を基準にする.
manifest の `kind`・列名は仮のデータ契約(`data/bundle.py` の定数)を使う.
- 組の欠け・大きさの違い等は,正常な組が混ざっていても黙って除かずに止まる
- 例外のメッセージ・トレースバックに `capture_id`・`subject_id`・ファイル名(ハッシュ)・
パスが出ない(目印になる値を ID・フォルダ名に入れて確かめる)
ファイル I/O はすべて `tmp_path` の合成データで行う(実データ・`legacy/`・リポジトリの
`data/synthetic/` は使わない).
"""
from __future__ import annotations
import hashlib
import json
import re
import traceback
from collections.abc import Iterable
from pathlib import Path
import cv2
import numpy as np
import pytest
import tiasdata
from tiasdata.bundle import BundleInfo, build_dataset_json
from tiasdata.manifest import manifest_sha256
from tongue_seg_model.data.bundle import (
IMAGE_KIND,
MASK_KIND,
SUBSET_ANNOTATION_FIELD,
SUBSET_ANNOTATION_KIND,
SUBSET_TEST,
SUBSET_TRAIN,
SegBundle,
SegRecord,
load_seg_bundle,
records_from_bundle_rows,
validate_image_size,
validate_records,
)
from tongue_seg_model.data.synthetic import (
SYNTHETIC_BUNDLE_NAME,
SYNTHETIC_BUNDLE_VERSION,
write_synthetic_bundle,
)
from tongue_seg_model.schema import BundleConfig
# 個人情報を出さないことを確かめるための目印(ID・フォルダ名・ファイル名に入れる).
CAPTURE_MARK = "CapMarkQz7"
SUBJECT_MARK = "SubjMarkXk3"
ROOT_MARK = "RootMarkWp5"
FILE_MARK = "FileMarkVb2"
BAD_KIND = "KindMarkTn4"
BAD_SUBSET = "SubsetMarkRj6"
SIZE = (32, 32)
SYNTHETIC = BundleConfig(name=SYNTHETIC_BUNDLE_NAME, version=SYNTHETIC_BUNDLE_VERSION)
_HEX64 = re.compile("[0-9a-f]{64}")
# ---------------------------------------------------------------------------
# 補助
# ---------------------------------------------------------------------------
def _sha(*parts: object) -> str:
return hashlib.sha256("/".join(str(p) for p in parts).encode()).hexdigest()
def _row(
kind: str,
capture: str,
*,
subject: str | None = None,
subset: str | None = SUBSET_TRAIN,
salt: object = 0,
with_subset_column: bool = True,
) -> tiasdata.BundleRow:
sha256 = _sha(kind, capture, subject, subset, salt)
annotations: dict[str, dict[str, str | None]] = {}
if with_subset_column:
annotations = {SUBSET_ANNOTATION_KIND: {SUBSET_ANNOTATION_FIELD: subset}}
return tiasdata.BundleRow(
path=f"files/{sha256}.png",
sha256=sha256,
kind=kind,
subject_id=f"{SUBJECT_MARK}-{capture}" if subject is None else subject,
capture_id=capture,
annotations=annotations,
)
def _pair(capture: str, subset: str = SUBSET_TRAIN, **kwargs) -> list[tiasdata.BundleRow]:
return [
_row(IMAGE_KIND, capture, subset=subset, **kwargs),
_row(MASK_KIND, capture, subset=subset, **kwargs),
]
def _valid_rows() -> list[tiasdata.BundleRow]:
"""train 2 組・test 1 組(行番号 2〜7)."""
return (
_pair(f"{CAPTURE_MARK}-a")
+ _pair(f"{CAPTURE_MARK}-b")
+ _pair(f"{CAPTURE_MARK}-c", SUBSET_TEST)
)
def _root(tmp_path: Path) -> Path:
return tmp_path / ROOT_MARK
def _all_text(exc: BaseException) -> str:
return "".join(traceback.format_exception(exc))
def _assert_no_pii(
exc: BaseException,
*,
rows: Iterable[tiasdata.BundleRow] = (),
extra: Iterable[str] = (),
) -> None:
text = _all_text(exc)
for mark in (CAPTURE_MARK, SUBJECT_MARK, ROOT_MARK, FILE_MARK, BAD_KIND, BAD_SUBSET):
assert mark not in text
for row in rows:
assert row.sha256[:12] not in text
if row.capture_id:
assert row.capture_id not in text
if row.subject_id:
assert row.subject_id not in text
for value in extra:
assert value not in text
assert _HEX64.search(str(exc)) is None
def _write_png(path: Path, array: np.ndarray) -> Path:
path.parent.mkdir(parents=True, exist_ok=True)
assert cv2.imwrite(str(path), array)
return path
def _image(size: tuple[int, int] = SIZE, value: int = 90) -> np.ndarray:
return np.full((*size, 3), value, dtype=np.uint8)
def _mask(size: tuple[int, int] = SIZE, *, empty: bool = False, fill: int = 255) -> np.ndarray:
mask = np.zeros(size, dtype=np.uint8)
if not empty:
mask[size[0] // 4 : size[0] // 2, size[1] // 4 : size[1] // 2] = fill
return mask
def _record(
tmp_path: Path,
index: int,
*,
subset: str = SUBSET_TRAIN,
image: np.ndarray | None = None,
mask: np.ndarray | None = None,
write_image: bool = True,
) -> SegRecord:
folder = tmp_path / ROOT_MARK / "files"
image_path = folder / f"{FILE_MARK}-{index}-image.png"
mask_path = folder / f"{FILE_MARK}-{index}-mask.png"
if write_image:
_write_png(image_path, _image() if image is None else image)
_write_png(mask_path, _mask() if mask is None else mask)
return SegRecord(
image_path=image_path,
mask_path=mask_path,
subset=subset,
subject_id=f"{SUBJECT_MARK}-{index}",
image_line=2 + 2 * index,
mask_line=3 + 2 * index,
)
def _rewrite_manifest(bundle_dir: Path, keep: Iterable[int]) -> None:
"""manifest.csv のデータ行を `keep`(行番号)だけにし,dataset.json を合わせる."""
lines = (bundle_dir / "manifest.csv").read_bytes().split(b"\n")
header, body = lines[0], [line for line in lines[1:] if line]
kept = [body[n - 2] for n in sorted(keep)]
manifest = b"\n".join([header, *kept]) + b"\n"
(bundle_dir / "manifest.csv").write_bytes(manifest)
info = json.loads((bundle_dir / "dataset.json").read_text(encoding="utf-8"))
info["manifest_sha256"] = manifest_sha256(manifest)
info["files"] = len(kept)
(bundle_dir / "dataset.json").write_bytes(build_dataset_json(BundleInfo(**info)))
def _manifest_kinds(bundle_dir: Path) -> list[str]:
lines = (bundle_dir / "manifest.csv").read_text(encoding="utf-8").splitlines()
header = lines[0].split(",")
kind_index = header.index("kind")
return [line.split(",")[kind_index] for line in lines[1:]]
# ---------------------------------------------------------------------------
# records_from_bundle_rows: 正常系
# ---------------------------------------------------------------------------
def test_records_pair_image_and_mask_by_capture_id(tmp_path: Path) -> None:
rows = _valid_rows()
root = _root(tmp_path)
records = records_from_bundle_rows(rows, root)
assert len(records) == 3
for record, (image_row, mask_row) in zip(
records, (rows[0:2], rows[2:4], rows[4:6]), strict=True
):
assert record.image_path == root / image_row.path
assert record.mask_path == root / mask_row.path
assert record.image_path.parent == root / "files"
assert record.mask_path.parent == root / "files"
assert record.subject_id == image_row.subject_id
assert [r.subset for r in records] == [SUBSET_TRAIN, SUBSET_TRAIN, SUBSET_TEST]
assert [(r.image_line, r.mask_line) for r in records] == [(2, 3), (4, 5), (6, 7)]
def test_records_follow_manifest_order_of_image_rows(tmp_path: Path) -> None:
# マスクの行が画像の行より前にある組・組の行が離れている組を混ぜる.
a_image, a_mask = _pair(f"{CAPTURE_MARK}-a")
b_image, b_mask = _pair(f"{CAPTURE_MARK}-b", SUBSET_TEST)
c_image, c_mask = _pair(f"{CAPTURE_MARK}-c")
rows = [b_mask, a_image, c_mask, b_image, a_mask, c_image]
records = records_from_bundle_rows(rows, _root(tmp_path))
# 画像の行の順: a(3 行目)→ b(5 行目)→ c(7 行目)
assert [(r.image_line, r.mask_line) for r in records] == [(3, 6), (5, 2), (7, 4)]
assert [r.image_path.name for r in records] == [
Path(a_image.path).name,
Path(b_image.path).name,
Path(c_image.path).name,
]
assert [r.mask_path.name for r in records] == [
Path(a_mask.path).name,
Path(b_mask.path).name,
Path(c_mask.path).name,
]
def test_records_allow_empty_subject_id(tmp_path: Path) -> None:
rows = _pair(f"{CAPTURE_MARK}-a", subject="") + _pair(
f"{CAPTURE_MARK}-b", SUBSET_TEST, subject=""
)
records = records_from_bundle_rows(rows, _root(tmp_path))
assert [r.subject_id for r in records] == ["", ""]
def test_records_is_pure_and_does_not_read_files(tmp_path: Path) -> None:
# ファイルが無くても変換できる(ファイルの中身は validate_records で確かめる).
records = records_from_bundle_rows(_valid_rows(), _root(tmp_path))
assert not any(r.image_path.exists() or r.mask_path.exists() for r in records)
# ---------------------------------------------------------------------------
# records_from_bundle_rows: 止まる条件(正常な組が混ざっていても止まる)
# ---------------------------------------------------------------------------
def test_no_rows_raises(tmp_path: Path) -> None:
with pytest.raises(ValueError):
records_from_bundle_rows([], _root(tmp_path))
def test_missing_subset_column_raises(tmp_path: Path) -> None:
rows = _valid_rows()
rows += [
_row(IMAGE_KIND, f"{CAPTURE_MARK}-x", with_subset_column=False),
_row(MASK_KIND, f"{CAPTURE_MARK}-x", with_subset_column=False),
]
with pytest.raises(
ValueError, match=f"{SUBSET_ANNOTATION_KIND}.{SUBSET_ANNOTATION_FIELD}"
) as e:
records_from_bundle_rows(rows, _root(tmp_path))
_assert_no_pii(e.value, rows=rows)
def test_subset_column_missing_in_every_row_raises(tmp_path: Path) -> None:
rows = [
_row(kind, f"{CAPTURE_MARK}-{i}", with_subset_column=False)
for i in range(2)
for kind in (IMAGE_KIND, MASK_KIND)
]
with pytest.raises(ValueError) as e:
records_from_bundle_rows(rows, _root(tmp_path))
_assert_no_pii(e.value, rows=rows)
def test_unknown_kind_raises_with_line_number(tmp_path: Path) -> None:
rows = _valid_rows() + [_row(BAD_KIND, f"{CAPTURE_MARK}-x")]
with pytest.raises(ValueError, match="1 件") as e:
records_from_bundle_rows(rows, _root(tmp_path))
assert "8" in str(e.value)
_assert_no_pii(e.value, rows=rows)
def test_empty_capture_id_raises(tmp_path: Path) -> None:
rows = _valid_rows() + [_row(IMAGE_KIND, ""), _row(MASK_KIND, "", salt=1)]
with pytest.raises(ValueError, match="capture_id") as e:
records_from_bundle_rows(rows, _root(tmp_path))
assert "2 件" in str(e.value)
_assert_no_pii(e.value, rows=rows)
@pytest.mark.parametrize("subset", [BAD_SUBSET, None, "Train", "val"])
def test_invalid_subset_raises(tmp_path: Path, subset: str | None) -> None:
rows = _valid_rows() + _pair(f"{CAPTURE_MARK}-x", subset) # type: ignore[arg-type]
with pytest.raises(ValueError) as e:
records_from_bundle_rows(rows, _root(tmp_path))
assert "8" in str(e.value) and "9" in str(e.value)
_assert_no_pii(e.value, rows=rows)
@pytest.mark.parametrize("kind", [IMAGE_KIND, MASK_KIND])
def test_duplicated_image_or_mask_in_one_capture_raises(tmp_path: Path, kind: str) -> None:
capture = f"{CAPTURE_MARK}-x"
rows = _valid_rows() + _pair(capture) + [_row(kind, capture, salt="dup")]
with pytest.raises(ValueError, match="2 つ以上") as e:
records_from_bundle_rows(rows, _root(tmp_path))
# 重複した組の 3 行(8・9・10 行目)を示す.
assert "3 件" in str(e.value)
_assert_no_pii(e.value, rows=rows)
def test_image_without_mask_raises(tmp_path: Path) -> None:
rows = _valid_rows() + [_row(IMAGE_KIND, f"{CAPTURE_MARK}-x")]
with pytest.raises(ValueError, match="正解マスクと組になっていない") as e:
records_from_bundle_rows(rows, _root(tmp_path))
assert "8" in str(e.value)
_assert_no_pii(e.value, rows=rows)
def test_mask_without_image_raises(tmp_path: Path) -> None:
rows = [_row(MASK_KIND, f"{CAPTURE_MARK}-x")] + _valid_rows()
with pytest.raises(ValueError, match="画像と組になっていない") as e:
records_from_bundle_rows(rows, _root(tmp_path))
assert "2" in str(e.value)
_assert_no_pii(e.value, rows=rows)
def test_subset_mismatch_within_pair_raises(tmp_path: Path) -> None:
capture = f"{CAPTURE_MARK}-x"
rows = _valid_rows() + [
_row(IMAGE_KIND, capture, subset=SUBSET_TRAIN),
_row(MASK_KIND, capture, subset=SUBSET_TEST),
]
with pytest.raises(ValueError, match="食い違う") as e:
records_from_bundle_rows(rows, _root(tmp_path))
_assert_no_pii(e.value, rows=rows)
def test_subject_id_mismatch_within_pair_raises(tmp_path: Path) -> None:
capture = f"{CAPTURE_MARK}-x"
rows = _valid_rows() + [
_row(IMAGE_KIND, capture, subject=f"{SUBJECT_MARK}-1"),
_row(MASK_KIND, capture, subject=f"{SUBJECT_MARK}-2"),
]
with pytest.raises(ValueError, match="subject_id") as e:
records_from_bundle_rows(rows, _root(tmp_path))
_assert_no_pii(e.value, rows=rows)
@pytest.mark.parametrize("missing", [SUBSET_TRAIN, SUBSET_TEST])
def test_no_train_or_no_test_pairs_raises(tmp_path: Path, missing: str) -> None:
present = SUBSET_TEST if missing == SUBSET_TRAIN else SUBSET_TRAIN
rows = _pair(f"{CAPTURE_MARK}-a", present) + _pair(f"{CAPTURE_MARK}-b", present)
with pytest.raises(ValueError, match=missing) as e:
records_from_bundle_rows(rows, _root(tmp_path))
_assert_no_pii(e.value, rows=rows)
def test_error_lists_at_most_five_line_numbers(tmp_path: Path) -> None:
orphans = [_row(IMAGE_KIND, f"{CAPTURE_MARK}-o{i}") for i in range(7)]
rows = _valid_rows() + orphans
with pytest.raises(ValueError, match="7 件") as e:
records_from_bundle_rows(rows, _root(tmp_path))
message = str(e.value)
for line in (8, 9, 10, 11, 12):
assert str(line) in message
assert "13" not in message and "14" not in message
_assert_no_pii(e.value, rows=rows)
# ---------------------------------------------------------------------------
# load_seg_bundle
# ---------------------------------------------------------------------------
def test_load_synthetic_bundle(tmp_path: Path) -> None:
bundle_dir = write_synthetic_bundle(
tmp_path, train_pairs=4, test_pairs=2, seed=0, image_size=SIZE
)
bundle = load_seg_bundle(SYNTHETIC, bundles_dir=tmp_path, verify=True)
assert isinstance(bundle, SegBundle)
assert len(bundle.records) == 6
assert sum(r.subset == SUBSET_TRAIN for r in bundle.records) == 4
assert sum(r.subset == SUBSET_TEST for r in bundle.records) == 2
files_dir = (bundle_dir / "files").resolve()
for record in bundle.records:
assert record.image_path.parent == files_dir
assert record.mask_path.parent == files_dir
assert record.image_path.is_file() and record.mask_path.is_file()
assert record.image_path != record.mask_path
assert [r.image_line for r in bundle.records] == sorted(r.image_line for r in bundle.records)
assert set(bundle.fingerprint) == {"name", "version", "manifest_sha256"}
assert bundle.fingerprint["name"] == SYNTHETIC_BUNDLE_NAME
assert bundle.fingerprint["version"] == SYNTHETIC_BUNDLE_VERSION
assert bundle.fingerprint["manifest_sha256"] == manifest_sha256(
(bundle_dir / "manifest.csv").read_bytes()
)
def test_load_uses_tiasdata_bundles_env_var(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
write_synthetic_bundle(tmp_path, train_pairs=2, test_pairs=1, seed=0, image_size=SIZE)
monkeypatch.setenv("TIASDATA_BUNDLES", str(tmp_path))
bundle = load_seg_bundle(SYNTHETIC)
assert len(bundle.records) == 3
def test_load_missing_bundle_raises_without_path(tmp_path: Path) -> None:
bundles_dir = tmp_path / ROOT_MARK
with pytest.raises(ValueError) as e:
load_seg_bundle(SYNTHETIC, bundles_dir=bundles_dir)
_assert_no_pii(e.value, extra=[str(tmp_path), tmp_path.name])
def test_load_name_mismatch_in_dataset_json_raises(tmp_path: Path) -> None:
other = write_synthetic_bundle(
tmp_path / "work", train_pairs=1, test_pairs=1, seed=0, image_size=SIZE, name="other"
)
target = tmp_path / SYNTHETIC_BUNDLE_NAME / f"v{SYNTHETIC_BUNDLE_VERSION}"
target.parent.mkdir(parents=True)
other.rename(target)
with pytest.raises(ValueError, match="other") as e:
load_seg_bundle(SYNTHETIC, bundles_dir=tmp_path)
_assert_no_pii(e.value, extra=[str(tmp_path)])
def test_load_tampered_manifest_raises(tmp_path: Path) -> None:
bundle_dir = write_synthetic_bundle(
tmp_path, train_pairs=2, test_pairs=1, seed=0, image_size=SIZE
)
manifest = bundle_dir / "manifest.csv"
manifest.write_bytes(manifest.read_bytes() + b"\n")
with pytest.raises(ValueError) as e:
load_seg_bundle(SYNTHETIC, bundles_dir=tmp_path)
_assert_no_pii(e.value, extra=[str(tmp_path), "syn-c", "syn-s"])
def test_load_verify_failure_hides_hashes(tmp_path: Path) -> None:
bundle_dir = write_synthetic_bundle(
tmp_path, train_pairs=2, test_pairs=1, seed=0, image_size=SIZE
)
removed = sorted((bundle_dir / "files").iterdir())[0]
removed.unlink()
# verify なしでは中身を照合しないので開ける.
load_seg_bundle(SYNTHETIC, bundles_dir=tmp_path)
with pytest.raises(ValueError) as e:
load_seg_bundle(SYNTHETIC, bundles_dir=tmp_path, verify=True)
_assert_no_pii(e.value, extra=[str(tmp_path), removed.stem[:12], "syn-c", "syn-s"])
def test_load_bundle_with_unpaired_image_raises(tmp_path: Path) -> None:
bundle_dir = write_synthetic_bundle(
tmp_path, train_pairs=3, test_pairs=1, seed=0, image_size=SIZE
)
kinds = _manifest_kinds(bundle_dir)
mask_lines = [n for n, kind in enumerate(kinds, start=2) if kind == MASK_KIND]
# マスクの行を 1 つ消す(残りの正常な組があっても止まる).
_rewrite_manifest(bundle_dir, [n for n in range(2, len(kinds) + 2) if n != mask_lines[0]])
with pytest.raises(ValueError, match="組になっていない") as e:
load_seg_bundle(SYNTHETIC, bundles_dir=tmp_path)
_assert_no_pii(e.value, extra=[str(tmp_path), "syn-c", "syn-s"])
# ---------------------------------------------------------------------------
# validate_image_size
# ---------------------------------------------------------------------------
@pytest.mark.parametrize("size", [(32, 32), (256, 256), (64, 96), (512, 32)])
def test_image_size_multiple_of_32_passes(size: tuple[int, int]) -> None:
validate_image_size(size)
@pytest.mark.parametrize("size", [(255, 256), (256, 255), (16, 32), (100, 100), (33, 64)])
def test_image_size_not_multiple_of_32_raises(size: tuple[int, int]) -> None:
with pytest.raises(ValueError):
validate_image_size(size)
# ---------------------------------------------------------------------------
# validate_records
# ---------------------------------------------------------------------------
def test_validate_records_passes_for_valid_pairs(tmp_path: Path) -> None:
records = [_record(tmp_path, 0), _record(tmp_path, 1, subset=SUBSET_TEST)]
validate_records(records, SIZE)
def test_validate_records_allows_empty_train_mask(tmp_path: Path) -> None:
records = [
_record(tmp_path, 0, mask=_mask(empty=True)),
_record(tmp_path, 1, subset=SUBSET_TEST),
]
validate_records(records, SIZE)
@pytest.mark.parametrize("fill", [0, 128], ids=["zero", "exactly-128"])
def test_validate_records_rejects_empty_test_mask(tmp_path: Path, fill: int) -> None:
# 128 ちょうどは舌以外(SPEC_02「入力の前処理」)なので,舌の画素が無いマスクになる.
records = [
_record(tmp_path, 0),
_record(tmp_path, 1, subset=SUBSET_TEST, mask=_mask(fill=fill)),
]
with pytest.raises(ValueError, match="1 件") as e:
validate_records(records, SIZE)
assert "4 行目" in str(e.value)
assert SUBSET_TEST in str(e.value)
_assert_no_pii(e.value, extra=[str(tmp_path)])
def test_validate_records_rejects_missing_image(tmp_path: Path) -> None:
records = [_record(tmp_path, 0), _record(tmp_path, 1, write_image=False, subset=SUBSET_TEST)]
with pytest.raises(ValueError, match="1 件") as e:
validate_records(records, SIZE)
assert "4 行目" in str(e.value)
_assert_no_pii(e.value, extra=[str(tmp_path)])
def test_validate_records_rejects_undecodable_mask(tmp_path: Path) -> None:
record = _record(tmp_path, 0)
record.mask_path.write_bytes(b"not a png")
with pytest.raises(ValueError) as e:
validate_records([record, _record(tmp_path, 1, subset=SUBSET_TEST)], SIZE)
assert "3 行目" in str(e.value)
_assert_no_pii(e.value, extra=[str(tmp_path)])
def test_validate_records_rejects_pair_size_mismatch(tmp_path: Path) -> None:
records = [
_record(tmp_path, 0, mask=_mask((32, 64))),
_record(tmp_path, 1, subset=SUBSET_TEST),
]
with pytest.raises(ValueError, match="1 件") as e:
validate_records(records, SIZE)
assert "2 行目" in str(e.value)
_assert_no_pii(e.value, extra=[str(tmp_path)])
def test_validate_records_rejects_size_different_from_config(tmp_path: Path) -> None:
# 画像とマスクは互いに一致するが,設定の大きさと違う.
records = [
_record(tmp_path, 0, image=_image((64, 64)), mask=_mask((64, 64))),
_record(tmp_path, 1, subset=SUBSET_TEST),
]
with pytest.raises(ValueError, match="1 件") as e:
validate_records(records, SIZE)
_assert_no_pii(e.value, extra=[str(tmp_path)])
def test_validate_records_rejects_size_not_multiple_of_32(tmp_path: Path) -> None:
size = (48, 48)
records = [
_record(tmp_path, 0, image=_image(size), mask=_mask(size)),
_record(tmp_path, 1, subset=SUBSET_TEST, image=_image(size), mask=_mask(size)),
]
with pytest.raises(ValueError, match="32"):
validate_records(records, size)
def test_validate_records_checks_all_and_reports_count(tmp_path: Path) -> None:
records = [_record(tmp_path, i, mask=_mask((32, 64))) for i in range(7)]
records.append(_record(tmp_path, 7, subset=SUBSET_TEST))
with pytest.raises(ValueError) as e:
validate_records(records, SIZE)
message = str(e.value)
assert "7 件" in message and "8 件" in message
# 最初の 5 件(画像の行 2・4・6・8・10)だけを示す.
for line in (2, 4, 6, 8, 10):
assert f"{line} 行目" in message
assert "12 行目" not in message and "14 行目" not in message
_assert_no_pii(e.value, extra=[str(tmp_path)])
def test_validate_records_reports_problems_after_first_valid_records(tmp_path: Path) -> None:
# 正常な組が先にあっても,後ろの問題で止まる(黙って除かない).
records = [_record(tmp_path, i) for i in range(3)]
records.append(_record(tmp_path, 3, subset=SUBSET_TEST, mask=_mask(empty=True)))
with pytest.raises(ValueError, match="1 件"):
validate_records(records, SIZE)