Skip to content

Commit

Permalink
add unidentified table error
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-troy committed Feb 7, 2024
1 parent f320775 commit 06b71a5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
4 changes: 3 additions & 1 deletion liiatools/common/stream_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ def add_table_name(event, schema: DataSchema):
event, table_name=table_name, table_spec=schema.column_map[table_name]
)
else:
return event
return EventErrors.add_to_event(
event, type="UnidentifiedTable", message=f"Failed to identify table based on headers"
)


@streamfilter(check=type_check(events.Cell), fail_function=pass_event)
Expand Down
48 changes: 38 additions & 10 deletions tests/common/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,52 @@ def get_table_name(headers):
stream = [events.StartTable(headers=headers)]
stream = stream_filters.add_table_name(stream, schema=schema)
event = list(stream)[0]
return getattr(event, "table_name", None)
table_name = getattr(event, "table_name", None)
errors = getattr(event, "errors", None)
return {"table_name": table_name, "errors": errors}

assert (
get_table_name(["CHILD", "SEX", "DOB", "ETHNIC", "UPN", "MOTHER", "MC_DOB"])
get_table_name(["CHILD", "SEX", "DOB", "ETHNIC", "UPN", "MOTHER", "MC_DOB"])[
"table_name"
]
== "Header"
)

for table_name, table_data in schema.table.items():
headers = list(table_data.keys())
assert get_table_name(headers) == table_name

assert get_table_name(["incorrect", "header", "values"]) is None
assert get_table_name(headers)["table_name"] == table_name

assert get_table_name(["incorrect", "header", "values"])["table_name"] is None
assert list(get_table_name(["incorrect", "header", "values"])["errors"]) == [
{
"message": "Failed to identify table based on headers",
"type": "UnidentifiedTable",
}
]

assert get_table_name([""]) is None
assert get_table_name([""])["table_name"] is None
assert list(get_table_name(["incorrect", "header", "values"])["errors"]) == [
{
"message": "Failed to identify table based on headers",
"type": "UnidentifiedTable",
}
]

assert get_table_name([]) is None
assert get_table_name([])["table_name"] is None
assert list(get_table_name(["incorrect", "header", "values"])["errors"]) == [
{
"message": "Failed to identify table based on headers",
"type": "UnidentifiedTable",
}
]

assert get_table_name(None) is None
assert get_table_name(None)["table_name"] is None
assert list(get_table_name(["incorrect", "header", "values"])["errors"]) == [
{
"message": "Failed to identify table based on headers",
"type": "UnidentifiedTable",
}
]

schema = annex_a_schema()

Expand All @@ -105,7 +133,7 @@ def get_table_name(headers):
"Date of Contact",
"Contact Source",
]
)
)["table_name"]
== "List 1"
)

Expand All @@ -121,7 +149,7 @@ def get_table_name(headers):
"Date of Contact",
"Contact Source",
]
)
)["table_name"]
== "List 1"
)

Expand Down

0 comments on commit 06b71a5

Please sign in to comment.