Skip to content

Commit bed15e9

Browse files
committed
Update test cases for built-in modules
1 parent db314e2 commit bed15e9

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

tests/runtime/test_runtime.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
from monic.expressions import ExpressionsParser, ExpressionsInterpreter
1212

1313

14+
def _has_module(module_name: str) -> bool:
15+
code = f"""
16+
{module_name}.is_available()
17+
"""
18+
parser = ExpressionsParser()
19+
interpreter = ExpressionsInterpreter()
20+
tree = parser.parse(code)
21+
return interpreter.execute(tree)
22+
23+
24+
@pytest.mark.skipif(not _has_module("json"), reason="JSON is not available")
1425
def test_json_runtime():
1526
code = """
1627
# Test json.dumps
@@ -28,6 +39,7 @@ def test_json_runtime():
2839
assert interpreter.local_env["parsed_obj"] == {"a": 1, "b": [2, 3]}
2940

3041

42+
@pytest.mark.skipif(not _has_module("time"), reason="Time is not available")
3143
def test_time_runtime():
3244
code = """
3345
# Test time.time() and time.monotonic()
@@ -43,6 +55,9 @@ def test_time_runtime():
4355
assert isinstance(interpreter.local_env["monotonic_time"], float)
4456

4557

58+
@pytest.mark.skipif(
59+
not _has_module("datetime"), reason="Datetime is not available"
60+
)
4661
def test_datetime_runtime():
4762
code = """
4863
# Test datetime module binding
@@ -60,16 +75,6 @@ def test_datetime_runtime():
6075
)
6176

6277

63-
def _has_module(module_name: str) -> bool:
64-
code = f"""
65-
{module_name}.is_available()
66-
"""
67-
parser = ExpressionsParser()
68-
interpreter = ExpressionsInterpreter()
69-
tree = parser.parse(code)
70-
return interpreter.execute(tree)
71-
72-
7378
@pytest.mark.skipif(not _has_module("np"), reason="Numpy is not available")
7479
def test_numpy_runtime():
7580
code = """

0 commit comments

Comments
 (0)