jaclang 0.7.1__py3-none-any.whl → 0.7.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of jaclang might be problematic. Click here for more details.
- jaclang/cli/cli.py +2 -2
- jaclang/compiler/absyntree.py +539 -297
- jaclang/compiler/codeloc.py +2 -2
- jaclang/compiler/constant.py +100 -2
- jaclang/compiler/jac.lark +27 -19
- jaclang/compiler/parser.py +119 -92
- jaclang/compiler/passes/main/access_modifier_pass.py +20 -12
- jaclang/compiler/passes/main/def_impl_match_pass.py +32 -12
- jaclang/compiler/passes/main/def_use_pass.py +59 -40
- jaclang/compiler/passes/main/fuse_typeinfo_pass.py +71 -30
- jaclang/compiler/passes/main/import_pass.py +12 -7
- jaclang/compiler/passes/main/pyast_gen_pass.py +110 -47
- jaclang/compiler/passes/main/pyast_load_pass.py +49 -13
- jaclang/compiler/passes/main/pyjac_ast_link_pass.py +25 -11
- jaclang/compiler/passes/main/pyout_pass.py +3 -1
- jaclang/compiler/passes/main/registry_pass.py +6 -6
- jaclang/compiler/passes/main/sub_node_tab_pass.py +0 -5
- jaclang/compiler/passes/main/sym_tab_build_pass.py +43 -235
- jaclang/compiler/passes/main/tests/test_decl_def_match_pass.py +21 -4
- jaclang/compiler/passes/main/tests/test_def_use_pass.py +5 -10
- jaclang/compiler/passes/main/tests/test_import_pass.py +8 -0
- jaclang/compiler/passes/main/tests/test_type_check_pass.py +1 -1
- jaclang/compiler/passes/main/type_check_pass.py +2 -1
- jaclang/compiler/passes/tool/jac_formatter_pass.py +44 -11
- jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +16 -0
- jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +16 -0
- jaclang/compiler/passes/tool/tests/fixtures/doc_string.jac +15 -0
- jaclang/compiler/passes/tool/tests/fixtures/genai/essay_review.jac +1 -1
- jaclang/compiler/passes/tool/tests/fixtures/genai/expert_answer.jac +1 -1
- jaclang/compiler/passes/tool/tests/fixtures/genai/joke_gen.jac +1 -1
- jaclang/compiler/passes/tool/tests/fixtures/genai/odd_word_out.jac +1 -1
- jaclang/compiler/passes/tool/tests/fixtures/genai/personality_finder.jac +1 -1
- jaclang/compiler/passes/tool/tests/fixtures/genai/text_to_type.jac +1 -1
- jaclang/compiler/passes/tool/tests/fixtures/genai/translator.jac +1 -1
- jaclang/compiler/passes/tool/tests/fixtures/genai/wikipedia.jac +1 -1
- jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +7 -5
- jaclang/compiler/passes/tool/tests/test_unparse_validate.py +1 -2
- jaclang/compiler/passes/transform.py +2 -4
- jaclang/{core/registry.py → compiler/semtable.py} +1 -3
- jaclang/compiler/symtable.py +150 -89
- jaclang/compiler/tests/test_parser.py +2 -2
- jaclang/core/aott.py +118 -18
- jaclang/core/{construct.py → architype.py} +44 -93
- jaclang/core/constructs.py +44 -0
- jaclang/core/context.py +157 -0
- jaclang/core/importer.py +18 -9
- jaclang/core/memory.py +53 -2
- jaclang/core/test.py +90 -0
- jaclang/core/utils.py +2 -2
- jaclang/langserve/engine.py +199 -138
- jaclang/langserve/server.py +48 -53
- jaclang/langserve/tests/fixtures/base_module_structure.jac +28 -0
- jaclang/langserve/tests/fixtures/circle.jac +16 -12
- jaclang/langserve/tests/fixtures/circle_err.jac +3 -3
- jaclang/langserve/tests/fixtures/circle_pure.impl.jac +8 -4
- jaclang/langserve/tests/fixtures/circle_pure.jac +2 -2
- jaclang/langserve/tests/fixtures/circle_pure.test.jac +15 -0
- jaclang/langserve/tests/fixtures/import_include_statements.jac +6 -0
- jaclang/langserve/tests/fixtures/py_import.py +26 -0
- jaclang/langserve/tests/test_server.py +200 -2
- jaclang/langserve/utils.py +214 -10
- jaclang/plugin/builtin.py +1 -1
- jaclang/plugin/default.py +48 -92
- jaclang/plugin/feature.py +33 -17
- jaclang/plugin/spec.py +18 -20
- jaclang/plugin/tests/test_features.py +0 -33
- jaclang/settings.py +4 -0
- jaclang/tests/fixtures/abc.jac +16 -12
- jaclang/tests/fixtures/aott_raise.jac +1 -1
- jaclang/tests/fixtures/byllmissue.jac +12 -0
- jaclang/tests/fixtures/edgetypeissue.jac +10 -0
- jaclang/tests/fixtures/hash_init_check.jac +17 -0
- jaclang/tests/fixtures/hello.jac +1 -1
- jaclang/tests/fixtures/impl_match_confused.impl.jac +1 -0
- jaclang/tests/fixtures/impl_match_confused.jac +5 -0
- jaclang/tests/fixtures/math_question.jpg +0 -0
- jaclang/tests/fixtures/maxfail_run_test.jac +17 -5
- jaclang/tests/fixtures/nosigself.jac +19 -0
- jaclang/tests/fixtures/run_test.jac +17 -5
- jaclang/tests/fixtures/walker_override.jac +21 -0
- jaclang/tests/fixtures/with_llm_function.jac +1 -1
- jaclang/tests/fixtures/with_llm_lower.jac +1 -1
- jaclang/tests/fixtures/with_llm_method.jac +1 -1
- jaclang/tests/fixtures/with_llm_type.jac +1 -1
- jaclang/tests/fixtures/with_llm_vision.jac +25 -0
- jaclang/tests/test_bugs.py +19 -0
- jaclang/tests/test_cli.py +1 -1
- jaclang/tests/test_language.py +197 -82
- jaclang/tests/test_reference.py +1 -1
- jaclang/utils/lang_tools.py +5 -4
- jaclang/utils/test.py +2 -1
- jaclang/utils/treeprinter.py +35 -4
- {jaclang-0.7.1.dist-info → jaclang-0.7.7.dist-info}/METADATA +3 -2
- {jaclang-0.7.1.dist-info → jaclang-0.7.7.dist-info}/RECORD +96 -88
- jaclang/core/llms/__init__.py +0 -20
- jaclang/core/llms/anthropic.py +0 -61
- jaclang/core/llms/base.py +0 -206
- jaclang/core/llms/groq.py +0 -67
- jaclang/core/llms/huggingface.py +0 -73
- jaclang/core/llms/ollama.py +0 -78
- jaclang/core/llms/openai.py +0 -61
- jaclang/core/llms/togetherai.py +0 -60
- jaclang/core/llms/utils.py +0 -9
- jaclang/core/shelve_storage.py +0 -55
- {jaclang-0.7.1.dist-info → jaclang-0.7.7.dist-info}/WHEEL +0 -0
- {jaclang-0.7.1.dist-info → jaclang-0.7.7.dist-info}/entry_points.txt +0 -0
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"""Tests for Jac parser."""
|
|
2
2
|
|
|
3
3
|
import inspect
|
|
4
|
-
import io
|
|
5
|
-
import sys
|
|
6
|
-
import traceback
|
|
7
4
|
from typing import List, Type
|
|
8
5
|
|
|
9
|
-
from jaclang.cli import cli
|
|
10
6
|
from jaclang.plugin.default import JacFeatureDefaults
|
|
11
7
|
from jaclang.plugin.feature import JacFeature
|
|
12
8
|
from jaclang.plugin.spec import JacFeatureSpec
|
|
@@ -58,32 +54,3 @@ class TestFeatures(TestCase):
|
|
|
58
54
|
self.assertEqual(jac_feature_spec_methods, jac_feature_defaults_methods)
|
|
59
55
|
for i in jac_feature_spec_methods:
|
|
60
56
|
self.assertIn(i, jac_feature_methods)
|
|
61
|
-
|
|
62
|
-
def test_impl_match_error_reporting(self) -> None:
|
|
63
|
-
"""Basic test for error reporting."""
|
|
64
|
-
captured_output = io.StringIO()
|
|
65
|
-
original_stderr = sys.stderr
|
|
66
|
-
sys.stderr = captured_output
|
|
67
|
-
|
|
68
|
-
try:
|
|
69
|
-
# Execute the function that is expected to raise an exception
|
|
70
|
-
cli.run(self.fixture_abs_path("impl_match.jac")) # type: ignore
|
|
71
|
-
except Exception:
|
|
72
|
-
# Print the full stack trace to the captured output
|
|
73
|
-
traceback.print_exc(file=captured_output)
|
|
74
|
-
finally:
|
|
75
|
-
# Restore the original stderr
|
|
76
|
-
sys.stderr = original_stderr
|
|
77
|
-
|
|
78
|
-
# Retrieve the captured output
|
|
79
|
-
stderr_val = captured_output.getvalue()
|
|
80
|
-
# Assertions or verifications
|
|
81
|
-
try:
|
|
82
|
-
self.assertIn("impl_match.jac", stderr_val)
|
|
83
|
-
self.assertIn("impl_match_impl.jac", stderr_val)
|
|
84
|
-
self.assertLess(
|
|
85
|
-
stderr_val.index("impl_match.jac"),
|
|
86
|
-
stderr_val.index("impl_match_impl.jac"),
|
|
87
|
-
)
|
|
88
|
-
except AssertionError:
|
|
89
|
-
self.skipTest("Error reporting not implemented yet")
|
jaclang/settings.py
CHANGED
|
@@ -12,11 +12,15 @@ class Settings:
|
|
|
12
12
|
# Debug configuration
|
|
13
13
|
fuse_type_info_debug: bool = False
|
|
14
14
|
filter_sym_builtins: bool = True
|
|
15
|
+
ast_symbol_info_detailed: bool = False
|
|
15
16
|
|
|
16
17
|
# Import configuration
|
|
17
18
|
py_raise: bool = False
|
|
18
19
|
py_raise_deep: bool = False
|
|
19
20
|
|
|
21
|
+
# LSP configuration
|
|
22
|
+
lsp_debug: bool = False
|
|
23
|
+
|
|
20
24
|
def __post_init__(self) -> None:
|
|
21
25
|
"""Initialize settings."""
|
|
22
26
|
home_dir = os.path.expanduser("~")
|
jaclang/tests/fixtures/abc.jac
CHANGED
|
@@ -18,9 +18,9 @@ Below we have the demonstration of a class to calculate the area of a circle.
|
|
|
18
18
|
*#
|
|
19
19
|
|
|
20
20
|
"""Enum for shape types"""
|
|
21
|
-
enum ShapeType
|
|
22
|
-
CIRCLE="Circle",
|
|
23
|
-
UNKNOWN="Unknown"
|
|
21
|
+
enum ShapeType {
|
|
22
|
+
CIRCLE = "Circle",
|
|
23
|
+
UNKNOWN = "Unknown"
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
"""Base class for a shape."""
|
|
@@ -50,24 +50,28 @@ with entry {
|
|
|
50
50
|
# Global also works here
|
|
51
51
|
|
|
52
52
|
with entry:__main__ {
|
|
53
|
-
# To run the program functionality
|
|
54
|
-
print(
|
|
55
|
-
|
|
53
|
+
# To run the program functionality
|
|
54
|
+
print(
|
|
55
|
+
f"Area of a circle with radius {RAD} using function: {calculate_area(RAD)}"
|
|
56
|
+
);
|
|
57
|
+
print(
|
|
58
|
+
f"Area of a {c.shape_type.value} with radius {RAD} using class: {c.area()}"
|
|
59
|
+
);
|
|
56
60
|
}
|
|
57
61
|
# Unit Tests!
|
|
58
62
|
|
|
59
63
|
glob expected_area = 78.53981633974483;
|
|
60
64
|
|
|
61
|
-
test calc_area
|
|
62
|
-
check
|
|
65
|
+
test calc_area {
|
|
66
|
+
check assertAlmostEqual(calculate_area(RAD), expected_area);
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
test circle_area
|
|
69
|
+
test circle_area {
|
|
66
70
|
c = Circle(RAD);
|
|
67
|
-
check
|
|
71
|
+
check assertAlmostEqual(c.area(), expected_area);
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
test circle_type
|
|
74
|
+
test circle_type {
|
|
71
75
|
c = Circle(RAD);
|
|
72
|
-
check
|
|
76
|
+
check assertEqual(c.shape_type, ShapeType.CIRCLE);
|
|
73
77
|
}
|
jaclang/tests/fixtures/hello.jac
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:walker:gen_outline:can:get_highlights {}
|
|
Binary file
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
glob x = 5,y=2;
|
|
2
|
-
|
|
3
|
-
test
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
glob x = 5, y = 2;
|
|
2
|
+
|
|
3
|
+
test a {
|
|
4
|
+
check assertAlmostEqual(5, x);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
test b {
|
|
8
|
+
check assertIn("l", "llm");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
test c {
|
|
12
|
+
check assertEqual(x - y, 3);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
test d {
|
|
16
|
+
check assertEqual(1, 2);
|
|
17
|
+
}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
glob a = 5,b=2;
|
|
2
|
-
|
|
3
|
-
test
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
glob a = 5, b = 2;
|
|
2
|
+
|
|
3
|
+
test t1 {
|
|
4
|
+
check assertAlmostEqual(a, 6);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
test t2 {
|
|
8
|
+
check assertTrue(a != b);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
test t3 {
|
|
12
|
+
check assertIn("d", "abc");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
test t4 {
|
|
16
|
+
check assertEqual(a - b, 3);
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
walker a {
|
|
2
|
+
can foo with `root entry {
|
|
3
|
+
print("foo");
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
walker b :a: {
|
|
8
|
+
can bar with `root entry {
|
|
9
|
+
print("bar");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
walker c :b: {
|
|
14
|
+
override can foo with `root entry {
|
|
15
|
+
print("baz");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
with entry {
|
|
20
|
+
root spawn c();
|
|
21
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import:py from mtllm.llms, BaseLLM;
|
|
2
|
+
import:py from PIL, Image;
|
|
3
|
+
import:py os;
|
|
4
|
+
|
|
5
|
+
obj model:BaseLLM: {
|
|
6
|
+
can init {
|
|
7
|
+
self.verbose = False;
|
|
8
|
+
self.max_tries = 1;
|
|
9
|
+
}
|
|
10
|
+
can __infer__(meaning_in: str, **kwargs: dict) {
|
|
11
|
+
print(kwargs);
|
|
12
|
+
print(meaning_in);
|
|
13
|
+
return "[Output] Something";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
glob llm = model();
|
|
17
|
+
|
|
18
|
+
can 'Solve the Given Math Question'
|
|
19
|
+
solve_math_question(question_img: 'Image of the Question': Image) -> 'Answer to the Question': str
|
|
20
|
+
by llm(method="Chain-of-Thoughts");
|
|
21
|
+
|
|
22
|
+
with entry {
|
|
23
|
+
question_img = Image.open(os.path.join(os.path.dirname(__file__), 'math_question.jpg'));
|
|
24
|
+
print(solve_math_question(question_img));
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Test Jac language generally."""
|
|
2
|
+
|
|
3
|
+
from jaclang.compiler.compile import jac_file_to_pass
|
|
4
|
+
from jaclang.utils.test import TestCase
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class JacBugTests(TestCase):
|
|
8
|
+
"""Test pass module."""
|
|
9
|
+
|
|
10
|
+
def setUp(self) -> None:
|
|
11
|
+
"""Set up test."""
|
|
12
|
+
return super().setUp()
|
|
13
|
+
|
|
14
|
+
def test_impl_match_confusion_issue(self) -> None:
|
|
15
|
+
"""Basic test for symtable support for inheritance."""
|
|
16
|
+
mypass = jac_file_to_pass(
|
|
17
|
+
self.fixture_abs_path("impl_match_confused.jac"),
|
|
18
|
+
)
|
|
19
|
+
self.assertEqual(len(mypass.errors_had), 1)
|
jaclang/tests/test_cli.py
CHANGED
|
@@ -112,7 +112,7 @@ class JacCliTests(TestCase):
|
|
|
112
112
|
cli.tool("ir", ["ast", f"{self.fixture_abs_path('type_info.jac')}"])
|
|
113
113
|
sys.stdout = sys.__stdout__
|
|
114
114
|
stdout_value = captured_output.getvalue()
|
|
115
|
-
self.assertEqual(stdout_value.count("type_info.ServerWrapper"),
|
|
115
|
+
self.assertEqual(stdout_value.count("type_info.ServerWrapper"), 7)
|
|
116
116
|
self.assertEqual(stdout_value.count("builtins.int"), 2)
|
|
117
117
|
self.assertEqual(stdout_value.count("builtins.str"), 7)
|
|
118
118
|
|
jaclang/tests/test_language.py
CHANGED
|
@@ -6,9 +6,12 @@ import pickle
|
|
|
6
6
|
import sys
|
|
7
7
|
import sysconfig
|
|
8
8
|
|
|
9
|
+
|
|
10
|
+
import jaclang.compiler.passes.main as passes
|
|
9
11
|
from jaclang import jac_import
|
|
10
12
|
from jaclang.cli import cli
|
|
11
13
|
from jaclang.compiler.compile import jac_file_to_pass, jac_pass_to_pass, jac_str_to_pass
|
|
14
|
+
from jaclang.compiler.passes.main.schedules import py_code_gen_typed
|
|
12
15
|
from jaclang.plugin.feature import JacFeature as Jac
|
|
13
16
|
from jaclang.settings import settings
|
|
14
17
|
from jaclang.utils.test import TestCase
|
|
@@ -109,91 +112,105 @@ class JacLanguageTests(TestCase):
|
|
|
109
112
|
"{'a': 'apple', 'b': 'ball', 'c': 'cat', 'd': 'dog', 'e': 'elephant'}\n",
|
|
110
113
|
)
|
|
111
114
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
)
|
|
128
|
-
except AssertionError:
|
|
129
|
-
self.skipTest(
|
|
130
|
-
"This error only happens in certain enviornments, check later."
|
|
131
|
-
)
|
|
115
|
+
# TODO: Move these tests to mtllm repo
|
|
116
|
+
# def test_with_llm_function(self) -> None:
|
|
117
|
+
# """Parse micro jac file."""
|
|
118
|
+
# captured_output = io.StringIO()
|
|
119
|
+
# sys.stdout = captured_output
|
|
120
|
+
# jac_import("with_llm_function", base_path=self.fixture_abs_path("./"))
|
|
121
|
+
# sys.stdout = sys.__stdout__
|
|
122
|
+
# stdout_value = captured_output.getvalue()
|
|
123
|
+
# self.assertIn("{'temperature': 0.7}", stdout_value)
|
|
124
|
+
# self.assertIn("Emoji Representation (str)", stdout_value)
|
|
125
|
+
# self.assertIn('Text Input (input) (str) = "Lets move to paris"', stdout_value)
|
|
126
|
+
# self.assertIn(
|
|
127
|
+
# ' = [{"input": "I love tp drink pina coladas"',
|
|
128
|
+
# stdout_value,
|
|
129
|
+
# )
|
|
132
130
|
|
|
133
|
-
def test_with_llm_method(self) -> None:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
131
|
+
# def test_with_llm_method(self) -> None:
|
|
132
|
+
# """Parse micro jac file."""
|
|
133
|
+
# captured_output = io.StringIO()
|
|
134
|
+
# sys.stdout = captured_output
|
|
135
|
+
# jac_import("with_llm_method", base_path=self.fixture_abs_path("./"))
|
|
136
|
+
# sys.stdout = sys.__stdout__
|
|
137
|
+
# stdout_value = captured_output.getvalue()
|
|
138
|
+
# self.assertIn("[Reasoning] <Reason>", stdout_value)
|
|
139
|
+
# self.assertIn("(Enum) eg:- Personality.EXTROVERT ->", stdout_value)
|
|
140
|
+
# self.assertIn(
|
|
141
|
+
# "Personality Index of a Person (PersonalityIndex) (class) eg:- "
|
|
142
|
+
# "PersonalityIndex(index=int) -> Personality Index (index) (int)",
|
|
143
|
+
# stdout_value,
|
|
144
|
+
# )
|
|
145
|
+
# self.assertIn(
|
|
146
|
+
# "Personality of the Person (dict[Personality,PersonalityIndex])",
|
|
147
|
+
# stdout_value,
|
|
148
|
+
# )
|
|
149
|
+
# self.assertIn(
|
|
150
|
+
# 'Diary Entries (diary_entries) (list[str]) = ["I won noble prize in '
|
|
151
|
+
# 'Physics", "I am popular for my theory of relativity"]',
|
|
152
|
+
# stdout_value,
|
|
153
|
+
# )
|
|
156
154
|
|
|
157
|
-
def test_with_llm_lower(self) -> None:
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
155
|
+
# def test_with_llm_lower(self) -> None:
|
|
156
|
+
# """Parse micro jac file."""
|
|
157
|
+
# captured_output = io.StringIO()
|
|
158
|
+
# sys.stdout = captured_output
|
|
159
|
+
# jac_import("with_llm_lower", base_path=self.fixture_abs_path("./"))
|
|
160
|
+
# sys.stdout = sys.__stdout__
|
|
161
|
+
# stdout_value = captured_output.getvalue()
|
|
162
|
+
# self.assertIn("[Reasoning] <Reason>", stdout_value)
|
|
163
|
+
# self.assertIn(
|
|
164
|
+
# 'Name of the Person (name) (str) = "Oppenheimer"',
|
|
165
|
+
# stdout_value,
|
|
166
|
+
# )
|
|
167
|
+
# self.assertIn(
|
|
168
|
+
# "Person (Person) (obj) eg:- Person(full_name=str, yod=int, personality"
|
|
169
|
+
# "=Personality) -> Fullname of the Person (full_name) (str), Year of Death"
|
|
170
|
+
# " (yod) (int), Personality of the Person (personality) (Personality)",
|
|
171
|
+
# stdout_value,
|
|
172
|
+
# )
|
|
173
|
+
# self.assertIn(
|
|
174
|
+
# "J. Robert Oppenheimer was a Introvert person who died in 1967",
|
|
175
|
+
# stdout_value,
|
|
176
|
+
# )
|
|
179
177
|
|
|
180
|
-
def test_with_llm_type(self) -> None:
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
178
|
+
# def test_with_llm_type(self) -> None:
|
|
179
|
+
# """Parse micro jac file."""
|
|
180
|
+
# captured_output = io.StringIO()
|
|
181
|
+
# sys.stdout = captured_output
|
|
182
|
+
# jac_import("with_llm_type", base_path=self.fixture_abs_path("./"))
|
|
183
|
+
# sys.stdout = sys.__stdout__
|
|
184
|
+
# stdout_value = captured_output.getvalue()
|
|
185
|
+
# self.assertIn("14/03/1879", stdout_value)
|
|
186
|
+
# self.assertNotIn(
|
|
187
|
+
# 'University (University) (obj) = type(__module__="with_llm_type", __doc__=None, '
|
|
188
|
+
# "_jac_entry_funcs_`=[`], _jac_exit_funcs_=[], __init__=function(__wrapped__=function()))",
|
|
189
|
+
# stdout_value,
|
|
190
|
+
# )
|
|
191
|
+
# desired_output_count = stdout_value.count(
|
|
192
|
+
# "Person(name='Jason Mars', dob='1994-01-01', age=30)"
|
|
193
|
+
# )
|
|
194
|
+
# self.assertEqual(desired_output_count, 2)
|
|
195
|
+
|
|
196
|
+
# def test_with_llm_vision(self) -> None:
|
|
197
|
+
# """Test MTLLLM Vision Implementation."""
|
|
198
|
+
# try:
|
|
199
|
+
# captured_output = io.StringIO()
|
|
200
|
+
# sys.stdout = captured_output
|
|
201
|
+
# jac_import("with_llm_vision", base_path=self.fixture_abs_path("./"))
|
|
202
|
+
# sys.stdout = sys.__stdout__
|
|
203
|
+
# stdout_value = captured_output.getvalue()
|
|
204
|
+
# self.assertIn(
|
|
205
|
+
# "{'type': 'text', 'text': '\\n[System Prompt]\\n", stdout_value[:500]
|
|
206
|
+
# )
|
|
207
|
+
# self.assertNotIn(
|
|
208
|
+
# " {'type': 'text', 'text': 'Image of the Question (question_img) (Image) = '}, "
|
|
209
|
+
# "{'type': 'image_url', 'image_url': {'url': 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQAB",
|
|
210
|
+
# stdout_value[:500],
|
|
211
|
+
# )
|
|
212
|
+
# except Exception:
|
|
213
|
+
# self.skipTest("This test requires Pillow to be installed.")
|
|
197
214
|
|
|
198
215
|
def test_ignore(self) -> None:
|
|
199
216
|
"""Parse micro jac file."""
|
|
@@ -829,3 +846,101 @@ class JacLanguageTests(TestCase):
|
|
|
829
846
|
stdout_value = captured_output.getvalue()
|
|
830
847
|
self.assertIn("Deep convo is imported", stdout_value)
|
|
831
848
|
settings.py_raise = settings.py_raise_deep = False
|
|
849
|
+
|
|
850
|
+
def test_override_walker_inherit(self) -> None:
|
|
851
|
+
"""Test py ast to Jac ast conversion output."""
|
|
852
|
+
captured_output = io.StringIO()
|
|
853
|
+
sys.stdout = captured_output
|
|
854
|
+
jac_import("walker_override", base_path=self.fixture_abs_path("./"))
|
|
855
|
+
sys.stdout = sys.__stdout__
|
|
856
|
+
stdout_value = captured_output.getvalue()
|
|
857
|
+
self.assertEqual("baz\nbar\n", stdout_value)
|
|
858
|
+
|
|
859
|
+
def test_ds_type_check_pass(self) -> None:
|
|
860
|
+
"""Test conn assign on edges."""
|
|
861
|
+
Jac.get_root()._jac_.edges.clear()
|
|
862
|
+
mypass = jac_file_to_pass(
|
|
863
|
+
self.fixture_abs_path("../../../examples/micro/simple_walk.jac"),
|
|
864
|
+
schedule=py_code_gen_typed,
|
|
865
|
+
)
|
|
866
|
+
self.assertEqual(len(mypass.errors_had), 0)
|
|
867
|
+
self.assertEqual(len(mypass.warnings_had), 0)
|
|
868
|
+
|
|
869
|
+
def test_ds_type_check_pass2(self) -> None:
|
|
870
|
+
"""Test conn assign on edges."""
|
|
871
|
+
Jac.get_root()._jac_.edges.clear()
|
|
872
|
+
mypass = jac_file_to_pass(
|
|
873
|
+
self.fixture_abs_path("../../../examples/guess_game/guess_game5.jac"),
|
|
874
|
+
schedule=py_code_gen_typed,
|
|
875
|
+
)
|
|
876
|
+
self.assertEqual(len(mypass.errors_had), 0)
|
|
877
|
+
self.assertEqual(len(mypass.warnings_had), 0)
|
|
878
|
+
|
|
879
|
+
def test_self_with_no_sig(self) -> None: # we can get rid of this, isn't?
|
|
880
|
+
"""Test py ast to Jac ast conversion output."""
|
|
881
|
+
captured_output = io.StringIO()
|
|
882
|
+
sys.stdout = captured_output
|
|
883
|
+
jac_import("nosigself", base_path=self.fixture_abs_path("./"))
|
|
884
|
+
sys.stdout = sys.__stdout__
|
|
885
|
+
stdout_value = captured_output.getvalue()
|
|
886
|
+
self.assertEqual(stdout_value.count("5"), 2)
|
|
887
|
+
|
|
888
|
+
def test_hash_init_check(self) -> None: # we can get rid of this, isn't?
|
|
889
|
+
"""Test py ast to Jac ast conversion output."""
|
|
890
|
+
captured_output = io.StringIO()
|
|
891
|
+
sys.stdout = captured_output
|
|
892
|
+
jac_import("hash_init_check", base_path=self.fixture_abs_path("./"))
|
|
893
|
+
sys.stdout = sys.__stdout__
|
|
894
|
+
stdout_value = captured_output.getvalue()
|
|
895
|
+
self.assertIn("Test Passed", stdout_value)
|
|
896
|
+
|
|
897
|
+
def test_multiline_single_tok(self) -> None:
|
|
898
|
+
"""Test conn assign on edges."""
|
|
899
|
+
Jac.get_root()._jac_.edges.clear()
|
|
900
|
+
mypass = jac_file_to_pass(self.fixture_abs_path("byllmissue.jac"))
|
|
901
|
+
self.assertIn("2:5 - 4:8", mypass.ir.pp())
|
|
902
|
+
|
|
903
|
+
def test_single_impl_annex(self) -> None:
|
|
904
|
+
"""Basic test for pass."""
|
|
905
|
+
mypass = jac_file_to_pass(
|
|
906
|
+
self.fixture_abs_path("../../../examples/manual_code/circle_pure.jac"),
|
|
907
|
+
target=passes.JacImportPass,
|
|
908
|
+
)
|
|
909
|
+
|
|
910
|
+
self.assertEqual(mypass.ir.pp().count("AbilityDef - (o)Circle.(c)area"), 1)
|
|
911
|
+
self.assertIsNone(mypass.ir._sym_tab)
|
|
912
|
+
mypass = jac_file_to_pass(
|
|
913
|
+
self.fixture_abs_path("../../../examples/manual_code/circle_pure.jac"),
|
|
914
|
+
target=passes.SymTabBuildPass,
|
|
915
|
+
)
|
|
916
|
+
self.assertEqual(
|
|
917
|
+
len([i for i in mypass.ir.sym_tab.kid if i.name == "circle_pure.impl"]),
|
|
918
|
+
1,
|
|
919
|
+
)
|
|
920
|
+
|
|
921
|
+
def test_inherit_baseclass_sym(self) -> None:
|
|
922
|
+
"""Basic test for symtable support for inheritance."""
|
|
923
|
+
mypass = jac_file_to_pass(
|
|
924
|
+
self.fixture_abs_path("../../../examples/guess_game/guess_game4.jac"),
|
|
925
|
+
target=passes.DefUsePass,
|
|
926
|
+
)
|
|
927
|
+
table = None
|
|
928
|
+
for i in mypass.ir.sym_tab.kid:
|
|
929
|
+
print(i.name)
|
|
930
|
+
if i.name == "GuessTheNumberGame":
|
|
931
|
+
for j in i.kid:
|
|
932
|
+
if j.name == "play":
|
|
933
|
+
table = j
|
|
934
|
+
break
|
|
935
|
+
break
|
|
936
|
+
self.assertIsNotNone(table)
|
|
937
|
+
self.assertIsNotNone(table.lookup("attempts"))
|
|
938
|
+
|
|
939
|
+
def test_edge_expr_not_type(self) -> None:
|
|
940
|
+
"""Test importing python."""
|
|
941
|
+
captured_output = io.StringIO()
|
|
942
|
+
sys.stdout = captured_output
|
|
943
|
+
jac_import("edgetypeissue", base_path=self.fixture_abs_path("./"))
|
|
944
|
+
sys.stdout = sys.__stdout__
|
|
945
|
+
stdout_value = captured_output.getvalue()
|
|
946
|
+
self.assertIn("[x()]", stdout_value)
|