예제 #1
0
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()
예제 #2
0
    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)
예제 #3
0
def siri2():
    filepath = DATA_DIR / "sirivm2good.xml"
    return DataSet(filepath)
예제 #4
0
def netex():
    filepath = DATA_DIR / "netex1good.xml"
    return DataSet(filepath)
예제 #5
0
def txc21_archive():
    filepath = DATA_DIR.joinpath("txc21archive.zip")
    return DataSet(filepath)
예제 #6
0
def txc24invalid():
    filepath = DATA_DIR / "txc24bad.xml"
    return DataSet(filepath)
예제 #7
0
def txc24():
    filepath = DATA_DIR / "txc24good.xml"
    return DataSet(filepath)