diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index 38a9e55ae..7f1205b9a 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -24,4 +24,3 @@ jobs: run: | python -m pytest tests/unit/ --cov=cdisc_rules_engine --cov-fail-under=75 python -m pytest tests/QARegressionTests/ - python -m pytest -m regression tests/QARegressionTests/test_Issues diff --git a/tests/QARegressionTests/globals.py b/tests/QARegressionTests/globals.py index 1ed0bc456..2512adb2a 100644 --- a/tests/QARegressionTests/globals.py +++ b/tests/QARegressionTests/globals.py @@ -1,10 +1,10 @@ -issue_datails_sheet = "Issue Details" -dataset_details_sheet = "Dataset Details" -entity_details_sheet = "Entity Details" -rules_report_sheet = "Rules Report" -issue_sheet_coreid_column = "A" -dataset_sheet_dataset_column = "A" -rules_sheet_rule_status_column = "F" -issue_sheet_record_column = "G" -issue_sheet_variable_column = "I" -issue_sheet_values_column = "J" +issue_datails_sheet = "Issue Details" +dataset_details_sheet = "Dataset Details" +entity_details_sheet = "Entity Details" +rules_report_sheet = "Rules Report" +issue_sheet_coreid_column = "A" +dataset_sheet_dataset_column = "A" +rules_sheet_rule_status_column = "F" +issue_sheet_record_column = "F" +issue_sheet_variable_column = "H" +issue_sheet_values_column = "I" diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1204.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1204.py index 24ec2349c..a1bd1045a 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1204.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1204.py @@ -1,40 +1,40 @@ -import subprocess -import pytest -from conftest import get_python_executable - - -@pytest.mark.regression -def test_non_existing_dataset_shows_helpful_error(): - """Test that the engine displays a helpful error message if dataset files are not found""" - command = [ - get_python_executable(), - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3.4", - "-dp", - "ds.json", - "-dp", - "ds2.json", - ] - - process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = process.communicate() - - stderr_text = stderr.decode() - stdout_text = stdout.decode() - - assert process.returncode == 2, "Expected non-zero exit code" - assert ( - "FileNotFoundError" not in stderr_text - ), "Should not show FileNotFoundError crash" - assert ( - "Failed to execute script" not in stderr_text - ), "Should not show script execution failure" - assert "Files ds.json, ds2.json are not found" in stderr_text, ( - f"Expected helpful error message about non-existing dataset files. " - f"stderr: {stderr_text}, stdout: {stdout_text}" - ) +import subprocess +import pytest +from conftest import get_python_executable + + +@pytest.mark.regression +def test_non_existing_dataset_shows_helpful_error(): + """Test that the engine displays a helpful error message if dataset files are not found""" + command = [ + get_python_executable(), + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3.4", + "-dp", + "ds.json", + "-dp", + "ds2.json", + ] + + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + + stderr_text = stderr.decode() + stdout_text = stdout.decode() + + assert process.returncode == 2, "Expected non-zero exit code" + assert ( + "FileNotFoundError" not in stderr_text + ), "Should not show FileNotFoundError crash" + assert ( + "Failed to execute script" not in stderr_text + ), "Should not show script execution failure" + assert "Files ds.json, ds2.json are not found" in stderr_text, ( + f"Expected helpful error message about non-existing dataset files. " + f"stderr: {stderr_text}, stdout: {stdout_text}" + ) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1248.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1248.py index b5b60572d..ab44096d3 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1248.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1248.py @@ -1,186 +1,186 @@ -import os -import subprocess - -import pytest -import json -from conftest import get_python_executable - - -@pytest.mark.regression -class TestCoreIssue1248: - @pytest.mark.parametrize( - "command,rules_report,num_issues", - [ - # define path provided will lead to successful execution - ( - [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3-2", - "-of", - "JSON", - "-lr", - os.path.join("tests", "resources", "CoreIssue1248", "sample.yml"), - "-cs", - "-dxp", - os.path.join( - "tests", - "resources", - "CoreIssue1248", - "define_subfolder", - "define.xml", - ), - "-ps", - "1", - "-dp", - os.path.join("tests", "resources", "CoreIssue1248", "data.xlsx"), - ], - [ - { - "core_id": "SD1129", - "version": "1", - "cdisc_rule_id": "", - "fda_rule_id": "", - "message": "TEST", - "status": "ISSUE REPORTED", - } - ], - 2, - ), - # JSON data file and no define.xml in same folder and no -dxp param will provide error - ( - [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3-2", - "-of", - "JSON", - "-lr", - os.path.join("tests", "resources", "CoreIssue1248", "sample.yml"), - "-cs", - "-dp", - os.path.join("tests", "resources", "CoreIssue1248", "relrec.json"), - "-ps", - "1", - ], - [ - { - "core_id": "SD1129", - "version": "1", - "cdisc_rule_id": "", - "fda_rule_id": "", - "message": "TEST", - "status": "EXECUTION ERROR", - } - ], - 1, - ), - # no define.xml in same path as data.xlsx file will provide error - ( - [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3-2", - "-of", - "JSON", - "-lr", - os.path.join("tests", "resources", "CoreIssue1248", "sample.yml"), - "-cs", - "-dp", - os.path.join("tests", "resources", "CoreIssue1248", "data.xlsx"), - "-ps", - "1", - ], - [ - { - "core_id": "SD1129", - "version": "1", - "cdisc_rule_id": "", - "fda_rule_id": "", - "message": "TEST", - "status": "EXECUTION ERROR", - } - ], - 1, - ), - # define.xml in same folder as the data.xls and no -dxp provided will provide error until - # in ExcelDataService dataset metadata creation full_path=dataset_name - ( - [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3-2", - "-of", - "JSON", - "-lr", - os.path.join("tests", "resources", "CoreIssue1248", "sample.yml"), - "-cs", - "-dp", - os.path.join( - "tests", - "resources", - "CoreIssue1248", - "data_and_define", - "data.xlsx", - ), - "-ps", - "1", - ], - [ - { - "core_id": "SD1129", - "version": "1", - "cdisc_rule_id": "", - "fda_rule_id": "", - "message": "TEST", - "status": "EXECUTION ERROR", - } - ], - 1, - ), - ], - ) - def test_define_path_used(self, command, rules_report, num_issues): - subprocess.run(command, check=True) - - # Get the latest created report file - files = os.listdir() - json_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".json") - ] - json_report_path = sorted(json_files)[-1] - # Open the JSON report file - json_report = json.load(open(json_report_path)) - assert { - "Conformance_Details", - "Dataset_Details", - "Issue_Summary", - "Issue_Details", - "Rules_Report", - }.issubset(json_report.keys()) - assert len(json_report["Issue_Details"]) == num_issues - assert json_report["Rules_Report"] == rules_report - if os.path.exists(json_report_path): - os.remove(json_report_path) +import os +import subprocess + +import pytest +import json +from conftest import get_python_executable + + +@pytest.mark.regression +class TestCoreIssue1248: + @pytest.mark.parametrize( + "command,rules_report,num_issues", + [ + # define path provided will lead to successful execution + ( + [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3-2", + "-of", + "JSON", + "-lr", + os.path.join("tests", "resources", "CoreIssue1248", "sample.yml"), + "-cs", + "-dxp", + os.path.join( + "tests", + "resources", + "CoreIssue1248", + "define_subfolder", + "define.xml", + ), + "-ps", + "1", + "-dp", + os.path.join("tests", "resources", "CoreIssue1248", "data.xlsx"), + ], + [ + { + "core_id": "SD1129", + "version": "1", + "cdisc_rule_id": "", + "fda_rule_id": "", + "message": "TEST", + "status": "ISSUE REPORTED", + } + ], + 2, + ), + # JSON data file and no define.xml in same folder and no -dxp param will provide error + ( + [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3-2", + "-of", + "JSON", + "-lr", + os.path.join("tests", "resources", "CoreIssue1248", "sample.yml"), + "-cs", + "-dp", + os.path.join("tests", "resources", "CoreIssue1248", "relrec.json"), + "-ps", + "1", + ], + [ + { + "core_id": "SD1129", + "version": "1", + "cdisc_rule_id": "", + "fda_rule_id": "", + "message": "TEST", + "status": "EXECUTION ERROR", + } + ], + 1, + ), + # no define.xml in same path as data.xlsx file will provide error + ( + [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3-2", + "-of", + "JSON", + "-lr", + os.path.join("tests", "resources", "CoreIssue1248", "sample.yml"), + "-cs", + "-dp", + os.path.join("tests", "resources", "CoreIssue1248", "data.xlsx"), + "-ps", + "1", + ], + [ + { + "core_id": "SD1129", + "version": "1", + "cdisc_rule_id": "", + "fda_rule_id": "", + "message": "TEST", + "status": "EXECUTION ERROR", + } + ], + 1, + ), + # define.xml in same folder as the data.xls and no -dxp provided will provide error until + # in ExcelDataService dataset metadata creation full_path=dataset_name + ( + [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3-2", + "-of", + "JSON", + "-lr", + os.path.join("tests", "resources", "CoreIssue1248", "sample.yml"), + "-cs", + "-dp", + os.path.join( + "tests", + "resources", + "CoreIssue1248", + "data_and_define", + "data.xlsx", + ), + "-ps", + "1", + ], + [ + { + "core_id": "SD1129", + "version": "1", + "cdisc_rule_id": "", + "fda_rule_id": "", + "message": "TEST", + "status": "EXECUTION ERROR", + } + ], + 1, + ), + ], + ) + def test_define_path_used(self, command, rules_report, num_issues): + subprocess.run(command, check=True) + + # Get the latest created report file + files = os.listdir() + json_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".json") + ] + json_report_path = sorted(json_files)[-1] + # Open the JSON report file + json_report = json.load(open(json_report_path)) + assert { + "Conformance_Details", + "Dataset_Details", + "Issue_Summary", + "Issue_Details", + "Rules_Report", + }.issubset(json_report.keys()) + assert len(json_report["Issue_Details"]) == num_issues + assert json_report["Rules_Report"] == rules_report + if os.path.exists(json_report_path): + os.remove(json_report_path) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1316.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1316.py index 44fdb8a87..0fdfd78dd 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1316.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1316.py @@ -1,58 +1,58 @@ -import os -import subprocess -import unittest - -import pytest -import json -from conftest import get_python_executable - - -@pytest.mark.regression -class TestCoreIssue1316(unittest.TestCase): - def test_new_rule(self): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3-4", - "-dp", - os.path.join( - "tests", - "resources", - "CoreIssue1316", - "test_dataset.json", - ), - "-lr", - os.path.join("tests", "resources", "CoreIssue1316", "rule_new.yml"), - "-ps", - "1", - "-of", - "json", - ] - subprocess.run(command, check=True) - - files = os.listdir() - json_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".json") - ] - json_report_path = sorted(json_files)[-1] - json_report = json.load(open(json_report_path)) - assert { - "Conformance_Details", - "Dataset_Details", - "Issue_Summary", - "Issue_Details", - "Rules_Report", - }.issubset(json_report.keys()) - assert json_report["Issue_Summary"][0]["issues"] == 591 - assert json_report["Rules_Report"][0]["status"] == "ISSUE REPORTED" - - if os.path.exists(json_report_path): - os.remove(json_report_path) +import os +import subprocess +import unittest + +import pytest +import json +from conftest import get_python_executable + + +@pytest.mark.regression +class TestCoreIssue1316(unittest.TestCase): + def test_new_rule(self): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3-4", + "-dp", + os.path.join( + "tests", + "resources", + "CoreIssue1316", + "test_dataset.json", + ), + "-lr", + os.path.join("tests", "resources", "CoreIssue1316", "rule_new.yml"), + "-ps", + "1", + "-of", + "json", + ] + subprocess.run(command, check=True) + + files = os.listdir() + json_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".json") + ] + json_report_path = sorted(json_files)[-1] + json_report = json.load(open(json_report_path)) + assert { + "Conformance_Details", + "Dataset_Details", + "Issue_Summary", + "Issue_Details", + "Rules_Report", + }.issubset(json_report.keys()) + assert json_report["Issue_Summary"][0]["issues"] == 591 + assert json_report["Rules_Report"][0]["status"] == "ISSUE REPORTED" + + if os.path.exists(json_report_path): + os.remove(json_report_path) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1326.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1326.py index dfef7a49c..3f55855cc 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1326.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1326.py @@ -1,169 +1,169 @@ -import os -import subprocess -import unittest -import openpyxl -import pytest -from conftest import get_python_executable -from QARegressionTests.globals import ( - entity_details_sheet, - issue_datails_sheet, - rules_report_sheet, - issue_sheet_record_column, - issue_sheet_variable_column, - issue_sheet_values_column, -) - - -@pytest.mark.regression -class TestPrefTerm(unittest.TestCase): - def test_positive_dataset(self): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "usdm", - "-v", - "3-0", - "-dp", - os.path.join( - "tests", - "resources", - "CoreIssue1326", - "regression-test-coreid-DDF00015-positive.json", - ), - "-lr", - os.path.join("tests", "resources", "CoreIssue1326", "rule.yml"), - ] - subprocess.run(command, check=True) - - # Get the latest created Excel file - files = os.listdir() - excel_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".xlsx") - ] - excel_file_path = sorted(excel_files)[-1] - # # Open the Excel file - workbook = openpyxl.load_workbook(excel_file_path) - - # Go to the "Issue Details" sheet - sheet = workbook[issue_datails_sheet] - - record_column = sheet[issue_sheet_record_column] - variables_column = sheet[issue_sheet_variable_column] - values_column = sheet[issue_sheet_values_column] - - record_values = [cell.value for cell in record_column[1:]] - variables_values = [cell.value for cell in variables_column[1:]] - values_column_values = [cell.value for cell in values_column[1:]] - - # Remove None values using list comprehension - record_values = [value for value in record_values if value is not None] - variables_values = [value for value in variables_values if value is not None] - values_column_values = [ - value for value in values_column_values if value is not None - ] - rules_values = [ - row for row in workbook[rules_report_sheet].iter_rows(values_only=True) - ][1:] - rules_values = [row for row in rules_values if any(row)] - # Perform the assertion - # Ensure only two negative values are caught - assert rules_values[0][0] == "CORE-000409" - assert rules_values[0][-1] == "SUCCESS" - assert len(record_values) == 0 - assert len(variables_values) == 0 - assert len(values_column_values) == 0 - if os.path.exists(excel_file_path): - os.remove(excel_file_path) - - def test_negative_dataset(self): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "usdm", - "-v", - "3-0", - "-dp", - os.path.join( - "tests", - "resources", - "CoreIssue1326", - "regression-test-coreid-DDF00015-negative.json", - ), - "-lr", - os.path.join("tests", "resources", "CoreIssue1326", "rule.yml"), - ] - subprocess.run(command, check=True) - - # Get the latest created Excel file - files = os.listdir() - excel_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".xlsx") - ] - excel_file_path = sorted(excel_files)[-1] - # # Open the Excel file - workbook = openpyxl.load_workbook(excel_file_path) - - # --- Entity Details --- - dataset_sheet = workbook[entity_details_sheet] - dataset_values = [row for row in dataset_sheet.iter_rows(values_only=True)][1:] - dataset_values = [row for row in dataset_values if any(row)] - assert len(dataset_values) > 0 - assert dataset_values[0][0] == "StudyVersion" - assert dataset_values[0][-1] == 7 - - # --- Issue Summary --- - issue_summary_sheet = workbook["Issue Summary"] - summary_values = [ - row for row in issue_summary_sheet.iter_rows(values_only=True) - ][1:] - summary_values = [row for row in summary_values if any(row)] - assert len(summary_values) > 0 - assert summary_values[0][1] == "CORE-000409" - assert summary_values[0][4] == 7 - - # --- Issue Details --- - expected_values = [ - "C199989, C199989, Phase II Trial, PHASE II TRIAL, C15601, Phase Ib Trial", - "null, null, Not Applicable, NOT APPLICABLE, C48660, N/A", - "C198366, C198366, null, null, C198366xx, Phase I/II/III Trial", - "C15600, C15600, null, null, C00001x, Phase I Trial", - "C198366, C198366, Phase II Trial, PHASE II TRIAL, C15601, Phase I/II/III Trial", - "C199989, C199989, null, null, C198366xx, PHASE IB TRIAL", - "null, null, Phase Ib Trial, PHASE IB TRIAL, C199989, PHASE 2 TRIAL", - ] - issue_details_sheet = workbook[issue_datails_sheet] - details_values = [ - row for row in issue_details_sheet.iter_rows(values_only=True) - ][1:] - details_values = [row for row in details_values if any(row)] - assert all(row[0] == "CORE-000409" for row in details_values) - actual_values = [row[-1] for row in details_values] - assert actual_values == expected_values - - # --- Rules Report --- - rules_values = [ - row for row in workbook[rules_report_sheet].iter_rows(values_only=True) - ][1:] - rules_values = [row for row in rules_values if any(row)] - assert len(rules_values) > 0 - assert rules_values[0][0] == "CORE-000409" - assert rules_values[0][-1] == "ISSUE REPORTED" - - if os.path.exists(excel_file_path): - os.remove(excel_file_path) - - -# if __name__ == "__main__": -# unittest.main() +import os +import subprocess +import unittest +import openpyxl +import pytest +from conftest import get_python_executable +from QARegressionTests.globals import ( + entity_details_sheet, + issue_datails_sheet, + rules_report_sheet, + issue_sheet_record_column, + issue_sheet_variable_column, + issue_sheet_values_column, +) + + +@pytest.mark.regression +class TestPrefTerm(unittest.TestCase): + def test_positive_dataset(self): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "usdm", + "-v", + "3-0", + "-dp", + os.path.join( + "tests", + "resources", + "CoreIssue1326", + "regression-test-coreid-DDF00015-positive.json", + ), + "-lr", + os.path.join("tests", "resources", "CoreIssue1326", "rule.yml"), + ] + subprocess.run(command, check=True) + + # Get the latest created Excel file + files = os.listdir() + excel_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".xlsx") + ] + excel_file_path = sorted(excel_files)[-1] + # # Open the Excel file + workbook = openpyxl.load_workbook(excel_file_path) + + # Go to the "Issue Details" sheet + sheet = workbook[issue_datails_sheet] + + record_column = sheet[issue_sheet_record_column] + variables_column = sheet[issue_sheet_variable_column] + values_column = sheet[issue_sheet_values_column] + + record_values = [cell.value for cell in record_column[1:]] + variables_values = [cell.value for cell in variables_column[1:]] + values_column_values = [cell.value for cell in values_column[1:]] + + # Remove None values using list comprehension + record_values = [value for value in record_values if value is not None] + variables_values = [value for value in variables_values if value is not None] + values_column_values = [ + value for value in values_column_values if value is not None + ] + rules_values = [ + row for row in workbook[rules_report_sheet].iter_rows(values_only=True) + ][1:] + rules_values = [row for row in rules_values if any(row)] + # Perform the assertion + # Ensure only two negative values are caught + assert rules_values[0][0] == "CORE-000409" + assert rules_values[0][-1] == "SUCCESS" + assert len(record_values) == 0 + assert len(variables_values) == 0 + assert len(values_column_values) == 0 + if os.path.exists(excel_file_path): + os.remove(excel_file_path) + + def test_negative_dataset(self): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "usdm", + "-v", + "3-0", + "-dp", + os.path.join( + "tests", + "resources", + "CoreIssue1326", + "regression-test-coreid-DDF00015-negative.json", + ), + "-lr", + os.path.join("tests", "resources", "CoreIssue1326", "rule.yml"), + ] + subprocess.run(command, check=True) + + # Get the latest created Excel file + files = os.listdir() + excel_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".xlsx") + ] + excel_file_path = sorted(excel_files)[-1] + # # Open the Excel file + workbook = openpyxl.load_workbook(excel_file_path) + + # --- Entity Details --- + dataset_sheet = workbook[entity_details_sheet] + dataset_values = [row for row in dataset_sheet.iter_rows(values_only=True)][1:] + dataset_values = [row for row in dataset_values if any(row)] + assert len(dataset_values) > 0 + assert dataset_values[0][0] == "StudyVersion" + assert dataset_values[0][-1] == 7 + + # --- Issue Summary --- + issue_summary_sheet = workbook["Issue Summary"] + summary_values = [ + row for row in issue_summary_sheet.iter_rows(values_only=True) + ][1:] + summary_values = [row for row in summary_values if any(row)] + assert len(summary_values) > 0 + assert summary_values[0][1] == "CORE-000409" + assert summary_values[0][4] == 7 + + # --- Issue Details --- + expected_values = [ + "C199989, C199989, Phase II Trial, PHASE II TRIAL, C15601, Phase Ib Trial", + "null, null, Not Applicable, NOT APPLICABLE, C48660, N/A", + "C198366, C198366, null, null, C198366xx, Phase I/II/III Trial", + "C15600, C15600, null, null, C00001x, Phase I Trial", + "C198366, C198366, Phase II Trial, PHASE II TRIAL, C15601, Phase I/II/III Trial", + "C199989, C199989, null, null, C198366xx, PHASE IB TRIAL", + "null, null, Phase Ib Trial, PHASE IB TRIAL, C199989, PHASE 2 TRIAL", + ] + issue_details_sheet = workbook[issue_datails_sheet] + details_values = [ + row for row in issue_details_sheet.iter_rows(values_only=True) + ][1:] + details_values = [row for row in details_values if any(row)] + assert all(row[0] == "CORE-000409" for row in details_values) + actual_values = [row[-1] for row in details_values] + assert actual_values == expected_values + + # --- Rules Report --- + rules_values = [ + row for row in workbook[rules_report_sheet].iter_rows(values_only=True) + ][1:] + rules_values = [row for row in rules_values if any(row)] + assert len(rules_values) > 0 + assert rules_values[0][0] == "CORE-000409" + assert rules_values[0][-1] == "ISSUE REPORTED" + + if os.path.exists(excel_file_path): + os.remove(excel_file_path) + + +# if __name__ == "__main__": +# unittest.main() diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1332.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1332.py index ff98b9148..d121a8e75 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1332.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1332.py @@ -1,111 +1,111 @@ -import os -import subprocess -import openpyxl -import pytest -from conftest import get_python_executable -from QARegressionTests.globals import ( - issue_datails_sheet, - rules_report_sheet, -) - - -@pytest.mark.regression -def test_ap_domain_should_be_correctly_substituted(): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3-3", - "-dp", - os.path.join( - "tests", - "resources", - "CoreIssue1332", - "Datasets.json", - ), - "-lr", - os.path.join("tests", "resources", "CoreIssue1332", "Rule.yml"), - ] - subprocess.run(command, check=True) - - files = os.listdir() - excel_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".xlsx") - ] - excel_file_path = sorted(excel_files)[-1] - - # # Open the Excel file - workbook = openpyxl.load_workbook(excel_file_path) - - # Go to the "Issue Details" sheet - sheet = workbook[issue_datails_sheet] - details_values = [row for row in sheet.iter_rows(values_only=True)][1:] - details_values = [row for row in details_values if any(row)] - assert len(details_values) == 8 - - # CORE-ID - assert all(row[0] == "CORE-000181" for row in details_values) - - # Message - assert ( - len( - [ - row - for row in details_values - if row[1] == "APMH Domain value length is not equal to 4." - ] - ) - == 4 - ) - assert ( - len( - [ - row - for row in details_values - if row[1] == "APSQ Domain value length is not equal to 4." - ] - ) - == 4 - ) - - # Variable(s) - assert len([row for row in details_values if row[7] == "MHTERM"]) == 4 - assert len([row for row in details_values if row[7] == "SQTERM"]) == 4 - - # Value(s) - assert all(row[8] == "POMPE DISEASE" for row in details_values) - - # Go to the "Issue Summary" sheet - issue_summary_sheet = workbook["Issue Summary"] - summary_values = [row for row in issue_summary_sheet.iter_rows(values_only=True)][ - 1: - ] - summary_values = [row for row in summary_values if any(row)] - assert len(summary_values) == 2 - assert all(row[1] == "CORE-000181" for row in summary_values) # CORE-ID - assert ( - summary_values[0][2] == "APMH Domain value length is not equal to 4." - ) # Message - assert ( - summary_values[1][2] == "APSQ Domain value length is not equal to 4." - ) # Message - assert all(row[3] == 4 for row in summary_values) # Issues - - # --- Rules Report --- - rules_values = [ - row for row in workbook[rules_report_sheet].iter_rows(values_only=True) - ][1:] - rules_values = [row for row in rules_values if any(row)] - assert len(rules_values) == 1 - assert rules_values[0][0] == "CORE-000181" - assert "ISSUE REPORTED" in rules_values[0] - - if os.path.exists(excel_file_path): - os.remove(excel_file_path) +import os +import subprocess +import openpyxl +import pytest +from conftest import get_python_executable +from QARegressionTests.globals import ( + issue_datails_sheet, + rules_report_sheet, +) + + +@pytest.mark.regression +def test_ap_domain_should_be_correctly_substituted(): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3-3", + "-dp", + os.path.join( + "tests", + "resources", + "CoreIssue1332", + "Datasets.json", + ), + "-lr", + os.path.join("tests", "resources", "CoreIssue1332", "Rule.yml"), + ] + subprocess.run(command, check=True) + + files = os.listdir() + excel_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".xlsx") + ] + excel_file_path = sorted(excel_files)[-1] + + # # Open the Excel file + workbook = openpyxl.load_workbook(excel_file_path) + + # Go to the "Issue Details" sheet + sheet = workbook[issue_datails_sheet] + details_values = [row for row in sheet.iter_rows(values_only=True)][1:] + details_values = [row for row in details_values if any(row)] + assert len(details_values) == 8 + + # CORE-ID + assert all(row[0] == "CORE-000181" for row in details_values) + + # Message + assert ( + len( + [ + row + for row in details_values + if row[1] == "APMH Domain value length is not equal to 4." + ] + ) + == 4 + ) + assert ( + len( + [ + row + for row in details_values + if row[1] == "APSQ Domain value length is not equal to 4." + ] + ) + == 4 + ) + + # Variable(s) + assert len([row for row in details_values if row[7] == "MHTERM"]) == 4 + assert len([row for row in details_values if row[7] == "SQTERM"]) == 4 + + # Value(s) + assert all(row[8] == "POMPE DISEASE" for row in details_values) + + # Go to the "Issue Summary" sheet + issue_summary_sheet = workbook["Issue Summary"] + summary_values = [row for row in issue_summary_sheet.iter_rows(values_only=True)][ + 1: + ] + summary_values = [row for row in summary_values if any(row)] + assert len(summary_values) == 2 + assert all(row[1] == "CORE-000181" for row in summary_values) # CORE-ID + assert ( + summary_values[0][2] == "APMH Domain value length is not equal to 4." + ) # Message + assert ( + summary_values[1][2] == "APSQ Domain value length is not equal to 4." + ) # Message + assert all(row[3] == 4 for row in summary_values) # Issues + + # --- Rules Report --- + rules_values = [ + row for row in workbook[rules_report_sheet].iter_rows(values_only=True) + ][1:] + rules_values = [row for row in rules_values if any(row)] + assert len(rules_values) == 1 + assert rules_values[0][0] == "CORE-000181" + assert "ISSUE REPORTED" in rules_values[0] + + if os.path.exists(excel_file_path): + os.remove(excel_file_path) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1345.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1345.py index bb160fd3f..54fb0c436 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1345.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1345.py @@ -1,167 +1,167 @@ -import os -import subprocess - -import pytest -import json -from conftest import get_python_executable - - -@pytest.fixture -def generate_report(): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3-4", - "-dxp", - os.path.join( - "tests", - "resources", - "CoreIssue1345", - "define_msg20_testsupp_core.xml", - ), - "-d", - os.path.join( - "tests", - "resources", - "CoreIssue1345", - ), - "-lr", - os.path.join( - "tests", - "resources", - "CoreIssue1345", - ), - "-r", - "CDISC.SDTMIG.CG0019", - "-l", - "error", - "-ps", - "1", - "-of", - "json", - ] - subprocess.run(command, check=True) - # Get the latest created Excel file - files = os.listdir() - json_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".json") - ] - json_report_path = sorted(json_files)[-1] - json_report = json.load(open(json_report_path)) - return json_report_path, json_report - - -@pytest.mark.regression -class TestCoreIssue1345: - def test_engine_correctly_merges_datasets_and_flags_row_uniqueness_issues( - self, generate_report - ): - json_report_path, json_report = generate_report - dataset_filenames = { - d["filename"].upper() for d in json_report.get("Dataset_Details", []) - } - - assert "DM" in dataset_filenames, "DM dataset is missing from Dataset_Details" - assert ( - "SUPPDM" in dataset_filenames - ), "SUPPDM dataset is missing from Dataset_Details" - - # 2. check for DM / SUPPDM Issue_Details - dm_related_issues = [ - issue - for issue in json_report.get("Issue_Details", []) - if issue.get("dataset", "") in {"DM", "SUPPDM"} - ] - - assert not dm_related_issues, ( - "Found issues related to DM/SUPPDM datasets:\n" f"{dm_related_issues}" - ) - - dm_related_summary = [ - s - for s in json_report.get("Issue_Summary", []) - if s.get("dataset", "") in {"DM", "SUPPDM"} - ] - - assert not dm_related_summary, ( - "Found issue summary entries related to DM/SUPPDM:\n" - f"{dm_related_summary}" - ) - - ec_detail_issues = [ - i - for i in json_report.get("Issue_Details", []) - if i.get("dataset", "") in {"EC"} - ] - - assert ( - ec_detail_issues - ), "Expected EC-related issues in Issue_Details, but none found" - assert ( - len(ec_detail_issues) == 2 - ), f"Expected 2 issues for EC dataset, but {len(ec_detail_issues)} found in Issue_Details" - - ec_summary_issues = [ - s - for s in json_report.get("Issue_Summary", []) - if s.get("dataset", "") in {"EC"} - ] - - assert ( - ec_summary_issues - ), "Expected issues for EC dataset, but none found in Issue_Summary" - - if os.path.exists(json_report_path): - os.remove(json_report_path) - - def test_engine_correctly_processes_relrec_when_supp_datasets_provided( - self, generate_report - ): - json_report_path, json_report = generate_report - # Open the JSON report file - dataset_filenames = { - d["filename"].upper() for d in json_report.get("Dataset_Details", []) - } - - assert "DM" in dataset_filenames, "DM dataset is missing from Dataset_Details" - assert ( - "SUPPDM" in dataset_filenames - ), "SUPPDM dataset is missing from Dataset_Details" - assert "EC" in dataset_filenames, "EC dataset is missing from Dataset_Details" - assert ( - "SUPPEC" in dataset_filenames - ), "SUPPEC dataset is missing from Dataset_Details" - - # check that relrec was processed and rule checked the data - assert ( - "RELREC" in dataset_filenames - ), "RELREC dataset is missing from Dataset_Details" - relrec_issues = [ - i - for i in json_report.get("Issue_Details", []) - if i.get("dataset", "") in {"RELREC"} - ] - assert ( - len(relrec_issues) == 2 - ), f"Expected 2 issues for RELREC dataset, but {len(relrec_issues)} found" - - # to confirm that EC is still processed and contains issues - ec_detail_issues = [ - i - for i in json_report.get("Issue_Details", []) - if i.get("dataset", "") in {"EC"} - ] - assert ( - len(ec_detail_issues) == 2 - ), f"Expected 2 issues for EC dataset, but {len(ec_detail_issues)} found in Issue_Details" - - if os.path.exists(json_report_path): - os.remove(json_report_path) +import os +import subprocess + +import pytest +import json +from conftest import get_python_executable + + +@pytest.fixture +def generate_report(): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3-4", + "-dxp", + os.path.join( + "tests", + "resources", + "CoreIssue1345", + "define_msg20_testsupp_core.xml", + ), + "-d", + os.path.join( + "tests", + "resources", + "CoreIssue1345", + ), + "-lr", + os.path.join( + "tests", + "resources", + "CoreIssue1345", + ), + "-r", + "CDISC.SDTMIG.CG0019", + "-l", + "error", + "-ps", + "1", + "-of", + "json", + ] + subprocess.run(command, check=True) + # Get the latest created Excel file + files = os.listdir() + json_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".json") + ] + json_report_path = sorted(json_files)[-1] + json_report = json.load(open(json_report_path)) + return json_report_path, json_report + + +@pytest.mark.regression +class TestCoreIssue1345: + def test_engine_correctly_merges_datasets_and_flags_row_uniqueness_issues( + self, generate_report + ): + json_report_path, json_report = generate_report + dataset_filenames = { + d["filename"].upper() for d in json_report.get("Dataset_Details", []) + } + + assert "DM" in dataset_filenames, "DM dataset is missing from Dataset_Details" + assert ( + "SUPPDM" in dataset_filenames + ), "SUPPDM dataset is missing from Dataset_Details" + + # 2. check for DM / SUPPDM Issue_Details + dm_related_issues = [ + issue + for issue in json_report.get("Issue_Details", []) + if issue.get("dataset", "") in {"DM", "SUPPDM"} + ] + + assert not dm_related_issues, ( + "Found issues related to DM/SUPPDM datasets:\n" f"{dm_related_issues}" + ) + + dm_related_summary = [ + s + for s in json_report.get("Issue_Summary", []) + if s.get("dataset", "") in {"DM", "SUPPDM"} + ] + + assert not dm_related_summary, ( + "Found issue summary entries related to DM/SUPPDM:\n" + f"{dm_related_summary}" + ) + + ec_detail_issues = [ + i + for i in json_report.get("Issue_Details", []) + if i.get("dataset", "") in {"EC"} + ] + + assert ( + ec_detail_issues + ), "Expected EC-related issues in Issue_Details, but none found" + assert ( + len(ec_detail_issues) == 2 + ), f"Expected 2 issues for EC dataset, but {len(ec_detail_issues)} found in Issue_Details" + + ec_summary_issues = [ + s + for s in json_report.get("Issue_Summary", []) + if s.get("dataset", "") in {"EC"} + ] + + assert ( + ec_summary_issues + ), "Expected issues for EC dataset, but none found in Issue_Summary" + + if os.path.exists(json_report_path): + os.remove(json_report_path) + + def test_engine_correctly_processes_relrec_when_supp_datasets_provided( + self, generate_report + ): + json_report_path, json_report = generate_report + # Open the JSON report file + dataset_filenames = { + d["filename"].upper() for d in json_report.get("Dataset_Details", []) + } + + assert "DM" in dataset_filenames, "DM dataset is missing from Dataset_Details" + assert ( + "SUPPDM" in dataset_filenames + ), "SUPPDM dataset is missing from Dataset_Details" + assert "EC" in dataset_filenames, "EC dataset is missing from Dataset_Details" + assert ( + "SUPPEC" in dataset_filenames + ), "SUPPEC dataset is missing from Dataset_Details" + + # check that relrec was processed and rule checked the data + assert ( + "RELREC" in dataset_filenames + ), "RELREC dataset is missing from Dataset_Details" + relrec_issues = [ + i + for i in json_report.get("Issue_Details", []) + if i.get("dataset", "") in {"RELREC"} + ] + assert ( + len(relrec_issues) == 2 + ), f"Expected 2 issues for RELREC dataset, but {len(relrec_issues)} found" + + # to confirm that EC is still processed and contains issues + ec_detail_issues = [ + i + for i in json_report.get("Issue_Details", []) + if i.get("dataset", "") in {"EC"} + ] + assert ( + len(ec_detail_issues) == 2 + ), f"Expected 2 issues for EC dataset, but {len(ec_detail_issues)} found in Issue_Details" + + if os.path.exists(json_report_path): + os.remove(json_report_path) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1348.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1348.py index 74c41a025..484f64833 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1348.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1348.py @@ -1,234 +1,234 @@ -import os -import subprocess - -import pytest -import json -from conftest import get_python_executable - -_message = ( - "The study version's study phase is not specified according to the extensible Trial Phase Response" - ' (C66737) SDTM codelist - codeSystem is not "http://www.cdisc.org", codeSystemVersion is not a valid' - " terminology package date, and/or the code or decode is found in the codelist (case insensitive)" - " but the corresponding decode or code does not match the codelist value (case sensitive)." -) -_summary = [ - { - "dataset": "StudyVersion", - "core_id": "CORE-000409", - "message": _message, - "issues": 7, - } -] -_issue_details = [ - { - "core_id": "CORE-000409", - "message": _message, - "executability": "fully executable", - "dataset": "StudyVersion", - "USUBJID": "", - "row": 1, - "SEQ": "", - "variables": [ - "$code_for_pref_term", - "$code_for_value", - "$pref_term_for_code", - "$value_for_code", - "studyPhase.standardCode.code", - "studyPhase.standardCode.decode", - ], - "values": [ - "C199989", - "C199989", - "Phase II Trial", - "PHASE II TRIAL", - "C15601", - "Phase Ib Trial", - ], - }, - { - "core_id": "CORE-000409", - "message": _message, - "executability": "fully executable", - "dataset": "StudyVersion", - "USUBJID": "", - "row": 2, - "SEQ": "", - "variables": [ - "$code_for_pref_term", - "$code_for_value", - "$pref_term_for_code", - "$value_for_code", - "studyPhase.standardCode.code", - "studyPhase.standardCode.decode", - ], - "values": ["null", "null", "Not Applicable", "NOT APPLICABLE", "C48660", "N/A"], - }, - { - "core_id": "CORE-000409", - "message": _message, - "executability": "fully executable", - "dataset": "StudyVersion", - "USUBJID": "", - "row": 3, - "SEQ": "", - "variables": [ - "$code_for_pref_term", - "$code_for_value", - "$pref_term_for_code", - "$value_for_code", - "studyPhase.standardCode.code", - "studyPhase.standardCode.decode", - ], - "values": [ - "C198366", - "C198366", - "null", - "null", - "C198366xx", - "Phase I/II/III Trial", - ], - }, - { - "core_id": "CORE-000409", - "message": _message, - "executability": "fully executable", - "dataset": "StudyVersion", - "USUBJID": "", - "row": 4, - "SEQ": "", - "variables": [ - "$code_for_pref_term", - "$code_for_value", - "$pref_term_for_code", - "$value_for_code", - "studyPhase.standardCode.code", - "studyPhase.standardCode.decode", - ], - "values": ["C15600", "C15600", "null", "null", "C00001x", "Phase I Trial"], - }, - { - "core_id": "CORE-000409", - "message": _message, - "executability": "fully executable", - "dataset": "StudyVersion", - "USUBJID": "", - "row": 5, - "SEQ": "", - "variables": [ - "$code_for_pref_term", - "$code_for_value", - "$pref_term_for_code", - "$value_for_code", - "studyPhase.standardCode.code", - "studyPhase.standardCode.decode", - ], - "values": [ - "C198366", - "C198366", - "Phase II Trial", - "PHASE II TRIAL", - "C15601", - "Phase I/II/III Trial", - ], - }, - { - "core_id": "CORE-000409", - "message": _message, - "executability": "fully executable", - "dataset": "StudyVersion", - "USUBJID": "", - "row": 6, - "SEQ": "", - "variables": [ - "$code_for_pref_term", - "$code_for_value", - "$pref_term_for_code", - "$value_for_code", - "studyPhase.standardCode.code", - "studyPhase.standardCode.decode", - ], - "values": ["C199989", "C199989", "null", "null", "C198366xx", "PHASE IB TRIAL"], - }, - { - "core_id": "CORE-000409", - "message": _message, - "executability": "fully executable", - "dataset": "StudyVersion", - "USUBJID": "", - "row": 7, - "SEQ": "", - "variables": [ - "$code_for_pref_term", - "$code_for_value", - "$pref_term_for_code", - "$value_for_code", - "studyPhase.standardCode.code", - "studyPhase.standardCode.decode", - ], - "values": [ - "null", - "null", - "Phase Ib Trial", - "PHASE IB TRIAL", - "C199989", - "PHASE 2 TRIAL", - ], - }, -] - - -@pytest.mark.regression -class TestCoreIssue1348: - @pytest.mark.parametrize( - "rule_name, dataset, issue_summary, details", - [ - ("DDF00015_not.yaml", "data_pos", [], []), - ("DDF00015_not.yaml", "data_neg", _summary, _issue_details), - ("DDF00015_all.yaml", "data_pos", [], []), - ("DDF00015_all.yaml", "data_neg", _summary, _issue_details), - ], - ) - def test_not_as_first_condition_same_errors_as_all_condition( - self, rule_name, dataset, issue_summary, details - ): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3-4", - "-lr", - os.path.join("tests", "resources", "CoreIssue1348", rule_name), - "-of", - "json", - "--data", - os.path.join("tests", "resources", "CoreIssue1348", dataset), - ] - subprocess.run(command, check=True) - - # Get the latest created Excel file - files = os.listdir() - json_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".json") - ] - json_report_path = sorted(json_files)[-1] - # Open the JSON report file - json_report = json.load(open(json_report_path)) - assert { - "Conformance_Details", - "Dataset_Details", - "Issue_Summary", - "Issue_Details", - "Rules_Report", - }.issubset(json_report.keys()) - - assert details == json_report["Issue_Details"] - assert issue_summary == json_report["Issue_Summary"] - if os.path.exists(json_report_path): - os.remove(json_report_path) +import os +import subprocess + +import pytest +import json +from conftest import get_python_executable + +_message = ( + "The study version's study phase is not specified according to the extensible Trial Phase Response" + ' (C66737) SDTM codelist - codeSystem is not "http://www.cdisc.org", codeSystemVersion is not a valid' + " terminology package date, and/or the code or decode is found in the codelist (case insensitive)" + " but the corresponding decode or code does not match the codelist value (case sensitive)." +) +_summary = [ + { + "dataset": "StudyVersion", + "core_id": "CORE-000409", + "message": _message, + "issues": 7, + } +] +_issue_details = [ + { + "core_id": "CORE-000409", + "message": _message, + "executability": "fully executable", + "dataset": "StudyVersion", + "USUBJID": "", + "row": 1, + "SEQ": "", + "variables": [ + "$code_for_pref_term", + "$code_for_value", + "$pref_term_for_code", + "$value_for_code", + "studyPhase.standardCode.code", + "studyPhase.standardCode.decode", + ], + "values": [ + "C199989", + "C199989", + "Phase II Trial", + "PHASE II TRIAL", + "C15601", + "Phase Ib Trial", + ], + }, + { + "core_id": "CORE-000409", + "message": _message, + "executability": "fully executable", + "dataset": "StudyVersion", + "USUBJID": "", + "row": 2, + "SEQ": "", + "variables": [ + "$code_for_pref_term", + "$code_for_value", + "$pref_term_for_code", + "$value_for_code", + "studyPhase.standardCode.code", + "studyPhase.standardCode.decode", + ], + "values": ["null", "null", "Not Applicable", "NOT APPLICABLE", "C48660", "N/A"], + }, + { + "core_id": "CORE-000409", + "message": _message, + "executability": "fully executable", + "dataset": "StudyVersion", + "USUBJID": "", + "row": 3, + "SEQ": "", + "variables": [ + "$code_for_pref_term", + "$code_for_value", + "$pref_term_for_code", + "$value_for_code", + "studyPhase.standardCode.code", + "studyPhase.standardCode.decode", + ], + "values": [ + "C198366", + "C198366", + "null", + "null", + "C198366xx", + "Phase I/II/III Trial", + ], + }, + { + "core_id": "CORE-000409", + "message": _message, + "executability": "fully executable", + "dataset": "StudyVersion", + "USUBJID": "", + "row": 4, + "SEQ": "", + "variables": [ + "$code_for_pref_term", + "$code_for_value", + "$pref_term_for_code", + "$value_for_code", + "studyPhase.standardCode.code", + "studyPhase.standardCode.decode", + ], + "values": ["C15600", "C15600", "null", "null", "C00001x", "Phase I Trial"], + }, + { + "core_id": "CORE-000409", + "message": _message, + "executability": "fully executable", + "dataset": "StudyVersion", + "USUBJID": "", + "row": 5, + "SEQ": "", + "variables": [ + "$code_for_pref_term", + "$code_for_value", + "$pref_term_for_code", + "$value_for_code", + "studyPhase.standardCode.code", + "studyPhase.standardCode.decode", + ], + "values": [ + "C198366", + "C198366", + "Phase II Trial", + "PHASE II TRIAL", + "C15601", + "Phase I/II/III Trial", + ], + }, + { + "core_id": "CORE-000409", + "message": _message, + "executability": "fully executable", + "dataset": "StudyVersion", + "USUBJID": "", + "row": 6, + "SEQ": "", + "variables": [ + "$code_for_pref_term", + "$code_for_value", + "$pref_term_for_code", + "$value_for_code", + "studyPhase.standardCode.code", + "studyPhase.standardCode.decode", + ], + "values": ["C199989", "C199989", "null", "null", "C198366xx", "PHASE IB TRIAL"], + }, + { + "core_id": "CORE-000409", + "message": _message, + "executability": "fully executable", + "dataset": "StudyVersion", + "USUBJID": "", + "row": 7, + "SEQ": "", + "variables": [ + "$code_for_pref_term", + "$code_for_value", + "$pref_term_for_code", + "$value_for_code", + "studyPhase.standardCode.code", + "studyPhase.standardCode.decode", + ], + "values": [ + "null", + "null", + "Phase Ib Trial", + "PHASE IB TRIAL", + "C199989", + "PHASE 2 TRIAL", + ], + }, +] + + +@pytest.mark.regression +class TestCoreIssue1348: + @pytest.mark.parametrize( + "rule_name, dataset, issue_summary, details", + [ + ("DDF00015_not.yaml", "data_pos", [], []), + ("DDF00015_not.yaml", "data_neg", _summary, _issue_details), + ("DDF00015_all.yaml", "data_pos", [], []), + ("DDF00015_all.yaml", "data_neg", _summary, _issue_details), + ], + ) + def test_not_as_first_condition_same_errors_as_all_condition( + self, rule_name, dataset, issue_summary, details + ): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3-4", + "-lr", + os.path.join("tests", "resources", "CoreIssue1348", rule_name), + "-of", + "json", + "--data", + os.path.join("tests", "resources", "CoreIssue1348", dataset), + ] + subprocess.run(command, check=True) + + # Get the latest created Excel file + files = os.listdir() + json_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".json") + ] + json_report_path = sorted(json_files)[-1] + # Open the JSON report file + json_report = json.load(open(json_report_path)) + assert { + "Conformance_Details", + "Dataset_Details", + "Issue_Summary", + "Issue_Details", + "Rules_Report", + }.issubset(json_report.keys()) + + assert details == json_report["Issue_Details"] + assert issue_summary == json_report["Issue_Summary"] + if os.path.exists(json_report_path): + os.remove(json_report_path) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1387.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1387.py index 3c94be9e9..24dd97a76 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1387.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1387.py @@ -1,240 +1,240 @@ -import subprocess -import os -import tempfile -import shutil -import pytest -from conftest import get_python_executable - - -@pytest.mark.regression -def test_multiple_xlsx_files_shows_helpful_error(): - """Test that multiple XLSX files show a helpful error message about single file limitation""" - with tempfile.TemporaryDirectory() as temp_dir: - xlsx_files = ["ae.xlsx", "dm.xlsx"] - - for filename in xlsx_files: - open(os.path.join(temp_dir, filename), "w").close() - - command = [ - get_python_executable(), - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3.4", - "-d", - temp_dir, - ] - - process = subprocess.Popen( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - stdout, stderr = process.communicate() - - stderr_text = stderr.decode() - stdout_text = stdout.decode() - - assert ( - process.returncode != 0 - ), "Expected non-zero exit code for multiple XLSX files" - assert "KeyError" not in stderr_text, "Should not show KeyError crash" - assert ( - "Failed to execute script" not in stderr_text - ), "Should not show script execution failure" - assert ( - "Multiple XLSX files found" in stderr_text - or "Multiple XLSX files found" in stdout_text - ), f"Expected helpful error message about multiple XLSX files. stderr: {stderr_text}, stdout: {stdout_text}" - assert ( - "Excel format (XLSX) validation only supports single files" in stderr_text - or "Excel format (XLSX) validation only supports single files" - in stdout_text - ), "Expected explanation of XLSX limitation" - - -@pytest.mark.regression -def test_folder_with_xlsx_files_works_with_excel_service(): - """Test that a folder with a single XLSX file now works with ExcelDataService""" - with tempfile.TemporaryDirectory() as temp_dir: - xlsx_files = ["ae.xlsx"] - - for filename in xlsx_files: - open(os.path.join(temp_dir, filename), "w").close() - - command = [ - get_python_executable(), - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3.4", - "-d", - temp_dir, - ] - - process = subprocess.Popen( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - stdout, stderr = process.communicate() - - stderr_text = stderr.decode() - stdout_text = stdout.decode() - - assert "KeyError: 'XLSX'" not in stderr_text, "Should not show KeyError crash" - assert ( - "Failed to execute script" not in stderr_text - ), "Should not show script execution failure" - - assert ( - "No valid dataset files found" not in stderr_text - and "No valid dataset files found" not in stdout_text - ), "XLSX files should now be recognized as valid" - - -@pytest.mark.regression -def test_folder_with_unsupported_formats_shows_helpful_error(): - """Test that folders with truly unsupported formats (like PDF) show helpful error messages""" - with tempfile.TemporaryDirectory() as temp_dir: - unsupported_files = ["ae.pdf", "dm.txt"] - - for filename in unsupported_files: - open(os.path.join(temp_dir, filename), "w").close() - - command = [ - get_python_executable(), - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3.4", - "-d", - temp_dir, - ] - - process = subprocess.Popen( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - stdout, stderr = process.communicate() - - stderr_text = stderr.decode() - stdout_text = stdout.decode() - - assert ( - process.returncode != 0 - ), "Expected non-zero exit code for unsupported files" - assert "KeyError" not in stderr_text, "Should not show KeyError crash" - assert ( - "Failed to execute script" not in stderr_text - ), "Should not show script execution failure" - assert ( - "No valid dataset files found" in stderr_text - or "No valid dataset files found" in stdout_text - ), f"Expected helpful error message. stderr: {stderr_text}, stdout: {stdout_text}" - assert ( - "SAS V5 XPT, Dataset-JSON" in stderr_text - or "SAS V5 XPT, Dataset-JSON" in stdout_text - ), "Expected format guidance in error message" - - -@pytest.mark.regression -def test_empty_folder_shows_helpful_error(): - with tempfile.TemporaryDirectory() as temp_dir: - command = [ - get_python_executable(), - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3.4", - "-d", - temp_dir, - ] - - process = subprocess.Popen( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - stdout, stderr = process.communicate() - - stderr_text = stderr.decode() - stdout_text = stdout.decode() - - assert process.returncode != 0, "Expected non-zero exit code for empty folder" - assert ( - "No valid dataset files found" in stderr_text - or "No valid dataset files found" in stdout_text - ), "Expected helpful error message for empty folder" - - -@pytest.mark.regression -def test_valid_xpt_files_work_normally(): - command = [ - get_python_executable(), - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3.4", - "-dp", - os.path.join("tests", "resources", "test_dataset.xpt"), - ] - - process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = process.communicate() - - stderr_text = stderr.decode() - - assert "KeyError: 'XLSX'" not in stderr_text, "Should not show KeyError" - assert "Failed to execute script" not in stderr_text, "Should not crash" - assert ( - "No valid dataset files found" not in stderr_text - ), "Should find valid XPT file" - - -@pytest.mark.regression -def test_mixed_folder_processes_valid_files(): - with tempfile.TemporaryDirectory() as temp_dir: - valid_xpt = os.path.join("tests", "resources", "test_dataset.xpt") - if os.path.exists(valid_xpt): - shutil.copy(valid_xpt, os.path.join(temp_dir, "ae.xpt")) - - xlsx_file = os.path.join(temp_dir, "dm.xlsx") - open(xlsx_file, "w").close() - - command = [ - get_python_executable(), - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3.4", - "-d", - temp_dir, - ] - - process = subprocess.Popen( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - stdout, stderr = process.communicate() - - stderr_text = stderr.decode() - stdout_text = stdout.decode() - - assert "KeyError" not in stderr_text, "Should not crash on any files" - assert "Failed to execute script" not in stderr_text, "Should not crash" - - assert ( - "No valid dataset files found" not in stderr_text - and "No valid dataset files found" not in stdout_text - ), "Should find the valid XPT file" +import subprocess +import os +import tempfile +import shutil +import pytest +from conftest import get_python_executable + + +@pytest.mark.regression +def test_multiple_xlsx_files_shows_helpful_error(): + """Test that multiple XLSX files show a helpful error message about single file limitation""" + with tempfile.TemporaryDirectory() as temp_dir: + xlsx_files = ["ae.xlsx", "dm.xlsx"] + + for filename in xlsx_files: + open(os.path.join(temp_dir, filename), "w").close() + + command = [ + get_python_executable(), + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3.4", + "-d", + temp_dir, + ] + + process = subprocess.Popen( + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + stdout, stderr = process.communicate() + + stderr_text = stderr.decode() + stdout_text = stdout.decode() + + assert ( + process.returncode != 0 + ), "Expected non-zero exit code for multiple XLSX files" + assert "KeyError" not in stderr_text, "Should not show KeyError crash" + assert ( + "Failed to execute script" not in stderr_text + ), "Should not show script execution failure" + assert ( + "Multiple XLSX files found" in stderr_text + or "Multiple XLSX files found" in stdout_text + ), f"Expected helpful error message about multiple XLSX files. stderr: {stderr_text}, stdout: {stdout_text}" + assert ( + "Excel format (XLSX) validation only supports single files" in stderr_text + or "Excel format (XLSX) validation only supports single files" + in stdout_text + ), "Expected explanation of XLSX limitation" + + +@pytest.mark.regression +def test_folder_with_xlsx_files_works_with_excel_service(): + """Test that a folder with a single XLSX file now works with ExcelDataService""" + with tempfile.TemporaryDirectory() as temp_dir: + xlsx_files = ["ae.xlsx"] + + for filename in xlsx_files: + open(os.path.join(temp_dir, filename), "w").close() + + command = [ + get_python_executable(), + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3.4", + "-d", + temp_dir, + ] + + process = subprocess.Popen( + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + stdout, stderr = process.communicate() + + stderr_text = stderr.decode() + stdout_text = stdout.decode() + + assert "KeyError: 'XLSX'" not in stderr_text, "Should not show KeyError crash" + assert ( + "Failed to execute script" not in stderr_text + ), "Should not show script execution failure" + + assert ( + "No valid dataset files found" not in stderr_text + and "No valid dataset files found" not in stdout_text + ), "XLSX files should now be recognized as valid" + + +@pytest.mark.regression +def test_folder_with_unsupported_formats_shows_helpful_error(): + """Test that folders with truly unsupported formats (like PDF) show helpful error messages""" + with tempfile.TemporaryDirectory() as temp_dir: + unsupported_files = ["ae.pdf", "dm.txt"] + + for filename in unsupported_files: + open(os.path.join(temp_dir, filename), "w").close() + + command = [ + get_python_executable(), + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3.4", + "-d", + temp_dir, + ] + + process = subprocess.Popen( + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + stdout, stderr = process.communicate() + + stderr_text = stderr.decode() + stdout_text = stdout.decode() + + assert ( + process.returncode != 0 + ), "Expected non-zero exit code for unsupported files" + assert "KeyError" not in stderr_text, "Should not show KeyError crash" + assert ( + "Failed to execute script" not in stderr_text + ), "Should not show script execution failure" + assert ( + "No valid dataset files found" in stderr_text + or "No valid dataset files found" in stdout_text + ), f"Expected helpful error message. stderr: {stderr_text}, stdout: {stdout_text}" + assert ( + "SAS V5 XPT, Dataset-JSON" in stderr_text + or "SAS V5 XPT, Dataset-JSON" in stdout_text + ), "Expected format guidance in error message" + + +@pytest.mark.regression +def test_empty_folder_shows_helpful_error(): + with tempfile.TemporaryDirectory() as temp_dir: + command = [ + get_python_executable(), + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3.4", + "-d", + temp_dir, + ] + + process = subprocess.Popen( + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + stdout, stderr = process.communicate() + + stderr_text = stderr.decode() + stdout_text = stdout.decode() + + assert process.returncode != 0, "Expected non-zero exit code for empty folder" + assert ( + "No valid dataset files found" in stderr_text + or "No valid dataset files found" in stdout_text + ), "Expected helpful error message for empty folder" + + +@pytest.mark.regression +def test_valid_xpt_files_work_normally(): + command = [ + get_python_executable(), + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3.4", + "-dp", + os.path.join("tests", "resources", "test_dataset.xpt"), + ] + + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + + stderr_text = stderr.decode() + + assert "KeyError: 'XLSX'" not in stderr_text, "Should not show KeyError" + assert "Failed to execute script" not in stderr_text, "Should not crash" + assert ( + "No valid dataset files found" not in stderr_text + ), "Should find valid XPT file" + + +@pytest.mark.regression +def test_mixed_folder_processes_valid_files(): + with tempfile.TemporaryDirectory() as temp_dir: + valid_xpt = os.path.join("tests", "resources", "test_dataset.xpt") + if os.path.exists(valid_xpt): + shutil.copy(valid_xpt, os.path.join(temp_dir, "ae.xpt")) + + xlsx_file = os.path.join(temp_dir, "dm.xlsx") + open(xlsx_file, "w").close() + + command = [ + get_python_executable(), + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3.4", + "-d", + temp_dir, + ] + + process = subprocess.Popen( + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + stdout, stderr = process.communicate() + + stderr_text = stderr.decode() + stdout_text = stdout.decode() + + assert "KeyError" not in stderr_text, "Should not crash on any files" + assert "Failed to execute script" not in stderr_text, "Should not crash" + + assert ( + "No valid dataset files found" not in stderr_text + and "No valid dataset files found" not in stdout_text + ), "Should find the valid XPT file" diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1421.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1421.py index 009e7eca0..02ed2aae6 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1421.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1421.py @@ -1,132 +1,132 @@ -import os -import subprocess -import openpyxl -import pytest -from conftest import get_python_executable -from QARegressionTests.globals import ( - dataset_details_sheet, - issue_datails_sheet, - rules_report_sheet, - issue_sheet_variable_column, - issue_sheet_coreid_column, -) - - -@pytest.mark.regression -def test_validate_define_xml_against_lib_metadata(): - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3-4", - "-dp", - os.path.join( - "tests", - "resources", - "CoreIssue1421", - "Dataset.json", - ), - "-lr", - os.path.join("tests", "resources", "CoreIssue1421", "Rule.yml"), - "-dxp", - os.path.join("tests", "resources", "CoreIssue1421", "Define.xml"), - ] - subprocess.run(command, check=True) - - # Get the latest created Excel file - files = os.listdir() - excel_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".xlsx") - ] - excel_file_path = sorted(excel_files)[-1] - # Open the Excel file - workbook = openpyxl.load_workbook(excel_file_path) - - # Go to the "Issue Details" sheet - sheet = workbook[issue_datails_sheet] - - # Check Variable(s) column (H) - variables_names_column = sheet["H"] - variables_names_values = [ - cell.value for cell in variables_names_column[1:] if cell.value is not None - ] - assert len(variables_names_values) == 3 - for value in variables_names_values: - assert len(value.split(",")) == 6 - - # Check Value(s) column (I) - variables_values_column = sheet[issue_sheet_variable_column] - variables_values = [ - cell.value for cell in variables_values_column[1:] if cell.value is not None - ] - assert len(variables_values) == 3 - for value in variables_values: - assert len(value.split(",")) == 6 - - dataset_column = sheet["D"] - dataset_column_values = [ - cell.value for cell in dataset_column[1:] if cell.value is not None - ] - assert sorted(set(dataset_column_values)) == ["DM", "SUPPEC"] - - core_id_column = sheet[issue_sheet_coreid_column] - core_id_column_values = [ - cell.value for cell in core_id_column[1:] if cell.value is not None - ] - assert set(core_id_column_values) == {"CDISC.SDTMIG.CG0999"} - - # Go to the "Rules Report" sheet - rules_values = [ - row for row in workbook[rules_report_sheet].iter_rows(values_only=True) - ][1:] - rules_values = [row for row in rules_values if any(row)] - assert rules_values[0][0] == "CDISC.SDTMIG.CG0999" - assert "ISSUE REPORTED" in rules_values[0] - assert ( - rules_values[0][4] - == "Issue with codelist definition in the Define-XML document." - ) - - # Go to the "Dataset Details" sheet - dataset_sheet = workbook[dataset_details_sheet] - dataset_values = [row for row in dataset_sheet.iter_rows(values_only=True)][1:] - dataset_values = [row for row in dataset_values if any(row)] - assert len(dataset_values) > 0 - dataset_names = set(row[0] for row in dataset_values if row[0] is not None) - assert dataset_names == {"AE", "DM", "EC", "EX", "SUPPEC"} - expected_records = { - "AE": 74, - "DM": 18, - "EC": 1590, - "EX": 1583, - "SUPPEC": 13, - } - for row in dataset_values: - dataset_name = row[0] - records_count = row[-1] - assert records_count == expected_records[dataset_name] - - # Go to the "Issue Summary" sheet - issue_summary_sheet = workbook["Issue Summary"] - summary_values = [row for row in issue_summary_sheet.iter_rows(values_only=True)][ - 1: - ] - summary_values = [row for row in summary_values if any(row)] - assert len(summary_values) == 2 - core_ids = set(row[1] for row in summary_values if row[1] is not None) - assert core_ids == {"CDISC.SDTMIG.CG0999"} - # Check Message and dataset columns - for row in summary_values: - assert row[2] == "Issue with codelist definition in the Define-XML document." - datasets_in_summary = set(row[0] for row in summary_values if row[0] is not None) - assert datasets_in_summary == {"DM", "SUPPEC"} - - # Delete the excel file - if os.path.exists(excel_file_path): - os.remove(excel_file_path) +import os +import subprocess +import openpyxl +import pytest +from conftest import get_python_executable +from QARegressionTests.globals import ( + dataset_details_sheet, + issue_datails_sheet, + rules_report_sheet, + issue_sheet_variable_column, + issue_sheet_coreid_column, +) + + +@pytest.mark.regression +def test_validate_define_xml_against_lib_metadata(): + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3-4", + "-dp", + os.path.join( + "tests", + "resources", + "CoreIssue1421", + "Dataset.json", + ), + "-lr", + os.path.join("tests", "resources", "CoreIssue1421", "Rule.yml"), + "-dxp", + os.path.join("tests", "resources", "CoreIssue1421", "Define.xml"), + ] + subprocess.run(command, check=True) + + # Get the latest created Excel file + files = os.listdir() + excel_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".xlsx") + ] + excel_file_path = sorted(excel_files)[-1] + # Open the Excel file + workbook = openpyxl.load_workbook(excel_file_path) + + # Go to the "Issue Details" sheet + sheet = workbook[issue_datails_sheet] + + # Check Variable(s) column (H) + variables_names_column = sheet["H"] + variables_names_values = [ + cell.value for cell in variables_names_column[1:] if cell.value is not None + ] + assert len(variables_names_values) == 3 + for value in variables_names_values: + assert len(value.split(",")) == 6 + + # Check Value(s) column (I) + variables_values_column = sheet[issue_sheet_variable_column] + variables_values = [ + cell.value for cell in variables_values_column[1:] if cell.value is not None + ] + assert len(variables_values) == 3 + for value in variables_values: + assert len(value.split(",")) == 6 + + dataset_column = sheet["D"] + dataset_column_values = [ + cell.value for cell in dataset_column[1:] if cell.value is not None + ] + assert sorted(set(dataset_column_values)) == ["DM", "SUPPEC"] + + core_id_column = sheet[issue_sheet_coreid_column] + core_id_column_values = [ + cell.value for cell in core_id_column[1:] if cell.value is not None + ] + assert set(core_id_column_values) == {"CDISC.SDTMIG.CG0999"} + + # Go to the "Rules Report" sheet + rules_values = [ + row for row in workbook[rules_report_sheet].iter_rows(values_only=True) + ][1:] + rules_values = [row for row in rules_values if any(row)] + assert rules_values[0][0] == "CDISC.SDTMIG.CG0999" + assert "ISSUE REPORTED" in rules_values[0] + assert ( + rules_values[0][4] + == "Issue with codelist definition in the Define-XML document." + ) + + # Go to the "Dataset Details" sheet + dataset_sheet = workbook[dataset_details_sheet] + dataset_values = [row for row in dataset_sheet.iter_rows(values_only=True)][1:] + dataset_values = [row for row in dataset_values if any(row)] + assert len(dataset_values) > 0 + dataset_names = set(row[0] for row in dataset_values if row[0] is not None) + assert dataset_names == {"AE", "DM", "EC", "EX", "SUPPEC"} + expected_records = { + "AE": 74, + "DM": 18, + "EC": 1590, + "EX": 1583, + "SUPPEC": 13, + } + for row in dataset_values: + dataset_name = row[0] + records_count = row[-1] + assert records_count == expected_records[dataset_name] + + # Go to the "Issue Summary" sheet + issue_summary_sheet = workbook["Issue Summary"] + summary_values = [row for row in issue_summary_sheet.iter_rows(values_only=True)][ + 1: + ] + summary_values = [row for row in summary_values if any(row)] + assert len(summary_values) == 2 + core_ids = set(row[1] for row in summary_values if row[1] is not None) + assert core_ids == {"CDISC.SDTMIG.CG0999"} + # Check Message and dataset columns + for row in summary_values: + assert row[2] == "Issue with codelist definition in the Define-XML document." + datasets_in_summary = set(row[0] for row in summary_values if row[0] is not None) + assert datasets_in_summary == {"DM", "SUPPEC"} + + # Delete the excel file + if os.path.exists(excel_file_path): + os.remove(excel_file_path) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1442.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1442.py index 172516786..a1ae1a304 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1442.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1442.py @@ -1,91 +1,91 @@ -import os -import subprocess -import openpyxl -import pytest -from conftest import get_python_executable - - -@pytest.mark.regression -class TestCoreIssue1442: - @pytest.mark.parametrize( - "command", - [ - ( - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "usdm", - "-v", - "4-0", - "-dp", - os.path.join( - "tests", "resources", "CoreIssue1442", "test_adam_dataset.xpt" - ), - "-dp", - os.path.join( - "tests", "resources", "CoreIssue1442", "test_dataset.ndjson" - ), - "-dp", - os.path.join( - "tests", "resources", "CoreIssue1442", "CDISC_Pilot_Study.json" - ), - "-ft", - "json", - "-lr", - os.path.join("tests", "resources", "CoreIssue1442", "rule.yml"), - ), - ( - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "usdm", - "-v", - "4-0", - "-d", - os.path.join("tests", "resources", "CoreIssue1442"), - "-ft", - "json", - "-lr", - os.path.join("tests", "resources", "CoreIssue1442", "rule.yml"), - ), - ], - ) - def test_positive_dataset(self, command): - # Run the command in the terminal - subprocess.run(command, check=True) - - # Get the latest created Excel file - files = os.listdir() - excel_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".xlsx") - ] - excel_file_path = sorted(excel_files)[-1] - # # Open the Excel file - workbook = openpyxl.load_workbook(excel_file_path) - if "Conformance Details" in workbook.sheetnames: - conformance_sheet = workbook["Conformance Details"] - found = False - for row in conformance_sheet.iter_rows(min_row=2, values_only=True): - for idx, cell in enumerate(row[:-1]): - if ( - cell == "JSON file name" - and row[idx + 1] == "CDISC_Pilot_Study.json" - ): - found = True - break - if found: - break - assert ( - found - ), "Pair ('JSON file name', 'CDISC_Pilot_Study.json') not found in any row of 'Conformance Details' sheet." - else: - assert False, "'Conformance Details' sheet not found in report." - - if os.path.exists(excel_file_path): - os.remove(excel_file_path) +import os +import subprocess +import openpyxl +import pytest +from conftest import get_python_executable + + +@pytest.mark.regression +class TestCoreIssue1442: + @pytest.mark.parametrize( + "command", + [ + ( + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "usdm", + "-v", + "4-0", + "-dp", + os.path.join( + "tests", "resources", "CoreIssue1442", "test_adam_dataset.xpt" + ), + "-dp", + os.path.join( + "tests", "resources", "CoreIssue1442", "test_dataset.ndjson" + ), + "-dp", + os.path.join( + "tests", "resources", "CoreIssue1442", "CDISC_Pilot_Study.json" + ), + "-ft", + "json", + "-lr", + os.path.join("tests", "resources", "CoreIssue1442", "rule.yml"), + ), + ( + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "usdm", + "-v", + "4-0", + "-d", + os.path.join("tests", "resources", "CoreIssue1442"), + "-ft", + "json", + "-lr", + os.path.join("tests", "resources", "CoreIssue1442", "rule.yml"), + ), + ], + ) + def test_positive_dataset(self, command): + # Run the command in the terminal + subprocess.run(command, check=True) + + # Get the latest created Excel file + files = os.listdir() + excel_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".xlsx") + ] + excel_file_path = sorted(excel_files)[-1] + # # Open the Excel file + workbook = openpyxl.load_workbook(excel_file_path) + if "Conformance Details" in workbook.sheetnames: + conformance_sheet = workbook["Conformance Details"] + found = False + for row in conformance_sheet.iter_rows(min_row=2, values_only=True): + for idx, cell in enumerate(row[:-1]): + if ( + cell == "JSON file name" + and row[idx + 1] == "CDISC_Pilot_Study.json" + ): + found = True + break + if found: + break + assert ( + found + ), "Pair ('JSON file name', 'CDISC_Pilot_Study.json') not found in any row of 'Conformance Details' sheet." + else: + assert False, "'Conformance Details' sheet not found in report." + + if os.path.exists(excel_file_path): + os.remove(excel_file_path) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1487.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1487.py index 932a67f5b..476a60e81 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1487.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1487.py @@ -1,54 +1,54 @@ -import os -import subprocess -import unittest -import openpyxl -import pytest -from conftest import get_python_executable - - -@pytest.mark.skip(reason="No library metadata found") -class TestCoreIssue1487(unittest.TestCase): - def test_positive_dataset(self): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "5-0", - "-d", - os.path.join("tests", "resources", "CoreIssue1487"), - "-r", - "CORE-000354", - ] - subprocess.run(command, check=True) - - # Get the latest created Excel file - files = os.listdir() - excel_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".xlsx") - ] - excel_file_path = sorted(excel_files)[-1] - # # Open the Excel file - workbook = openpyxl.load_workbook(excel_file_path) - - assert "Rules Report" in workbook.sheetnames - rules_sheet = workbook["Rules Report"] - target_row = None - for row in rules_sheet.iter_rows(min_row=2, values_only=True): - if row[0] == "CORE-000354": - target_row = row - break - assert target_row, "Rule CORE-000354 not present in 'Rules Report' sheet." - assert ( - target_row[4] and "was requested but is not available" in target_row[4] - ), "Expected error message for CORE-000354 not found." - assert target_row[5] == "SKIPPED", "CORE-000354 status should be SKIPPED." - - if os.path.exists(excel_file_path): - os.remove(excel_file_path) +import os +import subprocess +import unittest +import openpyxl +from conftest import get_python_executable + + +class TestCoreIssue1487(unittest.TestCase): + def test_positive_dataset(self): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3-4", + "-d", + os.path.join("tests", "resources", "CoreIssue1487"), + "-r", + "CORE-000354", + ] + subprocess.run(command, check=True) + + # Get the latest created Excel file + files = os.listdir() + excel_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".xlsx") + ] + excel_file_path = sorted(excel_files)[-1] + # # Open the Excel file + workbook = openpyxl.load_workbook(excel_file_path) + + assert "Rules Report" in workbook.sheetnames + rules_sheet = workbook["Rules Report"] + target_row = None + for row in rules_sheet.iter_rows(min_row=2, values_only=True): + if row[0] == "CORE-000354": + target_row = row + break + assert target_row, "Rule CORE-000354 not present in 'Rules Report' sheet." + assert ( + target_row[4] in target_row[4] + ), "Expected error message for CORE-000354 not found." + assert ( + target_row[5] == "ISSUE REPORTED" + ), "CORE-000354 status should be ISSUE REPORTED." + + if os.path.exists(excel_file_path): + os.remove(excel_file_path) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1501.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1501.py index d79dbc2a0..38c40214f 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1501.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1501.py @@ -1,62 +1,62 @@ -import os -import subprocess -import unittest -import pytest -import json -from conftest import get_python_executable - - -@pytest.mark.regression -class TestCoreIssue1501(unittest.TestCase): - def test_raw_report(self): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sendig", - "-v", - "3-1", - "-dp", - os.path.join( - "tests", - "resources", - "CoreIssue1501", - "unit-test-coreid-SENDIG282-negative.json", - ), - "-lr", - os.path.join("tests", "resources", "CoreIssue1501", "Rule.yml"), - "-ps", - "1", - "-of", - "json", - "-rr", - ] - subprocess.run(command, check=True) - - # Get the latest created Excel file - files = os.listdir() - json_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".json") - ] - json_report_path = sorted(json_files)[-1] - # Open the JSON report file - json_report = json.load(open(json_report_path)) - assert { - "Conformance_Details", - "Dataset_Details", - "Issue_Summary", - "Issue_Details", - "Rules_Report", - }.issubset(json_report.keys()) - - if "results_data" not in json_report.keys(): - assert ( - False - ), "'results_data' key not found in report. Expected while using -rr, --raw_report flag" - if os.path.exists(json_report_path): - os.remove(json_report_path) +import os +import subprocess +import unittest +import pytest +import json +from conftest import get_python_executable + + +@pytest.mark.regression +class TestCoreIssue1501(unittest.TestCase): + def test_raw_report(self): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sendig", + "-v", + "3-1", + "-dp", + os.path.join( + "tests", + "resources", + "CoreIssue1501", + "unit-test-coreid-SENDIG282-negative.json", + ), + "-lr", + os.path.join("tests", "resources", "CoreIssue1501", "Rule.yml"), + "-ps", + "1", + "-of", + "json", + "-rr", + ] + subprocess.run(command, check=True) + + # Get the latest created Excel file + files = os.listdir() + json_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".json") + ] + json_report_path = sorted(json_files)[-1] + # Open the JSON report file + json_report = json.load(open(json_report_path)) + assert { + "Conformance_Details", + "Dataset_Details", + "Issue_Summary", + "Issue_Details", + "Rules_Report", + }.issubset(json_report.keys()) + + if "results_data" not in json_report.keys(): + assert ( + False + ), "'results_data' key not found in report. Expected while using -rr, --raw_report flag" + if os.path.exists(json_report_path): + os.remove(json_report_path) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1558.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1558.py index 2c424e832..eace7e744 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1558.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1558.py @@ -1,100 +1,100 @@ -import os -import subprocess -import unittest - -import pytest -import json -from conftest import get_python_executable - - -@pytest.mark.regression -class TestCoreIssue1558(unittest.TestCase): - def test_raw_report(self): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-r", - "CORE-000007", - "-v", - "3.4", - "-d", - os.path.join( - "tests", - "resources", - "CoreIssue1558", - "datasets", - ), - "--output-format", - "json", - "-ps", - "1", - ] - subprocess.run(command, check=True) - - files = os.listdir() - json_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".json") - ] - json_report_path = sorted(json_files)[-1] - # Open the JSON report file - json_report = json.load(open(json_report_path)) - assert { - "Conformance_Details", - "Dataset_Details", - "Issue_Summary", - "Issue_Details", - "Rules_Report", - }.issubset(json_report.keys()) - datasets = {x["filename"] for x in json_report["Dataset_Details"]} - assert {"LB", "DM"}.issubset(datasets) - if os.path.exists(json_report_path): - os.remove(json_report_path) - - def test_env_vars_loaded(self): - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-r", - "CORE-000007", - "--dotenv-path", - os.path.join("tests", "resources", "CoreIssue1558", "test.env"), - "-d", - os.path.join( - "tests", - "resources", - "CoreIssue1558", - "datasets", - ), - "--output-format", - "json", - "-ps", - "1", - ] - subprocess.run(command, capture_output=True, text=True) - files = os.listdir() - json_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".json") - ] - json_report_path = sorted(json_files)[-1] - # Open the JSON report file - json_report = json.load(open(json_report_path)) - assert { - "Conformance_Details", - "Dataset_Details", - "Issue_Summary", - "Issue_Details", - "Rules_Report", - }.issubset(json_report.keys()) - assert json_report["Conformance_Details"]["Standard"] == "SDTMIG" - assert json_report["Conformance_Details"]["Version"] == "V3.4" +import os +import subprocess +import unittest + +import pytest +import json +from conftest import get_python_executable + + +@pytest.mark.regression +class TestCoreIssue1558(unittest.TestCase): + def test_raw_report(self): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-r", + "CORE-000007", + "-v", + "3.4", + "-d", + os.path.join( + "tests", + "resources", + "CoreIssue1558", + "datasets", + ), + "--output-format", + "json", + "-ps", + "1", + ] + subprocess.run(command, check=True) + + files = os.listdir() + json_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".json") + ] + json_report_path = sorted(json_files)[-1] + # Open the JSON report file + json_report = json.load(open(json_report_path)) + assert { + "Conformance_Details", + "Dataset_Details", + "Issue_Summary", + "Issue_Details", + "Rules_Report", + }.issubset(json_report.keys()) + datasets = {x["filename"] for x in json_report["Dataset_Details"]} + assert {"LB", "DM"}.issubset(datasets) + if os.path.exists(json_report_path): + os.remove(json_report_path) + + def test_env_vars_loaded(self): + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-r", + "CORE-000007", + "--dotenv-path", + os.path.join("tests", "resources", "CoreIssue1558", "test.env"), + "-d", + os.path.join( + "tests", + "resources", + "CoreIssue1558", + "datasets", + ), + "--output-format", + "json", + "-ps", + "1", + ] + subprocess.run(command, capture_output=True, text=True) + files = os.listdir() + json_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".json") + ] + json_report_path = sorted(json_files)[-1] + # Open the JSON report file + json_report = json.load(open(json_report_path)) + assert { + "Conformance_Details", + "Dataset_Details", + "Issue_Summary", + "Issue_Details", + "Rules_Report", + }.issubset(json_report.keys()) + assert json_report["Conformance_Details"]["Standard"] == "SDTMIG" + assert json_report["Conformance_Details"]["Version"] == "V3.4" diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue164.py b/tests/QARegressionTests/test_Issues/test_CoreIssue164.py index b62fc4456..9d5f0512b 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue164.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue164.py @@ -1,125 +1,122 @@ -import subprocess -import os -import openpyxl -import pytest -from conftest import get_python_executable -from QARegressionTests.globals import ( - issue_datails_sheet, - issue_sheet_record_column, - issue_sheet_variable_column, - issue_sheet_values_column, -) - - -@pytest.mark.skip(reason="The test is obsolete and requires modernization.") -def test_negative_dataset(): - command = ( - f"{get_python_executable()} -m core validate -s sdtmig -v 3.4 -r " - + os.path.join("tests", "resources", "CoreIssue164", "rule.json") - + " -dp " - + os.path.join("tests", "resources", "CoreIssue164", "Negative_Dataset.json") - ) - - # Construct the command - command = command.split(" ") - - # Run the command in the terminal - process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = process.communicate() - - file_name = stdout.decode().strip().split(": ")[1] - # Open the Excel file - workbook = openpyxl.load_workbook(file_name) - - # Go to the "Issue Details" sheet - sheet = workbook[issue_datails_sheet] - - record_column = sheet[issue_sheet_record_column] - variables_column = sheet[issue_sheet_variable_column] - values_column = sheet[issue_sheet_values_column] - - record_values = [cell.value for cell in record_column[1:]] - variables_values = [cell.value for cell in variables_column[1:]] - values_column_values = [cell.value for cell in values_column[1:]] - - # Remove None values using list comprehension - record_values = [value for value in record_values if value is not None] - variables_values = [value for value in variables_values if value is not None] - values_column_values = [ - value for value in values_column_values if value is not None - ] - - # Perform the assertion - # Ensure only two negative values are caught - assert len(record_values) == 2 - assert len(variables_values) == 2 - assert len(values_column_values) == 2 - - # Ensure negatives are detected at correct rows in dataset - assert record_values[0] == 1 - assert record_values[1] == 3 - - # Ensure correct variable is marked as negative - assert variables_values[0] == variables_values[1] == "DSDY" - - # Ensure correct values were marked negatives - assert values_column_values[0] == "0" - assert values_column_values[1] == "alolo" - - # Close the workbook - workbook.close() - - # Delete the file - os.remove(file_name) - - -@pytest.mark.skip(reason="The test is obsolete and requires modernization.") -def test_positive_dataset(): - command = ( - f"{get_python_executable()} -m core validate -s sdtmig -v 3.4 -r " - + os.path.join("tests", "resources", "CoreIssue164", "rule.json") - + " -dp " - + os.path.join("tests", "resources", "CoreIssue164", "Positive_Dataset.json") - ) - - # Construct the command - command = command.split(" ") - - # Run the command in the terminal - process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = process.communicate() - - file_name = stdout.decode().strip().split(": ")[1] - print(file_name) - # Open the Excel file - workbook = openpyxl.load_workbook(file_name) - - # Go to the "Issue Details" sheet - sheet = workbook[issue_datails_sheet] - - record_column = sheet[issue_sheet_record_column] - variables_column = sheet[issue_sheet_variable_column] - values_column = sheet[issue_sheet_values_column] - - record_values = [cell.value for cell in record_column[1:]] - variables_values = [cell.value for cell in variables_column[1:]] - values_column_values = [cell.value for cell in values_column[1:]] - - # Remove None values using list comprehension - record_values = [value for value in record_values if value is not None] - variables_values = [value for value in variables_values if value is not None] - values_column_values = [ - value for value in values_column_values if value is not None - ] - - # Perform the assertion - # Ensure only two negative values are caught - assert len(record_values) == 0 - assert len(variables_values) == 0 - assert len(values_column_values) == 0 - - # Close the workbook - workbook.close() - - # Delete the file - os.remove(file_name) +import subprocess +import os +import openpyxl +from conftest import get_python_executable +from QARegressionTests.globals import ( + issue_datails_sheet, + issue_sheet_record_column, + issue_sheet_variable_column, + issue_sheet_values_column, +) + + +def test_negative_dataset(): + command = ( + f"{get_python_executable()} -m core validate -s sdtmig -v 3.4 -lr " + + os.path.join("tests", "resources", "CoreIssue164", "rule.json") + + " -dp " + + os.path.join("tests", "resources", "CoreIssue164", "Negative_Dataset.json") + ) + + # Construct the command + command = command.split(" ") + + # Run the command in the terminal + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + + file_name = stdout.decode().strip().split(": ")[1] + # Open the Excel file + workbook = openpyxl.load_workbook(file_name) + + # Go to the "Issue Details" sheet + sheet = workbook[issue_datails_sheet] + + record_column = sheet[issue_sheet_record_column] + variables_column = sheet[issue_sheet_variable_column] + values_column = sheet[issue_sheet_values_column] + + record_values = [cell.value for cell in record_column[1:]] + variables_values = [cell.value for cell in variables_column[1:]] + values_column_values = [cell.value for cell in values_column[1:]] + + # Remove None values using list comprehension + record_values = [value for value in record_values if value is not None] + variables_values = [value for value in variables_values if value is not None] + values_column_values = [ + value for value in values_column_values if value is not None + ] + + # Perform the assertion + # Ensure only two negative values are caught + assert len(record_values) == 2 + assert len(variables_values) == 2 + assert len(values_column_values) == 2 + + # Ensure negatives are detected at correct rows in dataset + assert record_values[0] == 1 + assert record_values[1] == 3 + + # Ensure correct variable is marked as negative + assert variables_values[0] == variables_values[1] == "DSDY" + + # Ensure correct values were marked negatives + assert values_column_values[0] == "0" + assert values_column_values[1] == "alolo" + + # Close the workbook + workbook.close() + + # Delete the file + os.remove(file_name) + + +def test_positive_dataset(): + command = ( + f"{get_python_executable()} -m core validate -s sdtmig -v 3.4 -lr " + + os.path.join("tests", "resources", "CoreIssue164", "rule.json") + + " -dp " + + os.path.join("tests", "resources", "CoreIssue164", "Positive_Dataset.json") + ) + + # Construct the command + command = command.split(" ") + + # Run the command in the terminal + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + + file_name = stdout.decode().strip().split(": ")[1] + print(file_name) + # Open the Excel file + workbook = openpyxl.load_workbook(file_name) + + # Go to the "Issue Details" sheet + sheet = workbook[issue_datails_sheet] + + record_column = sheet[issue_sheet_record_column] + variables_column = sheet[issue_sheet_variable_column] + values_column = sheet[issue_sheet_values_column] + + record_values = [cell.value for cell in record_column[1:]] + variables_values = [cell.value for cell in variables_column[1:]] + values_column_values = [cell.value for cell in values_column[1:]] + + # Remove None values using list comprehension + record_values = [value for value in record_values if value is not None] + variables_values = [value for value in variables_values if value is not None] + values_column_values = [ + value for value in values_column_values if value is not None + ] + + # Perform the assertion + # Ensure only two negative values are caught + assert len(record_values) == 0 + assert len(variables_values) == 0 + assert len(values_column_values) == 0 + + # Close the workbook + workbook.close() + + # Delete the file + os.remove(file_name) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1699.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1699.py index c2064523a..fcd4fa5cc 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1699.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1699.py @@ -1,56 +1,56 @@ -import os -import subprocess -import unittest -import pytest -import json -from conftest import get_python_executable - - -@pytest.mark.regression -class TestCoreIssue1501(unittest.TestCase): - def test_raw_report(self): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sendig", - "-v", - "3-1", - "-d", - os.path.join( - "tests", - "resources", - "CoreIssue1699", - ), - "-lr", - os.path.join("tests", "resources", "CoreIssue1699", "rule.yml"), - "-ps", - "1", - "-of", - "json", - ] - subprocess.run(command, check=True) - - files = os.listdir() - json_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".json") - ] - json_report_path = sorted(json_files)[-1] - # Open the JSON report file - json_report = json.load(open(json_report_path)) - assert { - "Conformance_Details", - "Dataset_Details", - "Issue_Summary", - "Issue_Details", - "Rules_Report", - }.issubset(json_report.keys()) - assert json_report["Rules_Report"][0]["status"] == "SUCCESS" - - if os.path.exists(json_report_path): - os.remove(json_report_path) +import os +import subprocess +import unittest +import pytest +import json +from conftest import get_python_executable + + +@pytest.mark.regression +class TestCoreIssue1501(unittest.TestCase): + def test_raw_report(self): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sendig", + "-v", + "3-1", + "-d", + os.path.join( + "tests", + "resources", + "CoreIssue1699", + ), + "-lr", + os.path.join("tests", "resources", "CoreIssue1699", "rule.yml"), + "-ps", + "1", + "-of", + "json", + ] + subprocess.run(command, check=True) + + files = os.listdir() + json_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".json") + ] + json_report_path = sorted(json_files)[-1] + # Open the JSON report file + json_report = json.load(open(json_report_path)) + assert { + "Conformance_Details", + "Dataset_Details", + "Issue_Summary", + "Issue_Details", + "Rules_Report", + }.issubset(json_report.keys()) + assert json_report["Rules_Report"][0]["status"] == "SUCCESS" + + if os.path.exists(json_report_path): + os.remove(json_report_path) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue1718.py b/tests/QARegressionTests/test_Issues/test_CoreIssue1718.py index 926839bdf..7b5ec90fb 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue1718.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue1718.py @@ -1,60 +1,60 @@ -import os -import subprocess -import pytest -import json -from conftest import get_python_executable - - -@pytest.mark.regression -class TestCoreIssue1718: - def test_max_issues(self): - # Run the command in the terminal - max_issues = 3 - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-v", - "3-4", - "-d", - os.path.join( - "tests", - "resources", - "CoreIssue1718", - ), - "-r", - "CORE-000356", - "-ps", - "1", - "-of", - "json", - "-me", - f"{max_issues}", - "true", - ] - subprocess.run(command, check=True) - - files = os.listdir() - json_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".json") - ] - json_report_path = sorted(json_files)[-1] - json_report = json.load(open(json_report_path)) - assert { - "Conformance_Details", - "Dataset_Details", - "Issue_Summary", - "Issue_Details", - "Rules_Report", - }.issubset(json_report.keys()) - assert json_report["Rules_Report"][0]["status"] == "ISSUE REPORTED" - assert json_report["Issue_Summary"][0]["issues"] == 74 - assert len(json_report["Issue_Details"]) == max_issues - - if os.path.exists(json_report_path): - os.remove(json_report_path) +import os +import subprocess +import pytest +import json +from conftest import get_python_executable + + +@pytest.mark.regression +class TestCoreIssue1718: + def test_max_issues(self): + # Run the command in the terminal + max_issues = 3 + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-v", + "3-4", + "-d", + os.path.join( + "tests", + "resources", + "CoreIssue1718", + ), + "-r", + "CORE-000356", + "-ps", + "1", + "-of", + "json", + "-me", + f"{max_issues}", + "true", + ] + subprocess.run(command, check=True) + + files = os.listdir() + json_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".json") + ] + json_report_path = sorted(json_files)[-1] + json_report = json.load(open(json_report_path)) + assert { + "Conformance_Details", + "Dataset_Details", + "Issue_Summary", + "Issue_Details", + "Rules_Report", + }.issubset(json_report.keys()) + assert json_report["Rules_Report"][0]["status"] == "ISSUE REPORTED" + assert json_report["Issue_Summary"][0]["issues"] == 74 + assert len(json_report["Issue_Details"]) == max_issues + + if os.path.exists(json_report_path): + os.remove(json_report_path) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue208.py b/tests/QARegressionTests/test_Issues/test_CoreIssue208.py index acd8e243a..039a51810 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue208.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue208.py @@ -5,7 +5,6 @@ import pytest from conftest import get_python_executable - """This regression test is for automating the validation of acceptancce criteria which is "For any variables that come from datasets and appear in the results, the variables should have the same case as the variable names in the dataset". diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue363.py b/tests/QARegressionTests/test_Issues/test_CoreIssue363.py index 8cc43263f..f0baba5d9 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue363.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue363.py @@ -5,7 +5,9 @@ import pytest -@pytest.mark.skip(reason="The test is obsolete and requires modernization.") +@pytest.mark.skip( + reason="Requires API key to run. Run Locally with valid API key to test." +) class TestCoreIssue363(unittest.TestCase): def test_post_request(self): # URL to send the POST request to diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue576.py b/tests/QARegressionTests/test_Issues/test_CoreIssue576.py index 6aff31758..333351d02 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue576.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue576.py @@ -1,131 +1,128 @@ -import subprocess -import os -import openpyxl -import pytest -from conftest import get_python_executable -from QARegressionTests.globals import ( - issue_datails_sheet, - dataset_details_sheet, - rules_report_sheet, - issue_sheet_coreid_column, - dataset_sheet_dataset_column, - rules_sheet_rule_status_column, -) - -""" These tests utilize positive and negative dataset -to validate successful working CG0202. Positive -dataset have supp datasets so rule should run -successfully. while Negative datasets have no -supp datasets so rule should be skipped. The -succesfuly running against postive dataset means -the scope skip problem is resolved """ - - -@pytest.mark.skip(reason="The test is obsolete and requires modernization.") -def test_negative_dataset(): - command = ( - f"{get_python_executable()} -m core test -s sdtmig -v 3.4 -r " - + os.path.join("tests", "resources", "CoreIssue576", "Rule_underscores.json") - + " -dp " - + os.path.join("tests", "resources", "CoreIssue576", "Datasets_Negative.json") - ) - - # Construct the command - command = command.split(" ") - - # Run the command in the terminal - process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = process.communicate() - - file_name = stdout.decode().strip().split(": ")[1] - # Open the Excel file - workbook = openpyxl.load_workbook(file_name) - - # Go to the "Issue Details" sheet - issues_sheet = workbook[issue_datails_sheet] - dataset_sheet = workbook[dataset_details_sheet] - rules_sheet = workbook[rules_report_sheet] - - coreid_column = issues_sheet[issue_sheet_coreid_column] - dataset_column = dataset_sheet[dataset_sheet_dataset_column] - rule_status_column = rules_sheet[rules_sheet_rule_status_column] - - coreid_values = [cell.value for cell in coreid_column[1:]] - dataset_values = [cell.value for cell in dataset_column[1:]] - rule_status_column_values = [cell.value for cell in rule_status_column[1:]] - - # Remove None values using list comprehension - coreid_values = [value for value in coreid_values if value is not None] - dataset_values = [value for value in dataset_values if value is not None] - rule_status_column_values = [ - value for value in rule_status_column_values if value is not None - ] - - # Perform the assertion - assert dataset_values[0] == "DM" - assert len(dataset_values) == 1 - - assert len(coreid_values) == 0 - - assert rule_status_column_values[0] == "SKIPPED" - - # Close the workbook - workbook.close() - - # Delete the file - os.remove(file_name) - - -@pytest.mark.skip(reason="The test is obsolete and requires modernization.") -def test_positive_dataset(): - command = ( - f"{get_python_executable()} -m core validate -s sdtmig -v 3.4 -r " - + os.path.join("tests", "resources", "CoreIssue576", "Rule_underscores.json") - + " -dp " - + os.path.join("tests", "resources", "CoreIssue576", "Datasets_positive.json") - ) - - # Construct the command - command = command.split(" ") - - # Run the command in the terminal - process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = process.communicate() - - file_name = stdout.decode().strip().split(": ")[1] - # Open the Excel file - workbook = openpyxl.load_workbook(file_name) - - # Go to the "Issue Details" sheet - issues_sheet = workbook[issue_datails_sheet] - dataset_sheet = workbook[dataset_details_sheet] - rules_sheet = workbook[rules_report_sheet] - - coreid_column = issues_sheet[issue_sheet_coreid_column] - dataset_column = dataset_sheet[dataset_sheet_dataset_column] - rule_status_column = rules_sheet[rules_sheet_rule_status_column] - - coreid_values = [cell.value for cell in coreid_column[1:]] - dataset_values = [cell.value for cell in dataset_column[1:]] - rule_status_column_values = [cell.value for cell in rule_status_column[1:]] - - # Remove None values using list comprehension - coreid_values = [value for value in coreid_values if value is not None] - dataset_values = [value for value in dataset_values if value is not None] - rule_status_column_values = [ - value for value in rule_status_column_values if value is not None - ] - - # Perform the assertion - assert dataset_values[0] == "SUPPAE" - assert dataset_values[1] == "SUPPEC" - - assert len(coreid_values) == 0 - - assert rule_status_column_values[0] == "SUCCESS" - - # Close the workbook - workbook.close() - - # Delete the file - os.remove(file_name) +import subprocess +import os +import openpyxl +from conftest import get_python_executable +from QARegressionTests.globals import ( + issue_datails_sheet, + dataset_details_sheet, + rules_report_sheet, + issue_sheet_coreid_column, + dataset_sheet_dataset_column, + rules_sheet_rule_status_column, +) + +""" These tests utilize positive and negative dataset +to validate successful working CG0202. Positive +dataset have supp datasets so rule should run +successfully. while Negative datasets have no +supp datasets so rule should be skipped. The +succesfuly running against postive dataset means +the scope skip problem is resolved """ + + +def test_negative_dataset(): + command = ( + f"{get_python_executable()} -m core validate -s sdtmig -v 3.3 -lr " + + os.path.join("tests", "resources", "CoreIssue576", "Rule_underscores.json") + + " -dp " + + os.path.join("tests", "resources", "CoreIssue576", "Datasets_Negative.json") + ) + + # Construct the command + command = command.split(" ") + + # Run the command in the terminal + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + + file_name = stdout.decode().strip().split(": ")[1] + # Open the Excel file + workbook = openpyxl.load_workbook(file_name) + + # Go to the "Issue Details" sheet + issues_sheet = workbook[issue_datails_sheet] + dataset_sheet = workbook[dataset_details_sheet] + rules_sheet = workbook[rules_report_sheet] + + coreid_column = issues_sheet[issue_sheet_coreid_column] + dataset_column = dataset_sheet[dataset_sheet_dataset_column] + rule_status_column = rules_sheet[rules_sheet_rule_status_column] + + coreid_values = [cell.value for cell in coreid_column[1:]] + dataset_values = [cell.value for cell in dataset_column[1:]] + rule_status_column_values = [cell.value for cell in rule_status_column[1:]] + + # Remove None values using list comprehension + coreid_values = [value for value in coreid_values if value is not None] + dataset_values = [value for value in dataset_values if value is not None] + rule_status_column_values = [ + value for value in rule_status_column_values if value is not None + ] + + # Perform the assertion + assert dataset_values[0] == "DM" + assert len(dataset_values) == 1 + + assert len(coreid_values) == 0 + + assert rule_status_column_values[0] == "SKIPPED" + + # Close the workbook + workbook.close() + + # Delete the file + os.remove(file_name) + + +def test_positive_dataset(): + command = ( + f"{get_python_executable()} -m core validate -s sdtmig -v 3.3 -lr " + + os.path.join("tests", "resources", "CoreIssue576", "Rule_underscores.json") + + " -dp " + + os.path.join("tests", "resources", "CoreIssue576", "Datasets_positive.json") + ) + + # Construct the command + command = command.split(" ") + + # Run the command in the terminal + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + + file_name = stdout.decode().strip().split(": ")[1] + # Open the Excel file + workbook = openpyxl.load_workbook(file_name) + + # Go to the "Issue Details" sheet + issues_sheet = workbook[issue_datails_sheet] + dataset_sheet = workbook[dataset_details_sheet] + rules_sheet = workbook[rules_report_sheet] + + coreid_column = issues_sheet[issue_sheet_coreid_column] + dataset_column = dataset_sheet[dataset_sheet_dataset_column] + rule_status_column = rules_sheet[rules_sheet_rule_status_column] + + coreid_values = [cell.value for cell in coreid_column[1:]] + dataset_values = [cell.value for cell in dataset_column[1:]] + rule_status_column_values = [cell.value for cell in rule_status_column[1:]] + + # Remove None values using list comprehension + coreid_values = [value for value in coreid_values if value is not None] + dataset_values = [value for value in dataset_values if value is not None] + rule_status_column_values = [ + value for value in rule_status_column_values if value is not None + ] + + # Perform the assertion + assert dataset_values[0] == "SUPPAE" + assert dataset_values[1] == "SUPPEC" + + assert len(coreid_values) == 0 + + assert rule_status_column_values[0] == "SUCCESS" + + # Close the workbook + workbook.close() + + # Delete the file + os.remove(file_name) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue715.py b/tests/QARegressionTests/test_Issues/test_CoreIssue715.py index a69f3421b..e61ac5839 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue715.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue715.py @@ -1,139 +1,139 @@ -import os -import subprocess -import unittest -import openpyxl -import pytest -from conftest import get_python_executable -from QARegressionTests.globals import ( - issue_datails_sheet, - rules_report_sheet, - issue_sheet_record_column, - issue_sheet_variable_column, - issue_sheet_values_column, -) - - -@pytest.mark.regression -class TestCoreIssue715(unittest.TestCase): - def test_positive_dataset(self): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "usdm", - "-v", - "4-0", - "-dp", - os.path.join( - "tests", "resources", "CoreIssue715", "CDISC_Pilot_Study.json" - ), - "-lr", - os.path.join("tests", "resources", "CoreIssue715", "rule.yml"), - ] - subprocess.run(command, check=True) - - # Get the latest created Excel file - files = os.listdir() - excel_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".xlsx") - ] - excel_file_path = sorted(excel_files)[-1] - # # Open the Excel file - workbook = openpyxl.load_workbook(excel_file_path) - - # Go to the "Issue Details" sheet - sheet = workbook[issue_datails_sheet] - - record_column = sheet[issue_sheet_record_column] - variables_column = sheet[issue_sheet_variable_column] - values_column = sheet[issue_sheet_values_column] - - record_values = [cell.value for cell in record_column[1:]] - variables_values = [cell.value for cell in variables_column[1:]] - values_column_values = [cell.value for cell in values_column[1:]] - - # Remove None values using list comprehension - record_values = [value for value in record_values if value is not None] - variables_values = [value for value in variables_values if value is not None] - values_column_values = [ - value for value in values_column_values if value is not None - ] - rules_values = [ - row for row in workbook[rules_report_sheet].iter_rows(values_only=True) - ][1:] - rules_values = [row for row in rules_values if any(row)] - # Perform the assertion - assert rules_values[0][0] == "DDF00081" - assert "SUCCESS" in rules_values[0] - assert len(record_values) == 0 - assert len(variables_values) == 0 - assert len(values_column_values) == 0 - if os.path.exists(excel_file_path): - os.remove(excel_file_path) - - def test_negative_dataset(self): - # Run validation for invalid JSON - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "usdm", - "-v", - "4-0", - "-dp", - os.path.join( - "tests", "resources", "CoreIssue715", "CDISC_Pilot_Study_Invalid.json" - ), - "-lr", - os.path.join("tests", "resources", "CoreIssue715", "rule.yml"), - ] - subprocess.run(command, check=True) - - files = os.listdir() - excel_files = [ - f for f in files if f.startswith("CORE-Report-") and f.endswith(".xlsx") - ] - excel_file_path = sorted(excel_files)[-1] - workbook = openpyxl.load_workbook(excel_file_path) - - # Issue Summary basic checks - issue_summary_sheet = workbook["Issue Summary"] - summary_values = [r for r in issue_summary_sheet.iter_rows(values_only=True)][ - 1: - ] - summary_values = [r for r in summary_values if any(r)] - assert summary_values and summary_values[0][1] == "DDF00081" - assert summary_values[0][4] == 1 - - # Issue Details strict checks: now expect one row per error - issue_details_sheet = workbook[issue_datails_sheet] - details_rows = [r for r in issue_details_sheet.iter_rows(values_only=True)][1:] - details_rows = [r for r in details_rows if any(r)] - # Expect exactly 15 rows - assert len(details_rows) == 15 - - # Expected exact strings - for row in details_rows: - assert row[0] == "DDF00081" - assert ( - row[2] - == "The class relationship does not conform with the USDM schema." - ) - assert row[7] == ("json_path, message") - - # Rules Report - rules_rows = [ - r for r in workbook[rules_report_sheet].iter_rows(values_only=True) - ][1:] - rules_rows = [r for r in rules_rows if any(r)] - assert rules_rows and rules_rows[0][0] == "DDF00081" - assert "ISSUE REPORTED" in rules_rows[0] - if os.path.exists(excel_file_path): - os.remove(excel_file_path) +import os +import subprocess +import unittest +import openpyxl +import pytest +from conftest import get_python_executable +from QARegressionTests.globals import ( + issue_datails_sheet, + rules_report_sheet, + issue_sheet_record_column, + issue_sheet_variable_column, + issue_sheet_values_column, +) + + +@pytest.mark.regression +class TestCoreIssue715(unittest.TestCase): + def test_positive_dataset(self): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "usdm", + "-v", + "4-0", + "-dp", + os.path.join( + "tests", "resources", "CoreIssue715", "CDISC_Pilot_Study.json" + ), + "-lr", + os.path.join("tests", "resources", "CoreIssue715", "rule.yml"), + ] + subprocess.run(command, check=True) + + # Get the latest created Excel file + files = os.listdir() + excel_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".xlsx") + ] + excel_file_path = sorted(excel_files)[-1] + # # Open the Excel file + workbook = openpyxl.load_workbook(excel_file_path) + + # Go to the "Issue Details" sheet + sheet = workbook[issue_datails_sheet] + + record_column = sheet[issue_sheet_record_column] + variables_column = sheet[issue_sheet_variable_column] + values_column = sheet[issue_sheet_values_column] + + record_values = [cell.value for cell in record_column[1:]] + variables_values = [cell.value for cell in variables_column[1:]] + values_column_values = [cell.value for cell in values_column[1:]] + + # Remove None values using list comprehension + record_values = [value for value in record_values if value is not None] + variables_values = [value for value in variables_values if value is not None] + values_column_values = [ + value for value in values_column_values if value is not None + ] + rules_values = [ + row for row in workbook[rules_report_sheet].iter_rows(values_only=True) + ][1:] + rules_values = [row for row in rules_values if any(row)] + # Perform the assertion + assert rules_values[0][0] == "DDF00081" + assert "SUCCESS" in rules_values[0] + assert len(record_values) == 0 + assert len(variables_values) == 0 + assert len(values_column_values) == 0 + if os.path.exists(excel_file_path): + os.remove(excel_file_path) + + def test_negative_dataset(self): + # Run validation for invalid JSON + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "usdm", + "-v", + "4-0", + "-dp", + os.path.join( + "tests", "resources", "CoreIssue715", "CDISC_Pilot_Study_Invalid.json" + ), + "-lr", + os.path.join("tests", "resources", "CoreIssue715", "rule.yml"), + ] + subprocess.run(command, check=True) + + files = os.listdir() + excel_files = [ + f for f in files if f.startswith("CORE-Report-") and f.endswith(".xlsx") + ] + excel_file_path = sorted(excel_files)[-1] + workbook = openpyxl.load_workbook(excel_file_path) + + # Issue Summary basic checks + issue_summary_sheet = workbook["Issue Summary"] + summary_values = [r for r in issue_summary_sheet.iter_rows(values_only=True)][ + 1: + ] + summary_values = [r for r in summary_values if any(r)] + assert summary_values and summary_values[0][1] == "DDF00081" + assert summary_values[0][4] == 1 + + # Issue Details strict checks: now expect one row per error + issue_details_sheet = workbook[issue_datails_sheet] + details_rows = [r for r in issue_details_sheet.iter_rows(values_only=True)][1:] + details_rows = [r for r in details_rows if any(r)] + # Expect exactly 15 rows + assert len(details_rows) == 15 + + # Expected exact strings + for row in details_rows: + assert row[0] == "DDF00081" + assert ( + row[2] + == "The class relationship does not conform with the USDM schema." + ) + assert row[7] == ("json_path, message") + + # Rules Report + rules_rows = [ + r for r in workbook[rules_report_sheet].iter_rows(values_only=True) + ][1:] + rules_rows = [r for r in rules_rows if any(r)] + assert rules_rows and rules_rows[0][0] == "DDF00081" + assert "ISSUE REPORTED" in rules_rows[0] + if os.path.exists(excel_file_path): + os.remove(excel_file_path) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue720.py b/tests/QARegressionTests/test_Issues/test_CoreIssue720.py index a00aa158a..a655deb8d 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue720.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue720.py @@ -1,149 +1,149 @@ -import os -import subprocess -import unittest - -import openpyxl -import pytest -from conftest import get_python_executable -from QARegressionTests.globals import ( - issue_datails_sheet, - rules_report_sheet, -) - - -@pytest.mark.skip(reason="The test is obsolete and requires modernization.") -class TestCoreIssue720(unittest.TestCase): - def test_negative_dataset(self): - """Negative scenario: SPECIES missing -> expect one populated issue.""" - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "usdm", - "-v", - "4-0", - "-dp", - os.path.join("tests", "resources", "CoreIssue720", "Invalid_datasets.json"), - "-lr", - os.path.join("tests", "resources", "CoreIssue720", "Rule.yml"), - ] - subprocess.run(command, check=True) - - excel_files = [ - f - for f in os.listdir() - if f.startswith("CORE-Report-") and f.endswith(".xlsx") - ] - assert excel_files, "No CORE report generated" - excel_file_path = sorted(excel_files)[-1] - wb = openpyxl.load_workbook(excel_file_path) - - # Conformance Details - assert "Conformance Details" in wb.sheetnames - conf_rows = [ - row for row in wb["Conformance Details"].iter_rows(values_only=True) - ] - assert conf_rows[6][0] == "Standard" - assert conf_rows[6][1] == "USDM" - assert conf_rows[7][0] == "Version" - assert conf_rows[7][1] == "V4.0" - - # Entity Details - entity_rows = [row for row in wb["Entity Details"].iter_rows(values_only=True)][ - 1: - ] - entity_rows = [r for r in entity_rows if any(r)] - assert len(entity_rows) >= 2 - assert entity_rows[0][0] == "DM" and entity_rows[0][1] == 4 - assert entity_rows[1][0] == "TS" and entity_rows[1][1] == 4 - - # Issue Summary - summary_rows = [row for row in wb["Issue Summary"].iter_rows(values_only=True)][ - 1: - ] - summary_rows = [r for r in summary_rows if any(r)] - assert summary_rows[0][0] == "dm.xpt" - assert summary_rows[0][1] == "CDISC.SENDIG.105" - assert summary_rows[0][4] == 1 - - # Issue Details - details_rows = [ - row for row in wb[issue_datails_sheet].iter_rows(values_only=True) - ][1:] - details_rows = [r for r in details_rows if any(r)] - assert details_rows, "Issue Details should have at least one populated row" - first_issue = details_rows[0] - assert first_issue[0] == "CDISC.SENDIG.105" - assert first_issue[1] == "SEND105" - assert "SPECIES in not present" in first_issue[2] - assert first_issue[3] == "fully executable" - assert first_issue[4] == "dm.xpt" - assert first_issue[7] == "$distinct_tsparmcd, $distinct_txparmcd, SPECIES" - assert "Not in dataset" in first_issue[8] - - # Rules Report - rules_rows = [ - row for row in wb[rules_report_sheet].iter_rows(values_only=True) - ][1:] - rules_rows = [r for r in rules_rows if any(r)] - assert rules_rows, "Rules Report must have at least one populated row" - assert rules_rows[0][0] == "CDISC.SENDIG.105" - assert rules_rows[0][-1] == "SUCCESS" - - if os.path.exists(excel_file_path): - os.remove(excel_file_path) - - def test_positive_dataset(self): - """Positive scenario: SPECIES present -> expect no issue rows.""" - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "usdm", - "-v", - "4-0", - "-dp", - os.path.join("tests", "resources", "CoreIssue720", "Valid_datasets.json"), - "-lr", - os.path.join("tests", "resources", "CoreIssue720", "Rule.yml"), - ] - subprocess.run(command, check=True) - - excel_files = [ - f - for f in os.listdir() - if f.startswith("CORE-Report-") and f.endswith(".xlsx") - ] - assert excel_files, "No CORE report generated" - excel_file_path = sorted(excel_files)[-1] - wb = openpyxl.load_workbook(excel_file_path) - - # Issue Summary empty - summary_rows = [row for row in wb["Issue Summary"].iter_rows(values_only=True)][ - 1: - ] - summary_rows = [r for r in summary_rows if any(r)] - assert summary_rows == [] - - # Issue Details empty - details_rows = [ - row for row in wb[issue_datails_sheet].iter_rows(values_only=True) - ][1:] - details_rows = [r for r in details_rows if any(r)] - assert details_rows == [] - - # Rules Report has success row - rules_rows = [ - row for row in wb[rules_report_sheet].iter_rows(values_only=True) - ][1:] - rules_rows = [r for r in rules_rows if any(r)] - assert len(rules_rows) == 1 - assert rules_rows[0][0] == "CDISC.SENDIG.105" - assert rules_rows[0][-1] == "SUCCESS" - - if os.path.exists(excel_file_path): - os.remove(excel_file_path) +import os +import subprocess +import unittest + +import openpyxl +import pytest +from conftest import get_python_executable +from QARegressionTests.globals import ( + issue_datails_sheet, + rules_report_sheet, +) + + +@pytest.mark.skip(reason="The test is obsolete and requires modernization.") +class TestCoreIssue720(unittest.TestCase): + def test_negative_dataset(self): + """Negative scenario: SPECIES missing -> expect one populated issue.""" + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "usdm", + "-v", + "4-0", + "-dp", + os.path.join("tests", "resources", "CoreIssue720", "Invalid_datasets.json"), + "-lr", + os.path.join("tests", "resources", "CoreIssue720", "Rule.yml"), + ] + subprocess.run(command, check=True) + + excel_files = [ + f + for f in os.listdir() + if f.startswith("CORE-Report-") and f.endswith(".xlsx") + ] + assert excel_files, "No CORE report generated" + excel_file_path = sorted(excel_files)[-1] + wb = openpyxl.load_workbook(excel_file_path) + + # Conformance Details + assert "Conformance Details" in wb.sheetnames + conf_rows = [ + row for row in wb["Conformance Details"].iter_rows(values_only=True) + ] + assert conf_rows[6][0] == "Standard" + assert conf_rows[6][1] == "USDM" + assert conf_rows[7][0] == "Version" + assert conf_rows[7][1] == "V4.0" + + # Entity Details + entity_rows = [row for row in wb["Entity Details"].iter_rows(values_only=True)][ + 1: + ] + entity_rows = [r for r in entity_rows if any(r)] + assert len(entity_rows) >= 2 + assert entity_rows[0][0] == "DM" and entity_rows[0][1] == 4 + assert entity_rows[1][0] == "TS" and entity_rows[1][1] == 4 + + # Issue Summary + summary_rows = [row for row in wb["Issue Summary"].iter_rows(values_only=True)][ + 1: + ] + summary_rows = [r for r in summary_rows if any(r)] + assert summary_rows[0][0] == "dm.xpt" + assert summary_rows[0][1] == "CDISC.SENDIG.105" + assert summary_rows[0][4] == 1 + + # Issue Details + details_rows = [ + row for row in wb[issue_datails_sheet].iter_rows(values_only=True) + ][1:] + details_rows = [r for r in details_rows if any(r)] + assert details_rows, "Issue Details should have at least one populated row" + first_issue = details_rows[0] + assert first_issue[0] == "CDISC.SENDIG.105" + assert first_issue[1] == "SEND105" + assert "SPECIES in not present" in first_issue[2] + assert first_issue[3] == "fully executable" + assert first_issue[4] == "dm.xpt" + assert first_issue[7] == "$distinct_tsparmcd, $distinct_txparmcd, SPECIES" + assert "Not in dataset" in first_issue[8] + + # Rules Report + rules_rows = [ + row for row in wb[rules_report_sheet].iter_rows(values_only=True) + ][1:] + rules_rows = [r for r in rules_rows if any(r)] + assert rules_rows, "Rules Report must have at least one populated row" + assert rules_rows[0][0] == "CDISC.SENDIG.105" + assert rules_rows[0][-1] == "SUCCESS" + + if os.path.exists(excel_file_path): + os.remove(excel_file_path) + + def test_positive_dataset(self): + """Positive scenario: SPECIES present -> expect no issue rows.""" + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "usdm", + "-v", + "4-0", + "-dp", + os.path.join("tests", "resources", "CoreIssue720", "Valid_datasets.json"), + "-lr", + os.path.join("tests", "resources", "CoreIssue720", "Rule.yml"), + ] + subprocess.run(command, check=True) + + excel_files = [ + f + for f in os.listdir() + if f.startswith("CORE-Report-") and f.endswith(".xlsx") + ] + assert excel_files, "No CORE report generated" + excel_file_path = sorted(excel_files)[-1] + wb = openpyxl.load_workbook(excel_file_path) + + # Issue Summary empty + summary_rows = [row for row in wb["Issue Summary"].iter_rows(values_only=True)][ + 1: + ] + summary_rows = [r for r in summary_rows if any(r)] + assert summary_rows == [] + + # Issue Details empty + details_rows = [ + row for row in wb[issue_datails_sheet].iter_rows(values_only=True) + ][1:] + details_rows = [r for r in details_rows if any(r)] + assert details_rows == [] + + # Rules Report has success row + rules_rows = [ + row for row in wb[rules_report_sheet].iter_rows(values_only=True) + ][1:] + rules_rows = [r for r in rules_rows if any(r)] + assert len(rules_rows) == 1 + assert rules_rows[0][0] == "CDISC.SENDIG.105" + assert rules_rows[0][-1] == "SUCCESS" + + if os.path.exists(excel_file_path): + os.remove(excel_file_path) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue747.py b/tests/QARegressionTests/test_Issues/test_CoreIssue747.py index 241d26391..75ce4d600 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue747.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue747.py @@ -1,80 +1,78 @@ -import subprocess -import os -import openpyxl -import pytest -from conftest import get_python_executable -from QARegressionTests.globals import ( - issue_datails_sheet, - dataset_details_sheet, - rules_report_sheet, - issue_sheet_coreid_column, - dataset_sheet_dataset_column, - rules_sheet_rule_status_column, -) - -""" These tests utilizes a dataset -to validate successful working CG0019. The dataset -have both positive and negative cases, -including the supp and split domains""" - - -@pytest.mark.skip(reason="The test is obsolete and requires modernization.") -def test_CG0019(): - command = ( - f"{get_python_executable()} -m core test -s sdtmig -v 3.4 -r " - + os.path.join("tests", "resources", "CoreIssue747", "Rule_underscores.json") - + " -dp " - + os.path.join("tests", "resources", "CoreIssue747", "Datasets.json") - + " -dxp " - + os.path.join( - "tests", "resources", "CoreIssue747", "define_CG0019_split_and_supp.xml" - ) - ) - - # Construct the command - command = command.split(" ") - - # Run the command in the terminal - process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = process.communicate() - - file_name = stdout.decode().strip().split(": ")[1] - # Open the Excel file - workbook = openpyxl.load_workbook(file_name) - - # Go to the "Issue Details" sheet - issues_sheet = workbook[issue_datails_sheet] - dataset_sheet = workbook[dataset_details_sheet] - rules_sheet = workbook[rules_report_sheet] - - coreid_column = issues_sheet[issue_sheet_coreid_column] - dataset_column = dataset_sheet[dataset_sheet_dataset_column] - rule_status_column = rules_sheet[rules_sheet_rule_status_column] - - coreid_values = [cell.value for cell in coreid_column[1:]] - dataset_values = [cell.value for cell in dataset_column[1:]] - rule_status_column_values = [cell.value for cell in rule_status_column[1:]] - - # Remove None values using list comprehension - coreid_values = [value for value in coreid_values if value is not None] - dataset_values = [value for value in dataset_values if value is not None] - rule_status_column_values = [ - value for value in rule_status_column_values if value is not None - ] - - # Perform the assertion - assert process.returncode == 0, f"Process failed with error: {stderr.decode()}" - assert dataset_values[0] == "ECAA" - assert dataset_values[1] == "ECBB" - assert dataset_values[2] == "SUPPEC" - assert len(dataset_values) == 3 - - assert len(coreid_values) == 4 - - assert rule_status_column_values[0] == "SUCCESS" - - # Close the workbook - workbook.close() - - # Delete the file - os.remove(file_name) +import subprocess +import os +import openpyxl +from conftest import get_python_executable +from QARegressionTests.globals import ( + issue_datails_sheet, + dataset_details_sheet, + rules_report_sheet, + issue_sheet_coreid_column, + dataset_sheet_dataset_column, + rules_sheet_rule_status_column, +) + +""" These tests utilizes a dataset +to validate successful working CG0019. The dataset +have both positive and negative cases, +including the supp and split domains""" + + +def test_CG0019(): + command = ( + f"{get_python_executable()} -m core validate -s sdtmig -v 3.4 -lr " + + os.path.join("tests", "resources", "CoreIssue747", "Rule_underscores.json") + + " -dp " + + os.path.join("tests", "resources", "CoreIssue747", "Datasets.json") + + " -dxp " + + os.path.join( + "tests", "resources", "CoreIssue747", "define_CG0019_split_and_supp.xml" + ) + ) + + # Construct the command + command = command.split(" ") + + # Run the command in the terminal + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + + file_name = stdout.decode().strip().split(": ")[1] + # Open the Excel file + workbook = openpyxl.load_workbook(file_name) + + # Go to the "Issue Details" sheet + issues_sheet = workbook[issue_datails_sheet] + dataset_sheet = workbook[dataset_details_sheet] + rules_sheet = workbook[rules_report_sheet] + + coreid_column = issues_sheet[issue_sheet_coreid_column] + dataset_column = dataset_sheet[dataset_sheet_dataset_column] + rule_status_column = rules_sheet[rules_sheet_rule_status_column] + + coreid_values = [cell.value for cell in coreid_column[1:]] + dataset_values = [cell.value for cell in dataset_column[1:]] + rule_status_column_values = [cell.value for cell in rule_status_column[1:]] + + # Remove None values using list comprehension + coreid_values = [value for value in coreid_values if value is not None] + dataset_values = [value for value in dataset_values if value is not None] + rule_status_column_values = [ + value for value in rule_status_column_values if value is not None + ] + + # Perform the assertion + assert process.returncode == 0, f"Process failed with error: {stderr.decode()}" + assert dataset_values[0] == "ECAA" + assert dataset_values[1] == "ECBB" + assert dataset_values[2] == "SUPPEC" + assert len(dataset_values) == 3 + + assert len(coreid_values) == 4 + + assert rule_status_column_values[0] == "ISSUE REPORTED" + + # Close the workbook + workbook.close() + + # Delete the file + os.remove(file_name) diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue890.py b/tests/QARegressionTests/test_Issues/test_CoreIssue890.py index 9e8f8ce27..e87d3e763 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue890.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue890.py @@ -1,162 +1,160 @@ -import os -import subprocess -import unittest -import openpyxl -import pytest -from conftest import get_python_executable -from QARegressionTests.globals import ( - issue_datails_sheet, - rules_report_sheet, - issue_sheet_record_column, - issue_sheet_variable_column, - issue_sheet_values_column, -) - - -@pytest.mark.skip(reason="The test is obsolete and requires modernization.") -class TestColumnConsistsOfDelimitedCodelists(unittest.TestCase): - def test_positive_dataset(self): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "send", - "-v", - "1-0", - "-dp", - os.path.join( - "tests", - "resources", - "CoreIssue890", - "unit-test-coreid-SENDIG282-positive.json", - ), - "-lr", - os.path.join("tests", "resources", "CoreIssue890", "Rule.yml"), - "-ct", - "sendct-2025-09-26", - ] - subprocess.run(command, check=True) - - # Get the latest created Excel file - files = os.listdir() - excel_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".xlsx") - ] - excel_file_path = sorted(excel_files)[-1] - # # Open the Excel file - workbook = openpyxl.load_workbook(excel_file_path) - - # Go to the "Issue Details" sheet - sheet = workbook[issue_datails_sheet] - - record_column = sheet[issue_sheet_record_column] - variables_column = sheet[issue_sheet_variable_column] - values_column = sheet[issue_sheet_values_column] - - record_values = [cell.value for cell in record_column[1:]] - variables_values = [cell.value for cell in variables_column[1:]] - values_column_values = [cell.value for cell in values_column[1:]] - - # Remove None values using list comprehension - record_values = [value for value in record_values if value is not None] - variables_values = [value for value in variables_values if value is not None] - values_column_values = [ - value for value in values_column_values if value is not None - ] - rules_values = [ - row for row in workbook[rules_report_sheet].iter_rows(values_only=True) - ][1:] - rules_values = [row for row in rules_values if any(row)] - # Perform the assertion - # Ensure only two negative values are caught - assert rules_values[0][0] == "CDISC.SENDIG.SEND282" - assert len(record_values) == 0 - assert len(variables_values) == 0 - assert len(values_column_values) == 0 - if os.path.exists(excel_file_path): - os.remove(excel_file_path) - - def test_negaive_dataset(self): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "send", - "-v", - "1-0", - "-dp", - os.path.join( - "tests", - "resources", - "CoreIssue890", - "unit-test-coreid-SENDIG282-negative.json", - ), - "-lr", - os.path.join("tests", "resources", "CoreIssue890", "Rule.yml"), - "-ct", - "sendct-2025-09-26", - ] - subprocess.run(command, check=True) - - # Get the latest created Excel file - files = os.listdir() - excel_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".xlsx") - ] - excel_file_path = sorted(excel_files)[-1] - # Open the Excel file - workbook = openpyxl.load_workbook(excel_file_path) - - # --- Dataset Details --- - dataset_sheet = workbook["Dataset Details"] - dataset_values = [row for row in dataset_sheet.iter_rows(values_only=True)][1:] - dataset_values = [row for row in dataset_values if any(row)] - assert len(dataset_values) > 0 - assert dataset_values[0][0] == "pp.xpt" - assert dataset_values[0][1] == "Pharmacokinetics Parameters" - assert dataset_values[0][-1] == 4 - - # --- Issue Summary --- - issue_summary_sheet = workbook["Issue Summary"] - summary_values = [ - row for row in issue_summary_sheet.iter_rows(values_only=True) - ][1:] - summary_values = [row for row in summary_values if any(row)] - assert len(summary_values) > 0 - assert summary_values[0][0] == "pp.xpt" - assert summary_values[0][1] == "CDISC.SENDIG.SEND282" - assert summary_values[0][3] == 2 - - # --- Issue Details --- - issue_details_sheet = workbook["Issue Details"] - details_values = [ - row for row in issue_details_sheet.iter_rows(values_only=True) - ][1:] - details_values = [row for row in details_values if any(row)] - assert all(row[0] == "CDISC.SENDIG.SEND282" for row in details_values) - assert len(details_values) == 2 - - # --- Rules Report --- - rules_values = [ - row for row in workbook["Rules Report"].iter_rows(values_only=True) - ][1:] - rules_values = [row for row in rules_values if any(row)] - assert len(rules_values) > 0 - assert rules_values[0][0] == "CDISC.SENDIG.SEND282" - - if os.path.exists(excel_file_path): - os.remove(excel_file_path) - - -# if __name__ == "__main__": -# unittest.main() +import os +import subprocess +import unittest +import openpyxl +from conftest import get_python_executable +from QARegressionTests.globals import ( + issue_datails_sheet, + rules_report_sheet, + issue_sheet_record_column, + issue_sheet_variable_column, + issue_sheet_values_column, +) + + +class TestColumnConsistsOfDelimitedCodelists(unittest.TestCase): + def test_positive_dataset(self): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sendig", + "-v", + "3-1", + "-dp", + os.path.join( + "tests", + "resources", + "CoreIssue890", + "unit-test-coreid-SENDIG282-positive.json", + ), + "-lr", + os.path.join("tests", "resources", "CoreIssue890", "Rule.yml"), + "-ct", + "sendct-2025-09-26", + ] + subprocess.run(command, check=True) + + # Get the latest created Excel file + files = os.listdir() + excel_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".xlsx") + ] + excel_file_path = sorted(excel_files)[-1] + # # Open the Excel file + workbook = openpyxl.load_workbook(excel_file_path) + + # Go to the "Issue Details" sheet + sheet = workbook[issue_datails_sheet] + + record_column = sheet[issue_sheet_record_column] + variables_column = sheet[issue_sheet_variable_column] + values_column = sheet[issue_sheet_values_column] + + record_values = [cell.value for cell in record_column[1:]] + variables_values = [cell.value for cell in variables_column[1:]] + values_column_values = [cell.value for cell in values_column[1:]] + + # Remove None values using list comprehension + record_values = [value for value in record_values if value is not None] + variables_values = [value for value in variables_values if value is not None] + values_column_values = [ + value for value in values_column_values if value is not None + ] + rules_values = [ + row for row in workbook[rules_report_sheet].iter_rows(values_only=True) + ][1:] + rules_values = [row for row in rules_values if any(row)] + # Perform the assertion + # Ensure only two negative values are caught + assert rules_values[0][0] == "CDISC.SENDIG.SEND282" + assert len(record_values) == 0 + assert len(variables_values) == 0 + assert len(values_column_values) == 0 + if os.path.exists(excel_file_path): + os.remove(excel_file_path) + + def test_negative_dataset(self): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sendig", + "-v", + "3-1", + "-dp", + os.path.join( + "tests", + "resources", + "CoreIssue890", + "unit-test-coreid-SENDIG282-negative.json", + ), + "-lr", + os.path.join("tests", "resources", "CoreIssue890", "Rule.yml"), + "-ct", + "sendct-2025-09-26", + ] + subprocess.run(command, check=True) + + # Get the latest created Excel file + files = os.listdir() + excel_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".xlsx") + ] + excel_file_path = sorted(excel_files)[-1] + # Open the Excel file + workbook = openpyxl.load_workbook(excel_file_path) + + # --- Dataset Details --- + dataset_sheet = workbook["Dataset Details"] + dataset_values = [row for row in dataset_sheet.iter_rows(values_only=True)][1:] + dataset_values = [row for row in dataset_values if any(row)] + assert len(dataset_values) > 0 + assert dataset_values[0][0] == "PP" + assert dataset_values[0][1] == "Pharmacokinetics Parameters" + assert dataset_values[0][-1] == 4 + + # --- Issue Summary --- + issue_summary_sheet = workbook["Issue Summary"] + summary_values = [ + row for row in issue_summary_sheet.iter_rows(values_only=True) + ][1:] + summary_values = [row for row in summary_values if any(row)] + assert len(summary_values) > 0 + assert summary_values[0][0] == "PP" + assert summary_values[0][1] == "CDISC.SENDIG.SEND282" + assert summary_values[0][3] == 2 + + # --- Issue Details --- + issue_details_sheet = workbook["Issue Details"] + details_values = [ + row for row in issue_details_sheet.iter_rows(values_only=True) + ][1:] + details_values = [row for row in details_values if any(row)] + assert all(row[0] == "CDISC.SENDIG.SEND282" for row in details_values) + assert len(details_values) == 2 + + # --- Rules Report --- + rules_values = [ + row for row in workbook["Rules Report"].iter_rows(values_only=True) + ][1:] + rules_values = [row for row in rules_values if any(row)] + assert len(rules_values) > 0 + assert rules_values[0][0] == "CDISC.SENDIG.SEND282" + + if os.path.exists(excel_file_path): + os.remove(excel_file_path) + + +# if __name__ == "__main__": +# unittest.main() diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue897.py b/tests/QARegressionTests/test_Issues/test_CoreIssue897.py index 67758617e..8ea9ec399 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue897.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue897.py @@ -1,159 +1,159 @@ -import os -import subprocess -import unittest -import openpyxl -import pytest -from conftest import get_python_executable -from QARegressionTests.globals import ( - entity_details_sheet, - issue_datails_sheet, - rules_report_sheet, - issue_sheet_record_column, - issue_sheet_variable_column, - issue_sheet_values_column, -) - - -@pytest.mark.regression -class TestGetXHTMLErrors(unittest.TestCase): - def test_positive_dataset(self): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "usdm", - "-v", - "4-0", - "-dp", - os.path.join( - "tests", - "resources", - "CoreIssue897", - "Positive_datasets.json", - ), - "-lr", - os.path.join("tests", "resources", "CoreIssue897", "Rule.yml"), - ] - subprocess.run(command, check=True) - - # Get the latest created Excel file - files = os.listdir() - excel_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".xlsx") - ] - excel_file_path = sorted(excel_files)[-1] - # # Open the Excel file - workbook = openpyxl.load_workbook(excel_file_path) - - # Go to the "Issue Details" sheet - sheet = workbook[issue_datails_sheet] - - record_column = sheet[issue_sheet_record_column] - variables_column = sheet[issue_sheet_variable_column] - values_column = sheet[issue_sheet_values_column] - - record_values = [cell.value for cell in record_column[1:]] - variables_values = [cell.value for cell in variables_column[1:]] - values_column_values = [cell.value for cell in values_column[1:]] - - # Remove None values using list comprehension - record_values = [value for value in record_values if value is not None] - variables_values = [value for value in variables_values if value is not None] - values_column_values = [ - value for value in values_column_values if value is not None - ] - rules_values = [ - row for row in workbook[rules_report_sheet].iter_rows(values_only=True) - ][1:] - rules_values = [row for row in rules_values if any(row)] - # Perform the assertion - # Ensure only two negative values are caught - assert rules_values[0][0] == "CORE-000409" - assert rules_values[0][-1] == "SUCCESS" - assert len(record_values) == 0 - assert len(variables_values) == 0 - assert len(values_column_values) == 0 - if os.path.exists(excel_file_path): - os.remove(excel_file_path) - - def test_negative_dataset(self): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "usdm", - "-v", - "4-0", - "-dp", - os.path.join( - "tests", - "resources", - "CoreIssue897", - "Negative_datasets.json", - ), - "-lr", - os.path.join("tests", "resources", "CoreIssue897", "Rule.yml"), - ] - subprocess.run(command, check=True) - - # Get the latest created Excel file - files = os.listdir() - excel_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".xlsx") - ] - excel_file_path = sorted(excel_files)[-1] - # Open the Excel file - workbook = openpyxl.load_workbook(excel_file_path) - - # --- Dataset Details --- - dataset_sheet = workbook[entity_details_sheet] - dataset_values = [row for row in dataset_sheet.iter_rows(values_only=True)][1:] - dataset_values = [row for row in dataset_values if any(row)] - assert len(dataset_values) > 0 - assert dataset_values[0][0] == "NarrativeContentItem" - assert dataset_values[0][-1] == 170 - - # --- Issue Summary --- - issue_summary_sheet = workbook["Issue Summary"] - summary_values = [ - row for row in issue_summary_sheet.iter_rows(values_only=True) - ][1:] - summary_values = [row for row in summary_values if any(row)] - assert len(summary_values) > 0 - assert summary_values[0][1] == "CORE-000409" - assert summary_values[0][4] == 4 - - # --- Issue Details --- - issue_details_sheet = workbook["Issue Details"] - details_values = [ - row for row in issue_details_sheet.iter_rows(values_only=True) - ][1:] - details_values = [row for row in details_values if any(row)] - assert all(row[0] == "CORE-000409" for row in details_values) - assert len(details_values) == 4 - - # --- Rules Report --- - rules_values = [ - row for row in workbook["Rules Report"].iter_rows(values_only=True) - ][1:] - rules_values = [row for row in rules_values if any(row)] - assert len(rules_values) > 0 - assert rules_values[0][0] == "CORE-000409" - assert rules_values[0][-1] == "ISSUE REPORTED" - - if os.path.exists(excel_file_path): - os.remove(excel_file_path) - - -# if __name__ == "__main__": -# unittest.main() +import os +import subprocess +import unittest +import openpyxl +import pytest +from conftest import get_python_executable +from QARegressionTests.globals import ( + entity_details_sheet, + issue_datails_sheet, + rules_report_sheet, + issue_sheet_record_column, + issue_sheet_variable_column, + issue_sheet_values_column, +) + + +@pytest.mark.regression +class TestGetXHTMLErrors(unittest.TestCase): + def test_positive_dataset(self): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "usdm", + "-v", + "4-0", + "-dp", + os.path.join( + "tests", + "resources", + "CoreIssue897", + "Positive_datasets.json", + ), + "-lr", + os.path.join("tests", "resources", "CoreIssue897", "Rule.yml"), + ] + subprocess.run(command, check=True) + + # Get the latest created Excel file + files = os.listdir() + excel_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".xlsx") + ] + excel_file_path = sorted(excel_files)[-1] + # # Open the Excel file + workbook = openpyxl.load_workbook(excel_file_path) + + # Go to the "Issue Details" sheet + sheet = workbook[issue_datails_sheet] + + record_column = sheet[issue_sheet_record_column] + variables_column = sheet[issue_sheet_variable_column] + values_column = sheet[issue_sheet_values_column] + + record_values = [cell.value for cell in record_column[1:]] + variables_values = [cell.value for cell in variables_column[1:]] + values_column_values = [cell.value for cell in values_column[1:]] + + # Remove None values using list comprehension + record_values = [value for value in record_values if value is not None] + variables_values = [value for value in variables_values if value is not None] + values_column_values = [ + value for value in values_column_values if value is not None + ] + rules_values = [ + row for row in workbook[rules_report_sheet].iter_rows(values_only=True) + ][1:] + rules_values = [row for row in rules_values if any(row)] + # Perform the assertion + # Ensure only two negative values are caught + assert rules_values[0][0] == "CORE-000409" + assert rules_values[0][-1] == "SUCCESS" + assert len(record_values) == 0 + assert len(variables_values) == 0 + assert len(values_column_values) == 0 + if os.path.exists(excel_file_path): + os.remove(excel_file_path) + + def test_negative_dataset(self): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "usdm", + "-v", + "4-0", + "-dp", + os.path.join( + "tests", + "resources", + "CoreIssue897", + "Negative_datasets.json", + ), + "-lr", + os.path.join("tests", "resources", "CoreIssue897", "Rule.yml"), + ] + subprocess.run(command, check=True) + + # Get the latest created Excel file + files = os.listdir() + excel_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".xlsx") + ] + excel_file_path = sorted(excel_files)[-1] + # Open the Excel file + workbook = openpyxl.load_workbook(excel_file_path) + + # --- Dataset Details --- + dataset_sheet = workbook[entity_details_sheet] + dataset_values = [row for row in dataset_sheet.iter_rows(values_only=True)][1:] + dataset_values = [row for row in dataset_values if any(row)] + assert len(dataset_values) > 0 + assert dataset_values[0][0] == "NarrativeContentItem" + assert dataset_values[0][-1] == 170 + + # --- Issue Summary --- + issue_summary_sheet = workbook["Issue Summary"] + summary_values = [ + row for row in issue_summary_sheet.iter_rows(values_only=True) + ][1:] + summary_values = [row for row in summary_values if any(row)] + assert len(summary_values) > 0 + assert summary_values[0][1] == "CORE-000409" + assert summary_values[0][4] == 4 + + # --- Issue Details --- + issue_details_sheet = workbook["Issue Details"] + details_values = [ + row for row in issue_details_sheet.iter_rows(values_only=True) + ][1:] + details_values = [row for row in details_values if any(row)] + assert all(row[0] == "CORE-000409" for row in details_values) + assert len(details_values) == 4 + + # --- Rules Report --- + rules_values = [ + row for row in workbook["Rules Report"].iter_rows(values_only=True) + ][1:] + rules_values = [row for row in rules_values if any(row)] + assert len(rules_values) > 0 + assert rules_values[0][0] == "CORE-000409" + assert rules_values[0][-1] == "ISSUE REPORTED" + + if os.path.exists(excel_file_path): + os.remove(excel_file_path) + + +# if __name__ == "__main__": +# unittest.main() diff --git a/tests/QARegressionTests/test_Issues/test_CoreIssue984.py b/tests/QARegressionTests/test_Issues/test_CoreIssue984.py index 1bdda31f0..97db38903 100644 --- a/tests/QARegressionTests/test_Issues/test_CoreIssue984.py +++ b/tests/QARegressionTests/test_Issues/test_CoreIssue984.py @@ -1,67 +1,67 @@ -import os -import subprocess - -import pytest -import json -from conftest import get_python_executable - - -@pytest.mark.regression -class TestCoreIssue984: - def test_define_subversion_ignored(self): - # Run the command in the terminal - command = [ - f"{get_python_executable()}", - "-m", - "core", - "validate", - "-s", - "sdtmig", - "-r", - "CORE-000007", - "-v", - "3.4", - "-dp", - os.path.join( - "tests", - "resources", - "test_dataset.json", - ), - "-dxp", - os.path.join("tests", "resources", "CoreIssue984", "define.xml"), - "--output-format", - "json", - "-ps", - "1", - ] - subprocess.run(command, check=True) - - files = os.listdir() - json_files = [ - file - for file in files - if file.startswith("CORE-Report-") and file.endswith(".json") - ] - json_report_path = sorted(json_files)[-1] - # Open the JSON report file - json_report = json.load(open(json_report_path)) - assert { - "Conformance_Details", - "Dataset_Details", - "Issue_Summary", - "Issue_Details", - "Rules_Report", - }.issubset(json_report.keys()) - - assert { - "Conformance_Details", - "Dataset_Details", - "Issue_Summary", - "Issue_Details", - "Rules_Report", - }.issubset(json_report.keys()) - assert json_report["Conformance_Details"]["Standard"] == "SDTMIG" - assert json_report["Conformance_Details"]["Define_XML_Version"] == "2.1.5" - - if os.path.exists(json_report_path): - os.remove(json_report_path) +import os +import subprocess + +import pytest +import json +from conftest import get_python_executable + + +@pytest.mark.regression +class TestCoreIssue984: + def test_define_subversion_ignored(self): + # Run the command in the terminal + command = [ + f"{get_python_executable()}", + "-m", + "core", + "validate", + "-s", + "sdtmig", + "-r", + "CORE-000007", + "-v", + "3.4", + "-dp", + os.path.join( + "tests", + "resources", + "test_dataset.json", + ), + "-dxp", + os.path.join("tests", "resources", "CoreIssue984", "define.xml"), + "--output-format", + "json", + "-ps", + "1", + ] + subprocess.run(command, check=True) + + files = os.listdir() + json_files = [ + file + for file in files + if file.startswith("CORE-Report-") and file.endswith(".json") + ] + json_report_path = sorted(json_files)[-1] + # Open the JSON report file + json_report = json.load(open(json_report_path)) + assert { + "Conformance_Details", + "Dataset_Details", + "Issue_Summary", + "Issue_Details", + "Rules_Report", + }.issubset(json_report.keys()) + + assert { + "Conformance_Details", + "Dataset_Details", + "Issue_Summary", + "Issue_Details", + "Rules_Report", + }.issubset(json_report.keys()) + assert json_report["Conformance_Details"]["Standard"] == "SDTMIG" + assert json_report["Conformance_Details"]["Define_XML_Version"] == "2.1.5" + + if os.path.exists(json_report_path): + os.remove(json_report_path) diff --git a/tests/QARegressionTests/test_core/test_utils.py b/tests/QARegressionTests/test_core/test_utils.py index 89f9fabd6..900ac386e 100644 --- a/tests/QARegressionTests/test_core/test_utils.py +++ b/tests/QARegressionTests/test_core/test_utils.py @@ -1,33 +1,33 @@ -import subprocess -from platform import system -from os import listdir, remove - - -def run_command(args, shell): - try: - completed_process = subprocess.run( - args, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - universal_newlines=True, - check=True, - encoding="utf8", - # test_test_command and windows seem to be happy with shell=True - # test_validate on linux needs shell=False - shell=shell or system() == "Windows", - ) - return ( - completed_process.returncode, - completed_process.stdout.lower(), - completed_process.stderr.lower(), - ) - except subprocess.CalledProcessError as e: - return e.returncode, e.stdout.lower(), e.stderr.lower() - - -def tearDown(): - for file_name in listdir("."): - if file_name not in ("host.json", "local.settings.json") and ( - file_name.endswith(".xlsx") or file_name.endswith(".json") - ): - remove(file_name) +import subprocess +from platform import system +from os import listdir, remove + + +def run_command(args, shell): + try: + completed_process = subprocess.run( + args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + check=True, + encoding="utf8", + # test_test_command and windows seem to be happy with shell=True + # test_validate on linux needs shell=False + shell=shell or system() == "Windows", + ) + return ( + completed_process.returncode, + completed_process.stdout.lower(), + completed_process.stderr.lower(), + ) + except subprocess.CalledProcessError as e: + return e.returncode, e.stdout.lower(), e.stderr.lower() + + +def tearDown(): + for file_name in listdir("."): + if file_name not in ("host.json", "local.settings.json") and ( + file_name.endswith(".xlsx") or file_name.endswith(".json") + ): + remove(file_name) diff --git a/tests/QARegressionTests/test_core/test_validate.py b/tests/QARegressionTests/test_core/test_validate.py index b3e6229bc..6fb759ec5 100644 --- a/tests/QARegressionTests/test_core/test_validate.py +++ b/tests/QARegressionTests/test_core/test_validate.py @@ -163,7 +163,7 @@ def test_validate_all_options(self): "--meddra", os.path.join("tests", "resources", "dictionaries", "meddra"), "-r", - os.path.join("tests", "resources", "Rule-CG0027.json"), + "CORE-000237", "-lr", os.path.join("tests", "resources", "CG0272.yml"), "-p", @@ -264,7 +264,10 @@ def test_validate_less_than_minimum_options(self): args = ["python", "core.py", "validate", "-s", "sdtmig"] exit_code, stdout, stderr = run_command(args, False) self.assertNotEqual(exit_code, 0) - self.assertIn("error: missing option", stderr) + self.assertIn( + "\n\nerror: missing option '-v' / '--version'.\n", + stderr, + ) def test_validate_output_format_json(self): args = [ @@ -360,12 +363,13 @@ def test_validate_with_log_level_info(self): os.path.join("tests", "resources", "test_dataset.xpt"), "-l", "info", + "-r", + "CORE-000237", ] exit_code, stdout, stderr = run_command(args, False) self.assertEqual(exit_code, 0) self.assertFalse(self.error_keyword in stdout) - self.assertIn("warning", stderr) def test_validate_with_log_level_error(self): args = [