예제 #1
0
def test_complex_replacement():
    os.environ['MY_LAPTOP_NAME'] = 'laptop'
    os.environ['MY_LAPTOP_PRICE'] = '1000'
    os.environ['MY_IS_LAPTOP_SOLD'] = 'true'

    assert load(open('./tests/test_complex_replacement.toml')
                ) == MORE_COMPLEX_OUTPUT  # noqa
예제 #2
0
def run(config, verbose):
    """Validator of data that is queriable via SQL."""
    cfg = load(config)

    engine = db.create_engine(cfg['general']['sqla'])
    db_name = cfg['general']['db_name']

    validator_module = import_module('.validators', package='sqvid')

    n_failed = 0

    for table in cfg[db_name]:
        for column in cfg[db_name][table]:
            for val in cfg[db_name][table][column]:
                validator_name = val['validator']
                args = val.get('args')
                custom_column = val.get('custom_column')

                validator_fn = getattr(validator_module, validator_name)
                r, k, q = execute_validation(engine,
                                             table,
                                             column,
                                             validator_fn,
                                             args,
                                             custom_column=custom_column)

                col_names = val.get('report_columns', k)

                if custom_column:
                    column = "{} (customized as '{}')".format(
                        column, custom_column)

                if verbose:
                    print(QUERY_VERBOSE_STR.format(q))

                if len(r) == 0:
                    print("PASSED: Validation on [{}] {}.{} of {}{}".format(
                        db_name, table, column, validator_name,
                        '({})'.format(args) if args else ''))
                else:
                    print("FAILED: Validation on [{}] {}.{} of {}{}".format(
                        db_name,
                        table,
                        column,
                        validator_name,
                        '({})'.format(args) if args else '',
                    ))
                    print("Offending {} rows:".format(len(r)))
                    print(NiceTable(list(map(dict, r)), col_names=col_names))
                    n_failed += 1

    if n_failed > 0:
        sys.exit(1)
    else:
        sys.exit(0)
예제 #3
0
def load_directory(dir_path: Path):
    all_vars = dict()

    for var_file in dir_path.glob("*.toml"):
        all_vars.update(envtoml.load(var_file.open()))

    globs = (dir_path.glob(f"*.{ext}") for ext in ("json", "yml", "yaml"))

    for var_file in chain.from_iterable(globs):
        all_vars.update(envyaml.EnvYAML(str(var_file)))

    return all_vars
예제 #4
0
def test_load_with_replace():
    os.environ['MY_CONFIG_VAR'] = "10"
    assert load(open('./tests/test_simple_replacement.toml')) == SIMPLE_OUTPUT
예제 #5
0
def test_load():
    assert load(open('./tests/test_simple.toml')) == SIMPLE_OUTPUT
    assert load(open('./tests/test_complex.toml')) == MORE_COMPLEX_OUTPUT
예제 #6
0
import envtoml

cfg = envtoml.load(open("config.toml"))
예제 #7
0
 def resolve_env(
     files: typing.Iterable[pathlib.Path],
 ) -> typing.Generator[typing.Dict[str, typing.Any], None, None]:
     for file in files:
         yield envtoml.load(file)