Beispiel #1
0
def test_serializing_config(config: Config):
    work_dir = mkdtemp()
    path = Path(work_dir) / "olivertwist.yml"

    ConfigIO.write(config, path)

    assert ConfigIO.read(path) == ConfigIO.read(PATH_TO_VALID_CONFIG)
Beispiel #2
0
def config(config_path):
    """Interactively create or edit configuration file"""
    config_path = Path(config_path or ConfigIO.DEFAULT_CONFIG_FILE_PATH)
    logging.debug(config_path)
    try:
        config_obj = ConfigIO.read(config_path)
    except FileNotFoundError:
        config_obj = Config.empty()

    config_obj = Configurator.update(config_obj)
    ConfigIO.write(config_obj, config_path)
    click.echo(f"Created/updated config in {config_path}")
Beispiel #3
0
def test_config_with_config_file_existing(_):
    runner = CliRunner()
    config_path = "twisted.yml"
    dummy_rule_config = RuleConfig("a", enabled=False)
    with runner.isolated_filesystem():
        ConfigIO.write(Config(universal=[dummy_rule_config]), config_path)

        result = runner.invoke(main, ["config", "--config=twisted.yml"])

        assert result.exit_code == 0
        assert result.output == f"Created/updated config in {config_path}\n"
        assert (ConfigIO.read(config_path) == Config.empty()
                ), "existing config not overwritten"
Beispiel #4
0
def check(input, config, add_rules_paths, html=True, browser=False):
    """Check dbt DAG against configured rules."""
    config = ConfigIO.read(config)
    manifest = Manifest(json.load(input))
    rule_engine = RuleEngine.with_configured_rules(config)
    for rule_path in add_rules_paths:
        rule_engine.extend(RuleEngine.with_configured_rules(config, rule_path))

    results = rule_engine.run(manifest)
    report_to_terminal(results)
    metric_results = MetricEngine().run(manifest)
    report = to_html_report(results, metric_results)
    oliver_twist = json.loads(MyEncoder().encode(report))
    output_json(oliver_twist)
    if html or browser:
        logger.debug("Generating HTML report...")
        render_html_report(oliver_twist)
        if browser:
            webbrowser.open(f"file://{os.getcwd()}/target/index.html")

    exit_message(results)
Beispiel #5
0
def test_parsing_missing_config_file():
    path_to_non_existent_config = Path() / "non_existent_config.yml"
    with pytest.raises(FileNotFoundError):
        ConfigIO.read(path_to_non_existent_config)
Beispiel #6
0
def test_parsing_config_with_duplicates_raises_error():
    with pytest.raises(InvalidConfigError):
        ConfigIO.read(PATH_TO_DUPLICATE_CONFIG)
Beispiel #7
0
def test_parsing_config_with_no_version_raises_error():
    with pytest.raises(InvalidConfigError):
        ConfigIO.read(PATH_TO_NO_VERSION_CONFIG)
Beispiel #8
0
def test_parsing_invalid_config():
    with pytest.raises(InvalidConfigError):
        ConfigIO.read(PATH_TO_INVALID_CONFIG)
Beispiel #9
0
def test_getting_disabled_rule_ids_from_config():
    config = ConfigIO.read(PATH_TO_VALID_CONFIG)

    assert config.get_disabled_rule_ids() == ["no-rejoin-models"]
Beispiel #10
0
def test_parsing_valid_config(config: Config):
    parsed_config = ConfigIO.read(PATH_TO_VALID_CONFIG)

    assert parsed_config == config