Skip to content

Commit d656bcf

Browse files
committed
eli-579 updating tests to use hamcrest
1 parent d47a14c commit d656bcf

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

poetry.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/unit/services/processors/test_token_parser_functions.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from dataclasses import dataclass
44

55
import pytest
6+
from hamcrest import assert_that, calling, equal_to, is_, none, raises
67

78
from eligibility_signposting_api.services.processors.token_parser import TokenParser
89

@@ -61,26 +62,26 @@ def test_parse_tokens_with_functions(self, token: str, expected: ExpectedTokenRe
6162
"""Test parsing tokens with function calls."""
6263
parsed_token = TokenParser.parse(token)
6364

64-
assert parsed_token.attribute_level == expected.level
65-
assert parsed_token.attribute_name == expected.name
66-
assert parsed_token.attribute_value == expected.value
67-
assert parsed_token.function_name == expected.function
68-
assert parsed_token.function_args == expected.args
69-
assert parsed_token.format == expected.date_format
65+
assert_that(parsed_token.attribute_level, is_(equal_to(expected.level)))
66+
assert_that(parsed_token.attribute_name, is_(equal_to(expected.name)))
67+
assert_that(parsed_token.attribute_value, is_(equal_to(expected.value)))
68+
assert_that(parsed_token.function_name, is_(equal_to(expected.function)))
69+
assert_that(parsed_token.function_args, is_(equal_to(expected.args)))
70+
assert_that(parsed_token.format, is_(equal_to(expected.date_format)))
7071

7172
def test_parse_without_function_has_none_function_fields(self):
7273
"""Test that tokens without functions have None for function fields."""
7374
parsed = TokenParser.parse("[[TARGET.COVID.LAST_SUCCESSFUL_DATE]]")
7475

75-
assert parsed.function_name is None
76-
assert parsed.function_args is None
76+
assert_that(parsed.function_name, is_(none()))
77+
assert_that(parsed.function_args, is_(none()))
7778

7879
def test_parse_date_format_not_treated_as_function(self):
7980
"""Test that DATE format is not treated as a derived function."""
8081
parsed = TokenParser.parse("[[PERSON.DATE_OF_BIRTH:DATE(%d %B %Y)]]")
8182

82-
assert parsed.function_name is None
83-
assert parsed.format == "%d %B %Y"
83+
assert_that(parsed.function_name, is_(none()))
84+
assert_that(parsed.format, is_(equal_to("%d %B %Y")))
8485

8586
@pytest.mark.parametrize(
8687
"token",
@@ -92,5 +93,4 @@ def test_parse_date_format_not_treated_as_function(self):
9293
)
9394
def test_parse_invalid_function_format_raises_error(self, token):
9495
"""Test that malformed function calls raise errors."""
95-
with pytest.raises(ValueError, match="Invalid token format"):
96-
TokenParser.parse(token)
96+
assert_that(calling(TokenParser.parse).with_args(token), raises(ValueError, "Invalid token format"))

0 commit comments

Comments
 (0)