Skip to content

Commit 21822e2

Browse files
Move runtime tests to own file
1 parent c5c9b08 commit 21822e2

File tree

2 files changed

+100
-95
lines changed

2 files changed

+100
-95
lines changed

python/egg_smol/runtime.py

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -297,101 +297,6 @@ def _resolve_literal(decls: Declarations, arg: ArgType) -> RuntimeExpr:
297297
return arg
298298

299299

300-
def test_type_str():
301-
decls = Declarations(
302-
classes={
303-
"i64": ClassDecl(),
304-
"Map": ClassDecl(n_type_vars=2),
305-
}
306-
)
307-
i64 = RuntimeClass(decls, "i64")
308-
Map = RuntimeClass(decls, "Map")
309-
assert str(i64) == "i64"
310-
assert str(Map[i64, i64]) == "Map[i64, i64]"
311-
312-
313-
def test_function_call():
314-
decls = Declarations(
315-
classes={
316-
"i64": ClassDecl(),
317-
},
318-
functions={
319-
"one": FunctionDecl(
320-
(),
321-
TypeRefWithVars("i64"),
322-
),
323-
},
324-
)
325-
one = RuntimeFunction(decls, "one")
326-
assert one().__egg_parts__ == RuntimeExpr(decls, JustTypeRef("i64"), CallDecl(FunctionRef("one"))).__egg_parts__
327-
328-
329-
def test_classmethod_call():
330-
from pytest import raises
331-
332-
K, V = ClassTypeVarRef(0), ClassTypeVarRef(1)
333-
decls = Declarations(
334-
classes={
335-
"i64": ClassDecl(),
336-
"unit": ClassDecl(),
337-
"Map": ClassDecl(n_type_vars=2),
338-
},
339-
functions={
340-
"create": FunctionDecl(
341-
(),
342-
TypeRefWithVars("Map", (K, V)),
343-
)
344-
},
345-
)
346-
Map = RuntimeClass(decls, "Map")
347-
with raises(TypeConstraintError):
348-
Map.create()
349-
i64 = RuntimeClass(decls, "i64")
350-
unit = RuntimeClass(decls, "unit")
351-
assert (
352-
Map[i64, unit].create().__egg_parts__
353-
== RuntimeExpr(
354-
decls,
355-
JustTypeRef("Map", (JustTypeRef("i64"), JustTypeRef("unit"))),
356-
CallDecl(
357-
ClassMethodRef("Map", "create"),
358-
(),
359-
(JustTypeRef("i64"), JustTypeRef("unit")),
360-
),
361-
).__egg_parts__
362-
)
363-
364-
365-
def test_expr_special():
366-
decls = Declarations(
367-
classes={
368-
"i64": ClassDecl(
369-
methods={
370-
"__add__": FunctionDecl(
371-
(TypeRefWithVars("i64"), TypeRefWithVars("i64")),
372-
TypeRefWithVars("i64"),
373-
)
374-
},
375-
class_methods={
376-
"__init__": FunctionDecl(
377-
(TypeRefWithVars("i64"),),
378-
TypeRefWithVars("i64"),
379-
)
380-
},
381-
),
382-
},
383-
)
384-
i64 = RuntimeClass(decls, "i64")
385-
one = i64(1) # type: ignore
386-
res = one + one # type: ignore
387-
expected_res = RuntimeExpr(
388-
decls,
389-
JustTypeRef("i64"),
390-
CallDecl(MethodRef("i64", "__add__"), (LitDecl(1), LitDecl(1))),
391-
)
392-
assert res.parts == expected_res.__egg_parts__
393-
394-
395300
# def blacken_python_expression(expr: str) -> str:
396301
# """
397302
# Runs black on a Python expression, to remove excess paranthesis and wrap it.

python/tests/test_runtime.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
from __future__ import annotations
2+
3+
from egg_smol.declarations import *
4+
from egg_smol.runtime import *
5+
from egg_smol.type_constraint_solver import *
6+
7+
8+
def test_type_str():
9+
decls = Declarations(
10+
classes={
11+
"i64": ClassDecl(),
12+
"Map": ClassDecl(n_type_vars=2),
13+
}
14+
)
15+
i64 = RuntimeClass(decls, "i64")
16+
Map = RuntimeClass(decls, "Map")
17+
assert str(i64) == "i64"
18+
assert str(Map[i64, i64]) == "Map[i64, i64]"
19+
20+
21+
def test_function_call():
22+
decls = Declarations(
23+
classes={
24+
"i64": ClassDecl(),
25+
},
26+
functions={
27+
"one": FunctionDecl(
28+
(),
29+
TypeRefWithVars("i64"),
30+
),
31+
},
32+
)
33+
one = RuntimeFunction(decls, "one")
34+
assert one().__egg_parts__ == RuntimeExpr(decls, JustTypeRef("i64"), CallDecl(FunctionRef("one"))).__egg_parts__
35+
36+
37+
def test_classmethod_call():
38+
from pytest import raises
39+
40+
K, V = ClassTypeVarRef(0), ClassTypeVarRef(1)
41+
decls = Declarations(
42+
classes={
43+
"i64": ClassDecl(),
44+
"unit": ClassDecl(),
45+
"Map": ClassDecl(n_type_vars=2),
46+
},
47+
functions={
48+
"create": FunctionDecl(
49+
(),
50+
TypeRefWithVars("Map", (K, V)),
51+
)
52+
},
53+
)
54+
Map = RuntimeClass(decls, "Map")
55+
with raises(TypeConstraintError):
56+
Map.create()
57+
i64 = RuntimeClass(decls, "i64")
58+
unit = RuntimeClass(decls, "unit")
59+
assert (
60+
Map[i64, unit].create().__egg_parts__
61+
== RuntimeExpr(
62+
decls,
63+
JustTypeRef("Map", (JustTypeRef("i64"), JustTypeRef("unit"))),
64+
CallDecl(
65+
ClassMethodRef("Map", "create"),
66+
(),
67+
(JustTypeRef("i64"), JustTypeRef("unit")),
68+
),
69+
).__egg_parts__
70+
)
71+
72+
73+
def test_expr_special():
74+
decls = Declarations(
75+
classes={
76+
"i64": ClassDecl(
77+
methods={
78+
"__add__": FunctionDecl(
79+
(TypeRefWithVars("i64"), TypeRefWithVars("i64")),
80+
TypeRefWithVars("i64"),
81+
)
82+
},
83+
class_methods={
84+
"__init__": FunctionDecl(
85+
(TypeRefWithVars("i64"),),
86+
TypeRefWithVars("i64"),
87+
)
88+
},
89+
),
90+
},
91+
)
92+
i64 = RuntimeClass(decls, "i64")
93+
one = i64(1) # type: ignore
94+
res = one + one # type: ignore
95+
expected_res = RuntimeExpr(
96+
decls,
97+
JustTypeRef("i64"),
98+
CallDecl(MethodRef("i64", "__add__"), (LitDecl(1), LitDecl(1))),
99+
)
100+
assert res.parts == expected_res.__egg_parts__

0 commit comments

Comments
 (0)