Skip to content

Commit

Permalink
[#137] Add a test for the potential_matches.sql template itself
Browse files Browse the repository at this point in the history
  • Loading branch information
riley-harper committed Jun 5, 2024
1 parent e7e6225 commit d2430e9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions hlink/tests/matching_potential_matches_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# in this project's top-level directory, and also on-line at:
# https://github.com/ipums/hlink

from jinja2 import Environment, PackageLoader
import pytest


Expand Down Expand Up @@ -87,3 +88,35 @@ def test_step_4_aggregate_features(
)["exact_all_mult2"].iloc[0]
== 9
)


def test_potential_matches_sql_template() -> None:
loader = PackageLoader("hlink.linking.matching")
jinja_env = Environment(loader=loader)
template = jinja_env.get_template("potential_matches.sql")
context = {
"dataset_columns": ["AGE", "SEX"],
"feature_columns": [],
"blocking_columns": ["AGE_3", "SEX"],
}
query = template.render(context).strip()
query_lines = query.splitlines()
query_lines_clean = [line.strip() for line in query_lines]

assert query_lines_clean == [
"SELECT DISTINCT",
"",
"a.AGE as AGE_a",
",b.AGE as AGE_b",
"",
",a.SEX as SEX_a",
",b.SEX as SEX_b",
"",
"",
"FROM exploded_df_a a",
"JOIN exploded_df_b b ON",
"",
"a.AGE_3 = b.AGE_3 AND",
"",
"a.SEX = b.SEX",
]

0 comments on commit d2430e9

Please sign in to comment.