Skip to content

test(variables): cover Literal equality and NotImplemented semantics - #763

Open
janmejai2002 wants to merge 1 commit into
theskumar:mainfrom
janmejai2002:test-gap/literal-equality
Open

janmejai2002 wants to merge 1 commit into
theskumar:mainfrom
janmejai2002:test-gap/literal-equality

Conversation

@janmejai2002

Copy link
Copy Markdown

Summary

Add unit tests in tests/test_variables.py covering Literal equality semantics: negative equality between distinct values, cross-type comparison, the NotImplemented protocol, and hash/equality consistency.

What was uncovered

Literal.__eq__ returns NotImplemented for non-Literal operands and compares self.value == other.value for Literal operands. Existing tests only compare parsed variables in the positive case, so a regression that makes distinct literals compare equal (for example, returning a truthy non-boolean) or drops the NotImplemented protocol leaves the suite green.

Changes

  • tests/test_variables.py: added test_literal_equality, asserting:
    • Literal("a") == Literal("a")
    • Literal("a") != Literal("b") and (Literal("a") == Literal("b")) is False
    • Literal("a") != "a"
    • Literal("a").__eq__(object()) is NotImplemented
    • set dedupe across equal and unequal literals
  • No production code changed.

Verification

  • python -m pytest tests/test_variables.py -k test_literal_equality -q -> 1 passed, 6 deselected
  • Full suite: python -m pytest -q -> 240 passed, 50 skipped
  • The new assertions fail if __eq__ is mutated to return a truthy non-boolean or to drop NotImplemented.

Detected with cordis-verify

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant