How to use the routemaster.validation.ValidationError function in routemaster

To help you get started, we’ve selected a few routemaster examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thread / routemaster / routemaster / cli.py View on Github external
def _validate_config(app: App):
    try:
        validate_config(app, app.config)
    except ValidationError as e:
        msg = f"Validation Error: {e}"
        logger.exception(msg)
        click.get_current_context().exit(1)
github thread / routemaster / routemaster / validation.py View on Github external
def _validate_unique_state_names(state_machine):
    state_name_counts = collections.Counter([
        x.name for x in state_machine.states
    ])

    invalid_states = [x for x, y in state_name_counts.items() if y > 1]

    if invalid_states:
        raise ValidationError(
            f"States {invalid_states!r} are not unique in "
            f"{state_machine.name}",
github thread / routemaster / routemaster / validation.py View on Github external
def _validate_all_states_exist(state_machine):
    state_names = set(x.name for x in state_machine.states)
    for state in state_machine.states:
        for destination_name in state.next_states.all_destinations():
            if destination_name not in state_names:
                raise ValidationError(f"{destination_name} does not exist")
github thread / routemaster / routemaster / validation.py View on Github external
label_state_machine=state_machine.name,
    ).subquery()

    invalid_labels_and_states = app.session.query(
        states_by_rank.c.label_name,
        states_by_rank.c.new_state,
    ).filter(
        states_by_rank.c.rank == 1,
        ~(
            states_by_rank.c.new_state.in_(states) |
            states_by_rank.c.new_state.is_(None)
        ),
    ).all()

    if invalid_labels_and_states:
        raise ValidationError(
            f"{len(invalid_labels_and_states)} nodes in states that no "
            f"longer exist",
github thread / routemaster / routemaster / validation.py View on Github external
def _validate_route_start_to_end(state_machine):
    graph = _build_graph(state_machine)
    if not networkx.is_connected(graph):
        raise ValidationError("Graph is not fully connected")