def validate(source: str, version: str, output_csv: bool, schemas: Path): """ Validate a transit data file against a specified schema. """ if schemas: _load_schemas(schemas) try: validator = Validators.get_validator(version) except TransidateException as exc: console.rule(HEADER + "Error") raise ClickException(str(exc)) dataset_path = Path(source) dataset = DataSet(dataset_path) result = _validate(validator, dataset) if result.status == ValidationResult.OK: console.rule(HEADER + "Results") console.print("No issues found.") else: console.rule(HEADER + f"Results: {len(result.violations)} Issues found") ConsoleOutput(dataset=dataset, result=result).output() if output_csv: CSVOutput(dataset=dataset, result=result).output()
def validate(self, dataset: DataSet) -> ValidationResult: violations = [] status = ValidationResult.OK for d in dataset.documents(): console.print(f"Validating {d.name}.") try: self.schema.assertValid(d.tree) except etree.DocumentInvalid: status = ValidationResult.ERROR errors = self.schema.error_log # type: ignore violations += [Violation.from_log_entry(e) for e in errors] except etree.XMLSyntaxError as exc: status = ValidationResult.ERROR violations.append(Violation.from_syntax_error(exc)) return ValidationResult(status=status, violations=violations)
def siri2(): filepath = DATA_DIR / "sirivm2good.xml" return DataSet(filepath)
def netex(): filepath = DATA_DIR / "netex1good.xml" return DataSet(filepath)
def txc21_archive(): filepath = DATA_DIR.joinpath("txc21archive.zip") return DataSet(filepath)
def txc24invalid(): filepath = DATA_DIR / "txc24bad.xml" return DataSet(filepath)
def txc24(): filepath = DATA_DIR / "txc24good.xml" return DataSet(filepath)