Skip to content

Commit

Permalink
Make black and ruff happy
Browse files Browse the repository at this point in the history
  • Loading branch information
hkeeler committed Nov 7, 2023
1 parent 253f815 commit 18ff0d1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
1 change: 1 addition & 0 deletions regtech_data_validator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,6 @@ def validate(
# returned values are only used in unit tests
return is_valid, findings_df


if __name__ == '__main__':
app()
52 changes: 29 additions & 23 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@


class TestParseKeyValue:

def test_parse_success(self):
test_str = "fruit=apple"
key_val: cli.KeyValueOpt = cli.parse_key_value(test_str)

assert key_val.key == 'fruit'
assert key_val.value == 'apple'


def test_parse_fail_wrong_delimiter(self):
test_str = "fruit:apple"

Expand All @@ -44,14 +42,28 @@ def test_parse_fail_multiple_delimiters(self):


class TestOutputFormat:

# TODO: Figure out why uid.duplicates_in_dataset returns different findings for matched records
input_df = pd.DataFrame(
data=[
(1, 'uid', '12345678901234567890', 'error', 'E3000', 'uid.duplicates_in_dataset', "Any 'unique identifier' may not be used in mor..."),
(2, 'uid', '12345678901234567890', 'error', 'E3000', 'uid.duplicates_in_dataset', "Any 'unique identifier' may not be used in mor...")
{
'record_no': 1,
'field_name': 'uid',
'field_value': '12345678901234567890',
'validation_severity': 'error',
'validation_id': 'E3000',
'validation_name': 'uid.duplicates_in_dataset',
'validation_desc': "Any 'unique identifier' may not be used in mor...",
},
{
'record_no': 2,
'field_name': 'uid',
'field_value': '12345678901234567890',
'validation_severity': 'error',
'validation_id': 'E3000',
'validation_name': 'uid.duplicates_in_dataset',
'validation_desc': "Any 'unique identifier' may not be used in mor...",
},
],
columns=['record_no', 'field_name', 'field_value', 'validation_severity', 'validation_id', 'validation_name', 'validation_desc'],
)
input_df.index.name = 'finding_no'
input_df.index += 1
Expand All @@ -62,13 +74,12 @@ def test_output_pandas(self):
finding_no
1 1 uid 12345678901234567890 error E3000 uid.duplicates_in_dataset Any 'unique identifier' may not be used in mor...
2 2 uid 12345678901234567890 error E3000 uid.duplicates_in_dataset Any 'unique identifier' may not be used in mor...
""").strip('\n')
""").strip('\n') # noqa: E501

actual_output = cli.df_to_str(self.input_df)

assert actual_output == expected_output


def test_output_table(self):
expected_output = dedent("""
╭──────────────┬─────────────┬──────────────┬──────────────────────┬───────────────────────┬─────────────────┬───────────────────────────╮
Expand All @@ -77,26 +88,24 @@ def test_output_table(self):
│ 1 │ 1 │ uid │ 12345678901234567890 │ error │ E3000 │ uid.duplicates_in_dataset │
│ 2 │ 2 │ uid │ 12345678901234567890 │ error │ E3000 │ uid.duplicates_in_dataset │
╰──────────────┴─────────────┴──────────────┴──────────────────────┴───────────────────────┴─────────────────┴───────────────────────────╯
""").strip('\n')
""").strip('\n') # noqa: E501

actual_output = cli.df_to_table(self.input_df)

assert actual_output == expected_output


def test_output_csv(self):
expected_output = dedent("""
finding_no,record_no,field_name,field_value,validation_severity,validation_id,validation_name,validation_desc
1,1,uid,12345678901234567890,error,E3000,uid.duplicates_in_dataset,Any 'unique identifier' may not be used in mor...
2,2,uid,12345678901234567890,error,E3000,uid.duplicates_in_dataset,Any 'unique identifier' may not be used in mor...
""").strip('\n')
""").strip('\n') # noqa: E501

actual_output = cli.df_to_csv(self.input_df)

assert actual_output.strip('\n') == expected_output


def test_output_csv(self):
def test_output_json(self):
expected_output = dedent("""
[
{
Expand Down Expand Up @@ -136,15 +145,13 @@ def test_output_csv(self):


class TestDescribeCommand:

def test_defaults(self):
cli.describe()
cli.describe()


class TestValidateCommand:

valid_lei_context = cli.KeyValueOpt('lei','000TESTFIUIDDONOTUSE')
invalid_lei_context = cli.KeyValueOpt('lei','XXXXXXXXXXXXXXXXXXXX')
valid_lei_context = cli.KeyValueOpt('lei', '000TESTFIUIDDONOTUSE')
invalid_lei_context = cli.KeyValueOpt('lei', 'XXXXXXXXXXXXXXXXXXXX')

pass_path = Path(pass_file)
fail_path = Path(fail_file)
Expand Down Expand Up @@ -185,30 +192,29 @@ def test_fail_file_table_output(self):
assert not is_valid



class TestDescribeCli:
"""
Test `describe` command with Typer's CLI test runner
"""

def test_defaults(self):
result = cli_runner.invoke(cli.app, ['describe'])

assert result.exit_code == 0
assert result.stdout == 'Feature coming soon...\n'



class TestValidateCli:
"""
Test `validate` command with Typer's CLI test runner
"""

def test_pass_file_defaults(self):
result = cli_runner.invoke(cli.app, ['validate', pass_file])

assert result.exit_code == 0
assert result.stdout == ''


def test_fail_file_output_arg_value(self):
result = cli_runner.invoke(cli.app, ['validate', pass_file, '--output', 'pdf'])

Expand Down

0 comments on commit 18ff0d1

Please sign in to comment.