Skip to content
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Run `python core.py validate --help` to see the list of validation options.
--output-format JSON.
-dv, --define-version TEXT Define-XML version used for validation
-dxp, --define-xml-path Path to define-xml file.
-vx, --validate-xml This flag enables XML validation against a Define-XML schema.
-vx, --validate-xml Enable XML validation (default 'y' to enable, otherwise disable).
--whodrug TEXT Path to directory with WHODrug dictionary
files
--meddra TEXT Path to directory with MedDRA dictionary
Expand Down
23 changes: 14 additions & 9 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ def cli():
@click.option(
"-vx",
"--validate-xml",
is_flag=True,
help="This flag enables XML validation against a Define-XML schema.",
default="y",
help="Enable XML validation (default 'y' to enable, otherwise disable)",
)
@click.pass_context
def validate(
Expand Down Expand Up @@ -241,7 +241,7 @@ def validate(
custom_standard: bool,
progress: str,
define_xml_path: str,
validate_xml: bool,
validate_xml: str,
):
"""
Validate data using CDISC Rules Engine
Expand All @@ -259,7 +259,11 @@ def validate(
logger.error(
"Flag --raw-report can be used only when --output-format is JSON"
)
ctx.exit()
ctx.exit(2)

if exclude_rules and rules:
logger.error("Cannot use both --rules and --exclude-rules flags together.")
ctx.exit(2)

if exclude_rules and rules:
logger.error("Cannot use both --rules and --exclude-rules flags together.")
Expand Down Expand Up @@ -287,28 +291,29 @@ def validate(
logger.error(
"Argument --dataset-path cannot be used together with argument --data"
)
ctx.exit()
ctx.exit(2)
dataset_paths, found_formats = valid_data_file(
[str(Path(data).joinpath(fn)) for fn in os.listdir(data)]
)
if len(found_formats) > 1:
logger.error(
f"Argument --data contains more than one allowed file format ({', '.join(found_formats)})." # noqa: E501
)
ctx.exit()
ctx.exit(2)
elif dataset_path:
dataset_paths, found_formats = valid_data_file([dp for dp in dataset_path])
if len(found_formats) > 1:
logger.error(
f"Argument --dataset-path contains more than one allowed file format ({', '.join(found_formats)})." # noqa: E501
)
ctx.exit()
ctx.exit(2)
else:
logger.error(
"You must pass one of the following arguments: --dataset-path, --data"
)
# no need to define dataset_paths here, the program execution will stop
ctx.exit()
ctx.exit(2)
validate_xml_bool = True if validate_xml.lower() in ("y", "yes") else False
run_validation(
Validation_args(
cache_path,
Expand All @@ -331,7 +336,7 @@ def validate(
custom_standard,
progress,
define_xml_path,
validate_xml,
validate_xml_bool,
)
)

Expand Down
6 changes: 4 additions & 2 deletions scripts/script_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ def get_library_metadata_from_cache(args) -> LibraryMetadataContainer: # noqa
define_version.model_package == "define_2_1"
and len(args.controlled_terminology_package) > 0
):
raise ValueError(
engine_logger.error(
"Cannot use -ct controlled terminology package command with Define-XML2.1 submission"
)
raise SystemError(2)
elif (
define_version.model_package == "define_2_0"
and len(args.controlled_terminology_package) > 1
):
raise ValueError(
engine_logger.error(
"Cannot provide multiple controlled terminology packages with Define-XML2.0 submission"
)
raise SystemError(2)
standards_file = os.path.join(args.cache, "standards_details.pkl")
models_file = os.path.join(args.cache, "standards_models.pkl")
variables_codelist_file = os.path.join(args.cache, "variable_codelist_maps.pkl")
Expand Down
13 changes: 7 additions & 6 deletions tests/QARegressionTests/test_core/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def test_validate_include_exclude(self):
"CORE-000473",
]
exit_code, stdout, stderr = run_command(args, False)
self.assertEqual(exit_code, 0)
self.assertEqual(exit_code, 2)
self.assertIn(
"cannot use both --rules and --exclude-rules flags together.", stderr
)
Expand Down Expand Up @@ -534,7 +534,7 @@ def test_validate_dummy_with_all_options(self):
f"-l error"
)
exit_code, stdout, stderr = run_command(args, True)
self.assertEqual(exit_code, 0)
self.assertEqual(exit_code, 2)
self.assertFalse(self.error_keyword in stdout)
self.assertFalse(self.error_keyword in stdout)
expected_pattern = (
Expand All @@ -558,7 +558,7 @@ def test_validate_dummy_without_dataset_path(self):
f"-v 3.4 "
)
exit_code, stdout, stderr = run_command(args, True)
self.assertEqual(exit_code, 0)
self.assertEqual(exit_code, 2)
expected_pattern = (
r"\[error \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3} - "
r"core\.py:\d+\] - you must pass one of the following arguments: "
Expand Down Expand Up @@ -611,27 +611,28 @@ def test_validate_dummy_with_invalid_whodrug_and_meddra(self):
self.assertNotEqual(exit_code, 0)
self.assertNotEqual(stderr, "", f"Error while executing command:\n{stderr}")

def test_validate_dummy_without_vx(self):
def test_validate_dummy_with_vx_as_no(self):
args = (
f"python core.py validate "
f"-s sendig "
f"-v 3.1 "
f"-dv 2.1 "
f"-lr {os.path.join('tests', 'resources', 'CoreIssue295', 'SEND4.json')} "
f"-dp {os.path.join('tests', 'resources', 'CoreIssue295', 'dm.json')} "
f"-vx no"
)
exit_code, stdout, stderr = run_command(args, True)
self.assertNotIn("error", stdout)

def test_validate_dummy_with_vx(self):
def test_validate_dummy_with_vx_as_yes(self):
args = (
f"python core.py validate "
f"-s sendig "
f"-v 3.1 "
f"-dv 2.1 "
f"-lr {os.path.join('tests', 'resources', 'CoreIssue295', 'SEND4.json')} "
f"-dp {os.path.join('tests', 'resources', 'CoreIssue295', 'dm.json')} "
f"-vx"
f"-vx y"
)
exit_code, stdout, stderr = run_command(args, True)
self.assertEqual(exit_code, 0)
Expand Down
Loading