Skip to content

Commit cfedda4

Browse files
committed
Add Given/When/Then comments to identity-jsonpath unit tests
1 parent dd02fdc commit cfedda4

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

tests/test_translator_unit.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,8 @@ def test_translate_segment__percentage_split_trait_not_in_context__compiles_to_f
555555

556556

557557
def test_translate_segment__is_set_on_identity_identifier__emits_true() -> None:
558+
# Given an IS_SET on $.identity.identifier — every IDENTITIES row IS an
559+
# identity, so the predicate is unconditionally true
558560
seg = {
559561
"key": "j1",
560562
"name": "s",
@@ -567,10 +569,13 @@ def test_translate_segment__is_set_on_identity_identifier__emits_true() -> None:
567569
}
568570
],
569571
}
572+
573+
# When / Then the predicate collapses to TRUE
570574
assert translate_segment(seg, _ctx()) == "((TRUE))"
571575

572576

573577
def test_translate_segment__is_not_set_on_identity_key__emits_false() -> None:
578+
# Given an IS_NOT_SET on $.identity.key — same as above, inverted
574579
seg = {
575580
"key": "j2",
576581
"name": "s",
@@ -583,10 +588,13 @@ def test_translate_segment__is_not_set_on_identity_key__emits_false() -> None:
583588
}
584589
],
585590
}
591+
592+
# When / Then the predicate collapses to FALSE
586593
assert translate_segment(seg, _ctx()) == "((FALSE))"
587594

588595

589596
def test_translate_segment__not_equal_on_identity_identifier__emits_inequality() -> None:
597+
# Given a NOT_EQUAL against the identifier column
590598
seg = {
591599
"key": "j3",
592600
"name": "s",
@@ -599,12 +607,17 @@ def test_translate_segment__not_equal_on_identity_identifier__emits_inequality()
599607
}
600608
],
601609
}
610+
611+
# When translated
602612
sql = translate_segment(seg, _ctx())
613+
614+
# Then the predicate is a direct column inequality compare
603615
assert sql is not None
604616
assert "i.identifier <> 'ada'" in sql
605617

606618

607619
def test_translate_segment__contains_on_identity_identifier__uses_position() -> None:
620+
# Given a CONTAINS on the identifier column
608621
seg = {
609622
"key": "j4",
610623
"name": "s",
@@ -617,12 +630,17 @@ def test_translate_segment__contains_on_identity_identifier__uses_position() ->
617630
}
618631
],
619632
}
633+
634+
# When translated
620635
sql = translate_segment(seg, _ctx())
636+
637+
# Then the predicate uses POSITION on the identifier column
621638
assert sql is not None
622639
assert "POSITION('@', i.identifier) > 0" in sql
623640

624641

625642
def test_translate_segment__not_contains_on_identity_identifier__inverts_position() -> None:
643+
# Given a NOT_CONTAINS on the identifier column
626644
seg = {
627645
"key": "j5",
628646
"name": "s",
@@ -635,7 +653,11 @@ def test_translate_segment__not_contains_on_identity_identifier__inverts_positio
635653
}
636654
],
637655
}
656+
657+
# When translated
638658
sql = translate_segment(seg, _ctx())
659+
660+
# Then the predicate is the inverse of POSITION, with a not-null guard
639661
assert sql is not None
640662
assert "IS NOT NULL AND NOT" in sql
641663
assert "POSITION('@', i.identifier) > 0" in sql
@@ -687,6 +709,7 @@ def test_translate_segment__rule_with_untranslatable_nested_rule__returns_none()
687709

688710

689711
def test_translate_segment__none_rule_type__inverts_predicate() -> None:
712+
# Given a NONE rule (matches when no condition matches)
690713
seg = {
691714
"key": "r3",
692715
"name": "s",
@@ -697,7 +720,11 @@ def test_translate_segment__none_rule_type__inverts_predicate() -> None:
697720
}
698721
],
699722
}
723+
724+
# When translated
700725
sql = translate_segment(seg, _ctx())
726+
727+
# Then the rule is wrapped in a NOT
701728
assert sql is not None
702729
assert sql.startswith("(NOT (") or "NOT (" in sql
703730

@@ -718,6 +745,9 @@ def test_translate_segment__unknown_rule_type__raises() -> None:
718745
}
719746
],
720747
}
748+
749+
# When translation is attempted
750+
# Then the assert fires loudly rather than returning a wrong-but-quiet answer
721751
with pytest.raises(AssertionError):
722752
translate_segment(seg, _ctx())
723753

0 commit comments

Comments
 (0)