Skip to content

Commit bc6ec1d

Browse files
expanded condition to truncate reported issues (#1730)
* expanded condition to truncate reported issues * fix test --------- Co-authored-by: Samuel Johnson <96841389+SFJohnson24@users.noreply.github.com>
1 parent e13ed6a commit bc6ec1d

4 files changed

Lines changed: 3232 additions & 2 deletions

File tree

cdisc_rules_engine/rules_engine.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,13 @@ def _update_total_errors_and_check_limit(
195195

196196
def _truncate_dataset_errors(self, dataset_results, rule, dataset_metadata):
197197
for result in dataset_results:
198-
if result.get("executionStatus") == "success":
198+
if result.get("executionStatus") in [
199+
ExecutionStatus.ISSUE_REPORTED.value,
200+
ExecutionStatus.SUCCESS.value,
201+
]:
199202
errors = result.get("errors", [])
200203
if len(errors) > self.max_errors_per_rule:
204+
result["original_errors_len"] = len(errors)
201205
result["errors"] = errors[: self.max_errors_per_rule]
202206
logger.info(
203207
f"Rule {rule.get('core_id')}: Truncated {len(errors)} errors to "

cdisc_rules_engine/services/reporting/sdtm_report_data.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,14 @@ def get_summary_data(self) -> list[dict]:
224224
result.get("errors")
225225
and result.get("executionStatus") != ExecutionStatus.SKIPPED.value
226226
):
227+
issues = result.get("original_errors_len") or len(
228+
result.get("errors", [])
229+
)
227230
summary_item = {
228231
"dataset": dataset,
229232
"core_id": validation_result.id,
230233
"message": result.get("message"),
231-
"issues": len(result.get("errors")),
234+
"issues": issues,
232235
}
233236
summary_data.append(summary_item)
234237

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import os
2+
import subprocess
3+
import pytest
4+
import json
5+
from conftest import get_python_executable
6+
7+
8+
@pytest.mark.regression
9+
class TestCoreIssue1718:
10+
def test_max_issues(self):
11+
# Run the command in the terminal
12+
max_issues = 3
13+
command = [
14+
f"{get_python_executable()}",
15+
"-m",
16+
"core",
17+
"validate",
18+
"-s",
19+
"sdtmig",
20+
"-v",
21+
"3-4",
22+
"-d",
23+
os.path.join(
24+
"tests",
25+
"resources",
26+
"CoreIssue1718",
27+
),
28+
"-r",
29+
"CORE-000356",
30+
"-ps",
31+
"1",
32+
"-of",
33+
"json",
34+
"-me",
35+
f"{max_issues}",
36+
"true",
37+
]
38+
subprocess.run(command, check=True)
39+
40+
files = os.listdir()
41+
json_files = [
42+
file
43+
for file in files
44+
if file.startswith("CORE-Report-") and file.endswith(".json")
45+
]
46+
json_report_path = sorted(json_files)[-1]
47+
json_report = json.load(open(json_report_path))
48+
assert {
49+
"Conformance_Details",
50+
"Dataset_Details",
51+
"Issue_Summary",
52+
"Issue_Details",
53+
"Rules_Report",
54+
}.issubset(json_report.keys())
55+
assert json_report["Rules_Report"][0]["status"] == "ISSUE REPORTED"
56+
assert json_report["Issue_Summary"][0]["issues"] == 74
57+
assert len(json_report["Issue_Details"]) == max_issues
58+
59+
if os.path.exists(json_report_path):
60+
os.remove(json_report_path)

0 commit comments

Comments
 (0)