diff --git a/README.md b/README.md index 6c2fd4cb5..34a90b945 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ Run `python core.py validate --help` to see the list of validation options. If set to 0, no maximum will be enforced. -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 diff --git a/core.py b/core.py index f005f5eff..fc0edd9b2 100644 --- a/core.py +++ b/core.py @@ -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.option( "-jcf", @@ -267,7 +267,7 @@ def validate( custom_standard: bool, progress: str, define_xml_path: str, - validate_xml: bool, + validate_xml: str, jsonata_custom_functions: tuple[()] | tuple[tuple[str, str], ...], max_report_rows: int, max_errors_per_rule: int, @@ -289,7 +289,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.") @@ -317,7 +321,7 @@ 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)] ) @@ -325,20 +329,21 @@ def validate( 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, @@ -361,7 +366,7 @@ def validate( custom_standard, progress, define_xml_path, - validate_xml, + validate_xml_bool, jsonata_custom_functions, max_report_rows, max_errors_per_rule, diff --git a/scripts/script_utils.py b/scripts/script_utils.py index f0a5d2203..ff96bd72a 100644 --- a/scripts/script_utils.py +++ b/scripts/script_utils.py @@ -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") diff --git a/tests/QARegressionTests/test_core/test_validate.py b/tests/QARegressionTests/test_core/test_validate.py index 3fb28614e..75e44752c 100644 --- a/tests/QARegressionTests/test_core/test_validate.py +++ b/tests/QARegressionTests/test_core/test_validate.py @@ -236,7 +236,7 @@ def test_validate_include_exclude(self): "error", ] 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 ) @@ -538,7 +538,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 = ( @@ -562,7 +562,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: " @@ -615,7 +615,7 @@ def test_validate_dummy_with_invalid_whodrug_and_meddra(self): self.assertNotEqual(exit_code, 0) self.assertNotEqual(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 " @@ -623,11 +623,12 @@ def test_validate_dummy_without_vx(self): 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 " @@ -635,7 +636,7 @@ def test_validate_dummy_with_vx(self): 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)