Skip to content

Commit

Permalink
feat: Allow user to specify a format for stdout, files reformatted wi…
Browse files Browse the repository at this point in the history
…th black version 19 (#242)
  • Loading branch information
Yogesh Tewari committed Aug 2, 2021
1 parent bb5f91e commit 4522073
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion data_validation/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def build_config_managers_from_args(args):
result_handler_config=result_handler_config,
filter_config=filter_config,
verbose=args.verbose,
format=args.format
format=args.format,
)
configs.append(build_config_from_args(args, config_manager))

Expand Down
6 changes: 4 additions & 2 deletions data_validation/result_handlers/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ def print_formatted_(format, result_df):
elif format == "table":
print(result_df.to_markdown(tablefmt="fancy_grid"))
else:
error_msg = f"format [{format}] not supported, results printed in default(table) mode. " \
f"Supported formats are [text, csv, json, table]"
error_msg = (
f"format [{format}] not supported, results printed in default(table) mode. "
f"Supported formats are [text, csv, json, table]"
)
print(result_df.to_markdown(tablefmt="fancy_grid"))
raise ValueError(error_msg)

Expand Down
19 changes: 14 additions & 5 deletions tests/system/data_sources/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@


def test_count_validator():
validator = data_validation.DataValidation(CONFIG_COUNT_VALID, format="text", verbose=True)
validator = data_validation.DataValidation(
CONFIG_COUNT_VALID, format="text", verbose=True
)
df = validator.execute()

count_value = df[df["validation_name"] == "count"]["source_agg_value"].values[0]
Expand All @@ -202,12 +204,15 @@ def test_count_validator():
assert float(max_birth_year_value) > 0
assert float(min_birth_year_value) > 0
assert (
df["source_agg_value"].astype(float).sum() == df["target_agg_value"].astype(float).sum()
df["source_agg_value"].astype(float).sum()
== df["target_agg_value"].astype(float).sum()
)


def test_grouped_count_validator():
validator = data_validation.DataValidation(CONFIG_GROUPED_COUNT_VALID, format="csv", verbose=True)
validator = data_validation.DataValidation(
CONFIG_GROUPED_COUNT_VALID, format="csv", verbose=True
)
df = validator.execute()
rows = list(df[df["validation_name"] == "count"].iterrows())

Expand All @@ -223,7 +228,9 @@ def test_grouped_count_validator():


def test_numeric_types():
validator = data_validation.DataValidation(CONFIG_NUMERIC_AGG_VALID, format="json", verbose=True)
validator = data_validation.DataValidation(
CONFIG_NUMERIC_AGG_VALID, format="json", verbose=True
)
df = validator.execute()

for validation in df.to_dict(orient="records"):
Expand Down Expand Up @@ -282,7 +289,9 @@ def _remove_bq_conn():

def test_unsupported_result_format():
with pytest.raises(ValueError):
validator = data_validation.DataValidation(CONFIG_GROUPED_COUNT_VALID, format="foobar", verbose=True)
validator = data_validation.DataValidation(
CONFIG_GROUPED_COUNT_VALID, format="foobar", verbose=True
)
df = validator.execute()
rows = list(df[df["validation_name"] == "count"].iterrows())
assert len(rows) > 1

0 comments on commit 4522073

Please sign in to comment.