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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The released versions correspond to PyPi releases.
## Unreleased

### Fixes
* Error totals correctly count accumulated module errors across repeated updates.
* File validation restores the caller's pydicom reading validation mode after
dataset validation and result handling, including when either raises an error.
* DICOM filenames in HTML report headings are escaped so markup characters
Expand Down
59 changes: 59 additions & 0 deletions dicom_validator/tests/validator/test_validation_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import pytest

from dicom_validator.validator.validation_result import (
DicomTag,
ErrorCode,
TagError,
ValidationResult,
)


@pytest.mark.parametrize("initial_errors", [0, 1])
@pytest.mark.parametrize(
"batches, expected_counts",
[
([(0x00100010,), (0x00100020,)], [1, 2]),
([(0x00100010, 0x00100020), (0x00100020, 0x00100030)], [2, 3]),
([(0x00100010, 0x00100020), (0x00100010,)], [2, 2]),
([(0x00100010, 0x00100020), (0x00100010, 0x00100020)], [2, 2]),
([(0x00100010, 0x00100020), ()], [2, 2]),
([(0x00100010,), (0x00100020,), (0x00100010,), (0x00100020,)], [1, 2, 2, 2]),
],
)
def test_add_tag_errors_accumulates_distinct_tags(
initial_errors, batches, expected_counts
):
result = ValidationResult(errors=initial_errors)
retained_tags = set()

for batch, expected_count in zip(batches, expected_counts):
errors = {DicomTag(tag): TagError(code=ErrorCode.TagMissing) for tag in batch}
result.add_tag_errors("Patient", errors)
retained_tags.update(errors)

assert result.errors == initial_errors + expected_count
assert set(result.module_errors["Patient"]) == retained_tags


def test_add_tag_errors_counts_each_module():
result = ValidationResult()
tag = DicomTag(0x00100010)
errors = {tag: TagError(code=ErrorCode.TagMissing)}

result.add_tag_errors("Patient", errors)
result.add_tag_errors("Other", errors)

assert result.errors == 2
assert result.module_errors == {"Patient": errors, "Other": errors}


def test_add_tag_errors_updates_existing_error():
result = ValidationResult()
tag = DicomTag(0x00100010)
result.add_tag_errors("Patient", {tag: TagError(code=ErrorCode.TagMissing)})
replacement = TagError(code=ErrorCode.TagEmpty)

result.add_tag_errors("Patient", {tag: replacement})

assert result.errors == 1
assert result.module_errors["Patient"][tag] is replacement
2 changes: 1 addition & 1 deletion dicom_validator/validator/validation_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,4 @@ def reset(self):
def add_tag_errors(self, module_name: str, tag_errors: TagErrors) -> None:
nr_module_errors = len(self.module_errors.get(module_name, []))
self.module_errors.setdefault(module_name, {}).update(tag_errors)
self.errors += len(tag_errors) - nr_module_errors
self.errors += len(self.module_errors[module_name]) - nr_module_errors
Loading