Skip to content

Commit 3e9dfd0

Browse files
committed
Add test cases to get coverage to 100%
1 parent 9569e76 commit 3e9dfd0

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎pyproject.toml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ build-backend = "hatchling.build"
5757
[tool.hatch.build.targets.wheel]
5858
packages = ["src/celpy"]
5959

60+
# Attempts to get re2 to build for Python 3.15.
61+
[tool.hatch.envs.hatch-build.env-vars]
62+
# Need to set the Extension.include_dirs values for build_ext command inside bdist_wheel command.
63+
# These don't seem to work.
64+
GCC_INCLUDE_DIR = "/opt/local/include"
65+
HEADER_SEARCH_PATHS = "/opt/local/include"
66+
6067
[tool.uv]
6168
required-version = ">=0.7"
6269

@@ -88,6 +95,7 @@ dev = [
8895
"ipykernel>=7.2.0",
8996
]
9097

98+
# Python 3.15 support depends on Google RE2 offering pre-built binaries for MacOS.
9199
[tool.tox]
92100
envlist = ["py310", "py311", "py312", "py313", "py314", "lint", "tools"]
93101
minversion = "4.24.0"

‎src/celpy/celtypes.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ def __new__(
13751375
re.finditer(rf"([0-9]*(\.[0-9]*)?)({units_pattern})", seconds),
13761376
)
13771377
)
1378-
except KeyError:
1378+
except KeyError: # pragma: no cover
13791379
raise ValueError(f"Invalid duration {seconds!r}")
13801380

13811381
if not (cls.MinSeconds <= seconds <= cls.MaxSeconds):

‎tests/test_celtypes.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ def test_bool_type():
3131
t, f = BoolType(True), BoolType(False)
3232
exc = CELEvalError(("summary", "details"))
3333

34+
assert all(BoolType(s) == t for s in ("True", "true", "TRUE", "t"))
35+
assert all(BoolType(s) == f for s in ("False", "false", "FALSE", "f"))
36+
assert BoolType("1") == t
37+
assert BoolType("0") == f
38+
3439
assert logical_condition(t, sentinel.true, sentinel.false) == sentinel.true
3540
assert logical_condition(f, sentinel.true, sentinel.false) == sentinel.false
3641
with pytest.raises(TypeError):
@@ -62,6 +67,7 @@ def test_bool_type():
6267
assert logical_not(f) == t
6368
with pytest.raises(TypeError):
6469
logical_not(StringType("nope"))
70+
assert logical_not(exc) == exc
6571

6672
assert repr(f) == "BoolType(False)"
6773
assert repr(t) == "BoolType(True)"
@@ -211,10 +217,12 @@ def test_list_type():
211217
[IntType(42), StringType("2.718281828459045**1.791759469228055"), IntType(7)]
212218
)
213219
assert l_1 == l_1
220+
assert not l_1 == None
214221
with pytest.raises(TypeError):
215222
assert l_1 != l_2
216223
with pytest.raises(TypeError):
217224
assert not l_1 == l_2
225+
218226
assert repr(l_1) == "ListType([IntType(42), IntType(6), IntType(7)])"
219227
with pytest.raises(TypeError):
220228
l_1 < l_2
@@ -264,6 +272,7 @@ def test_map_type():
264272
)
265273
assert m_1 == m_1
266274
assert m_1 == m_3
275+
assert not m_1 == None
267276
assert not m_1 != m_1
268277
assert not m_single != m_single
269278
with pytest.raises(TypeError):

‎tests/test_evaluation.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ def mock_operation(a, b):
157157
result_3 = mock_operation(sentinel.not_implemented, sentinel.b)
158158
assert result_3 == NotImplemented
159159

160+
eval_error = CELEvalError()
161+
assert mock_operation(eval_error, True) == eval_error
162+
assert mock_operation(True, eval_error) == eval_error
163+
160164

161165
def test_operator_in():
162166
"""
@@ -183,6 +187,9 @@ def test_operator_in():
183187
assert operator_in(celtypes.IntType(42), container_2)
184188
assert isinstance(operator_in(celtypes.IntType(-1), container_2), CELEvalError)
185189

190+
eval_error = CELEvalError()
191+
assert operator_in(eval_error, container_1) == eval_error
192+
assert operator_in(celtypes.IntType(42), eval_error) == eval_error
186193

187194
@pytest.mark.skipif(
188195
"re2" not in celpy.evaluation.function_matches.__globals__, reason="Not using RE2"
@@ -441,9 +448,14 @@ def test_function_eval_1(monkeypatch):
441448
function_of_error_result = evaluator.function_eval(
442449
lark.Token("IDENT", "size"), error
443450
)
444-
print(f"{function_of_error_result=}")
451+
# print(f"{function_of_error_result=}")
445452
assert function_of_error_result == error
446453

454+
function_of_list_with_error_result = evaluator.function_eval(
455+
lark.Token("IDENT", "size"), [error]
456+
)
457+
assert function_of_list_with_error_result == error
458+
447459

448460
def test_function_eval_2(monkeypatch):
449461
mock_size = Mock(side_effect=ValueError(sentinel.value))

0 commit comments

Comments
 (0)