Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/pip-48da786093
Browse files Browse the repository at this point in the history
  • Loading branch information
jcadam14 authored Jun 18, 2024
2 parents b9ec1c5 + 1b08fe6 commit 6397a8f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
1 change: 0 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions src/regtech_data_validator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,8 @@ def validate(
status = 'FAILURE'
findings_df = validation_results.findings
no_of_findings = len(findings_df.index.unique())
total_errors = sum(
[
validation_results.error_counts.total_count,
validation_results.warning_counts.total_count,
]
)
warning_count = validation_results.warning_counts.total_count
error_count = validation_results.error_counts.total_count

match output:
case OutputFormat.PANDAS:
Expand All @@ -113,7 +109,7 @@ def validate(
case OutputFormat.TABLE:
print(df_to_table(findings_df))
case OutputFormat.DOWNLOAD:
print(df_to_download(findings_df, total_errors))
print(df_to_download(findings_df, warning_count, error_count))
case _:
raise ValueError(f'output format "{output}" not supported')

Expand Down
12 changes: 10 additions & 2 deletions src/regtech_data_validator/data_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def find_check(group_name, checks):
return next(gen)


def df_to_download(df: pd.DataFrame, total_errors: int, max_errors: int = 1000000) -> str:
def df_to_download(df: pd.DataFrame, warning_count: int = 0, error_count: int = 0, max_errors: int = 1000000) -> str:
header = "validation_type,validation_id,validation_name,row,unique_identifier,fig_link,validation_description,"
if df.empty:
# return headers of csv for 'emtpy' report
Expand Down Expand Up @@ -106,8 +106,16 @@ def df_to_download(df: pd.DataFrame, total_errors: int, max_errors: int = 100000
field_headers.append(f"value_{i+1}")
header += ",".join(field_headers) + "\n"

total_errors = warning_count + error_count
error_type = "errors"
if warning_count > 0:
if error_count > 0:
error_type = "errors and warnings"
else:
error_type = "warnings"

if total_errors and total_errors > max_errors:
header += f"The submission contained {total_errors}, but only {max_errors} will be displayed in the download report. Fix the current errors and resubmit to see more.\n"
header += f"Your register contains {total_errors} {error_type}, however, only {max_errors} records are displayed in this report. To see additional {error_type}, correct the listed records, and upload a new file.\n"

csv_data = header + total_csv
return csv_data
Expand Down
8 changes: 4 additions & 4 deletions tests/test_output_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ def test_download_csv(self):
","uid","12345678901234567890"
"""
).strip('\n')
actual_output = df_to_download(self.input_df, 2)
actual_output = df_to_download(self.input_df, error_count=2)
assert actual_output.strip() == expected_output

def test_download_max_message_csv(self):
expected_output = dedent(
"""
validation_type,validation_id,validation_name,row,unique_identifier,fig_link,validation_description,field_1,value_1,field_2,value_2
The submission contained 5, but only 3 will be displayed in the download report. Fix the current errors and resubmit to see more.
Your register contains 6 errors and warnings, however, only 3 records are displayed in this report. To see additional errors and warnings, correct the listed records, and upload a new file.
"Error","E2008","amount_approved.conditional_field_conflict",4,"12345678901234567891","https://www.consumerfinance.gov/data-research/small-business-lending/filing-instructions-guide/2024-guide/#4.2.7","* When 'action taken' does **not** equal 1 (originated) or
2 (approved but not accepted), 'amount approved or originated' must be blank.
* When 'action taken' equals 1 or 2, 'amount approved or originated' must **not** be blank.
Expand All @@ -275,7 +275,7 @@ def test_download_max_message_csv(self):
","uid","12345678901234567890"
"""
).strip('\n')
actual_output = df_to_download(self.input_df, 5, 3)
actual_output = df_to_download(self.input_df, warning_count=1, error_count=5, max_errors=3)
assert actual_output.strip() == expected_output

def test_empty_download_csv(self):
Expand All @@ -284,5 +284,5 @@ def test_empty_download_csv(self):
validation_type,validation_id,validation_name,row,unique_identifier,fig_link,validation_description,
"""
).strip('\n')
actual_output = df_to_download(pd.DataFrame(), 0)
actual_output = df_to_download(pd.DataFrame(), warning_count=0, error_count=0)
assert actual_output == expected_output

0 comments on commit 6397a8f

Please sign in to comment.