pygeai 0.6.0b7__py3-none-any.whl → 0.6.0b10__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.
- pygeai/_docs/source/conf.py +78 -6
- pygeai/_docs/source/content/api_reference/embeddings.rst +31 -1
- pygeai/_docs/source/content/api_reference/evaluation.rst +590 -0
- pygeai/_docs/source/content/api_reference/feedback.rst +237 -0
- pygeai/_docs/source/content/api_reference/files.rst +592 -0
- pygeai/_docs/source/content/api_reference/gam.rst +401 -0
- pygeai/_docs/source/content/api_reference/proxy.rst +318 -0
- pygeai/_docs/source/content/api_reference/secrets.rst +495 -0
- pygeai/_docs/source/content/api_reference/usage_limits.rst +390 -0
- pygeai/_docs/source/content/api_reference.rst +7 -0
- pygeai/_docs/source/content/debugger.rst +376 -83
- pygeai/_docs/source/content/migration.rst +528 -0
- pygeai/_docs/source/content/modules.rst +1 -1
- pygeai/_docs/source/pygeai.cli.rst +8 -0
- pygeai/_docs/source/pygeai.tests.cli.rst +16 -0
- pygeai/_docs/source/pygeai.tests.core.embeddings.rst +16 -0
- pygeai/_docs/source/pygeai.tests.snippets.chat.rst +40 -0
- pygeai/_docs/source/pygeai.tests.snippets.dbg.rst +45 -0
- pygeai/_docs/source/pygeai.tests.snippets.embeddings.rst +40 -0
- pygeai/_docs/source/pygeai.tests.snippets.evaluation.dataset.rst +197 -0
- pygeai/_docs/source/pygeai.tests.snippets.evaluation.plan.rst +133 -0
- pygeai/_docs/source/pygeai.tests.snippets.evaluation.result.rst +37 -0
- pygeai/_docs/source/pygeai.tests.snippets.evaluation.rst +10 -0
- pygeai/_docs/source/pygeai.tests.snippets.rst +1 -0
- pygeai/admin/clients.py +5 -0
- pygeai/assistant/clients.py +7 -0
- pygeai/assistant/data_analyst/clients.py +2 -0
- pygeai/assistant/rag/clients.py +11 -0
- pygeai/chat/clients.py +191 -25
- pygeai/chat/endpoints.py +2 -1
- pygeai/cli/commands/chat.py +227 -1
- pygeai/cli/commands/embeddings.py +56 -8
- pygeai/cli/commands/migrate.py +994 -434
- pygeai/cli/error_handler.py +116 -0
- pygeai/cli/geai.py +28 -10
- pygeai/cli/parsers.py +8 -2
- pygeai/core/base/clients.py +3 -1
- pygeai/core/common/exceptions.py +11 -10
- pygeai/core/embeddings/__init__.py +19 -0
- pygeai/core/embeddings/clients.py +17 -2
- pygeai/core/embeddings/mappers.py +16 -2
- pygeai/core/embeddings/responses.py +9 -2
- pygeai/core/feedback/clients.py +1 -0
- pygeai/core/files/clients.py +5 -7
- pygeai/core/files/managers.py +42 -0
- pygeai/core/llm/clients.py +4 -0
- pygeai/core/plugins/clients.py +1 -0
- pygeai/core/rerank/clients.py +1 -0
- pygeai/core/secrets/clients.py +6 -0
- pygeai/core/services/rest.py +1 -1
- pygeai/dbg/__init__.py +3 -0
- pygeai/dbg/debugger.py +565 -70
- pygeai/evaluation/clients.py +1 -1
- pygeai/evaluation/dataset/clients.py +45 -44
- pygeai/evaluation/plan/clients.py +27 -26
- pygeai/evaluation/result/clients.py +37 -5
- pygeai/gam/clients.py +4 -0
- pygeai/health/clients.py +1 -0
- pygeai/lab/agents/clients.py +8 -1
- pygeai/lab/models.py +3 -3
- pygeai/lab/processes/clients.py +21 -0
- pygeai/lab/strategies/clients.py +4 -0
- pygeai/lab/tools/clients.py +1 -0
- pygeai/migration/__init__.py +31 -0
- pygeai/migration/strategies.py +404 -155
- pygeai/migration/tools.py +170 -3
- pygeai/organization/clients.py +13 -0
- pygeai/organization/limits/clients.py +15 -0
- pygeai/proxy/clients.py +3 -1
- pygeai/tests/admin/test_clients.py +16 -11
- pygeai/tests/assistants/rag/test_clients.py +35 -23
- pygeai/tests/assistants/test_clients.py +22 -15
- pygeai/tests/auth/test_clients.py +14 -6
- pygeai/tests/chat/test_clients.py +211 -1
- pygeai/tests/cli/commands/test_embeddings.py +32 -9
- pygeai/tests/cli/commands/test_evaluation.py +7 -0
- pygeai/tests/cli/commands/test_migrate.py +112 -243
- pygeai/tests/cli/test_error_handler.py +225 -0
- pygeai/tests/cli/test_geai_driver.py +154 -0
- pygeai/tests/cli/test_parsers.py +5 -5
- pygeai/tests/core/embeddings/test_clients.py +144 -0
- pygeai/tests/core/embeddings/test_managers.py +171 -0
- pygeai/tests/core/embeddings/test_mappers.py +142 -0
- pygeai/tests/core/feedback/test_clients.py +2 -0
- pygeai/tests/core/files/test_clients.py +1 -0
- pygeai/tests/core/llm/test_clients.py +14 -9
- pygeai/tests/core/plugins/test_clients.py +5 -3
- pygeai/tests/core/rerank/test_clients.py +1 -0
- pygeai/tests/core/secrets/test_clients.py +19 -13
- pygeai/tests/dbg/test_debugger.py +453 -75
- pygeai/tests/evaluation/dataset/test_clients.py +3 -1
- pygeai/tests/evaluation/plan/test_clients.py +4 -2
- pygeai/tests/evaluation/result/test_clients.py +7 -5
- pygeai/tests/gam/test_clients.py +1 -1
- pygeai/tests/health/test_clients.py +1 -0
- pygeai/tests/lab/agents/test_clients.py +9 -0
- pygeai/tests/lab/processes/test_clients.py +36 -0
- pygeai/tests/lab/processes/test_mappers.py +3 -0
- pygeai/tests/lab/strategies/test_clients.py +14 -9
- pygeai/tests/migration/test_strategies.py +45 -218
- pygeai/tests/migration/test_tools.py +133 -9
- pygeai/tests/organization/limits/test_clients.py +17 -0
- pygeai/tests/organization/test_clients.py +22 -0
- pygeai/tests/proxy/test_clients.py +2 -0
- pygeai/tests/proxy/test_integration.py +1 -0
- pygeai/tests/snippets/chat/chat_completion_with_reasoning_effort.py +18 -0
- pygeai/tests/snippets/chat/get_response.py +15 -0
- pygeai/tests/snippets/chat/get_response_streaming.py +20 -0
- pygeai/tests/snippets/chat/get_response_with_files.py +16 -0
- pygeai/tests/snippets/chat/get_response_with_tools.py +36 -0
- pygeai/tests/snippets/dbg/__init__.py +0 -0
- pygeai/tests/snippets/dbg/basic_debugging.py +32 -0
- pygeai/tests/snippets/dbg/breakpoint_management.py +48 -0
- pygeai/tests/snippets/dbg/stack_navigation.py +45 -0
- pygeai/tests/snippets/dbg/stepping_example.py +40 -0
- pygeai/tests/snippets/embeddings/cache_example.py +31 -0
- pygeai/tests/snippets/embeddings/cohere_example.py +41 -0
- pygeai/tests/snippets/embeddings/openai_base64_example.py +27 -0
- pygeai/tests/snippets/embeddings/openai_example.py +30 -0
- pygeai/tests/snippets/embeddings/similarity_example.py +42 -0
- pygeai/tests/snippets/evaluation/dataset/__init__.py +0 -0
- pygeai/tests/snippets/evaluation/dataset/complete_workflow_example.py +195 -0
- pygeai/tests/snippets/evaluation/dataset/create_dataset.py +26 -0
- pygeai/tests/snippets/evaluation/dataset/create_dataset_from_file.py +11 -0
- pygeai/tests/snippets/evaluation/dataset/create_dataset_row.py +17 -0
- pygeai/tests/snippets/evaluation/dataset/create_expected_source.py +18 -0
- pygeai/tests/snippets/evaluation/dataset/create_filter_variable.py +19 -0
- pygeai/tests/snippets/evaluation/dataset/delete_dataset.py +9 -0
- pygeai/tests/snippets/evaluation/dataset/delete_dataset_row.py +10 -0
- pygeai/tests/snippets/evaluation/dataset/delete_expected_source.py +15 -0
- pygeai/tests/snippets/evaluation/dataset/delete_filter_variable.py +15 -0
- pygeai/tests/snippets/evaluation/dataset/get_dataset.py +9 -0
- pygeai/tests/snippets/evaluation/dataset/get_dataset_row.py +10 -0
- pygeai/tests/snippets/evaluation/dataset/get_expected_source.py +15 -0
- pygeai/tests/snippets/evaluation/dataset/get_filter_variable.py +15 -0
- pygeai/tests/snippets/evaluation/dataset/list_dataset_rows.py +9 -0
- pygeai/tests/snippets/evaluation/dataset/list_datasets.py +6 -0
- pygeai/tests/snippets/evaluation/dataset/list_expected_sources.py +10 -0
- pygeai/tests/snippets/evaluation/dataset/list_filter_variables.py +10 -0
- pygeai/tests/snippets/evaluation/dataset/update_dataset.py +15 -0
- pygeai/tests/snippets/evaluation/dataset/update_dataset_row.py +20 -0
- pygeai/tests/snippets/evaluation/dataset/update_expected_source.py +18 -0
- pygeai/tests/snippets/evaluation/dataset/update_filter_variable.py +19 -0
- pygeai/tests/snippets/evaluation/dataset/upload_dataset_rows_file.py +10 -0
- pygeai/tests/snippets/evaluation/plan/__init__.py +0 -0
- pygeai/tests/snippets/evaluation/plan/add_plan_system_metric.py +13 -0
- pygeai/tests/snippets/evaluation/plan/complete_workflow_example.py +136 -0
- pygeai/tests/snippets/evaluation/plan/create_evaluation_plan.py +24 -0
- pygeai/tests/snippets/evaluation/plan/create_rag_evaluation_plan.py +22 -0
- pygeai/tests/snippets/evaluation/plan/delete_evaluation_plan.py +9 -0
- pygeai/tests/snippets/evaluation/plan/delete_plan_system_metric.py +13 -0
- pygeai/tests/snippets/evaluation/plan/execute_evaluation_plan.py +11 -0
- pygeai/tests/snippets/evaluation/plan/get_evaluation_plan.py +9 -0
- pygeai/tests/snippets/evaluation/plan/get_plan_system_metric.py +13 -0
- pygeai/tests/snippets/evaluation/plan/get_system_metric.py +9 -0
- pygeai/tests/snippets/evaluation/plan/list_evaluation_plans.py +7 -0
- pygeai/tests/snippets/evaluation/plan/list_plan_system_metrics.py +9 -0
- pygeai/tests/snippets/evaluation/plan/list_system_metrics.py +7 -0
- pygeai/tests/snippets/evaluation/plan/update_evaluation_plan.py +22 -0
- pygeai/tests/snippets/evaluation/plan/update_plan_system_metric.py +14 -0
- pygeai/tests/snippets/evaluation/result/__init__.py +0 -0
- pygeai/tests/snippets/evaluation/result/complete_workflow_example.py +150 -0
- pygeai/tests/snippets/evaluation/result/get_evaluation_result.py +26 -0
- pygeai/tests/snippets/evaluation/result/list_evaluation_results.py +17 -0
- pygeai/tests/snippets/migrate/__init__.py +45 -0
- pygeai/tests/snippets/migrate/agent_migration.py +110 -0
- pygeai/tests/snippets/migrate/assistant_migration.py +64 -0
- pygeai/tests/snippets/migrate/orchestrator_examples.py +179 -0
- pygeai/tests/snippets/migrate/process_migration.py +64 -0
- pygeai/tests/snippets/migrate/project_migration.py +42 -0
- pygeai/tests/snippets/migrate/tool_migration.py +64 -0
- pygeai/tests/snippets/organization/create_project.py +2 -2
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b10.dist-info}/METADATA +1 -1
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b10.dist-info}/RECORD +178 -96
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b10.dist-info}/WHEEL +0 -0
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b10.dist-info}/entry_points.txt +0 -0
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b10.dist-info}/licenses/LICENSE +0 -0
- {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b10.dist-info}/top_level.txt +0 -0
|
@@ -1,128 +1,506 @@
|
|
|
1
1
|
from unittest import TestCase
|
|
2
|
-
from unittest.mock import patch, MagicMock
|
|
3
|
-
from
|
|
2
|
+
from unittest.mock import patch, MagicMock, call
|
|
3
|
+
from types import FrameType
|
|
4
|
+
from pygeai.dbg.debugger import Debugger, Breakpoint
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TestBreakpoint(TestCase):
|
|
8
|
+
"""Test Breakpoint class."""
|
|
9
|
+
|
|
10
|
+
def test_breakpoint_creation(self):
|
|
11
|
+
bp = Breakpoint(module="test.module", function_name="test_func")
|
|
12
|
+
self.assertEqual(bp.module, "test.module")
|
|
13
|
+
self.assertEqual(bp.function_name, "test_func")
|
|
14
|
+
self.assertTrue(bp.enabled)
|
|
15
|
+
self.assertEqual(bp.hit_count, 0)
|
|
16
|
+
self.assertIsNone(bp.condition)
|
|
17
|
+
|
|
18
|
+
def test_breakpoint_matches_exact(self):
|
|
19
|
+
bp = Breakpoint(module="test.module", function_name="test_func")
|
|
20
|
+
self.assertTrue(bp.matches("test.module", "test_func"))
|
|
21
|
+
self.assertFalse(bp.matches("other.module", "test_func"))
|
|
22
|
+
self.assertFalse(bp.matches("test.module", "other_func"))
|
|
23
|
+
|
|
24
|
+
def test_breakpoint_matches_wildcard_module(self):
|
|
25
|
+
bp = Breakpoint(module=None, function_name="test_func")
|
|
26
|
+
self.assertTrue(bp.matches("any.module", "test_func"))
|
|
27
|
+
self.assertTrue(bp.matches("other.module", "test_func"))
|
|
28
|
+
self.assertFalse(bp.matches("any.module", "other_func"))
|
|
29
|
+
|
|
30
|
+
def test_breakpoint_matches_wildcard_function(self):
|
|
31
|
+
bp = Breakpoint(module="test.module", function_name=None)
|
|
32
|
+
self.assertTrue(bp.matches("test.module", "any_func"))
|
|
33
|
+
self.assertTrue(bp.matches("test.module", "other_func"))
|
|
34
|
+
self.assertFalse(bp.matches("other.module", "any_func"))
|
|
35
|
+
|
|
36
|
+
def test_breakpoint_disabled(self):
|
|
37
|
+
bp = Breakpoint(module="test.module", function_name="test_func", enabled=False)
|
|
38
|
+
self.assertFalse(bp.matches("test.module", "test_func"))
|
|
39
|
+
|
|
40
|
+
def test_breakpoint_str(self):
|
|
41
|
+
bp = Breakpoint(module="test.module", function_name="test_func")
|
|
42
|
+
bp.hit_count = 5
|
|
43
|
+
self.assertIn("test.module:test_func", str(bp))
|
|
44
|
+
self.assertIn("enabled", str(bp))
|
|
45
|
+
self.assertIn("5", str(bp))
|
|
46
|
+
|
|
47
|
+
def test_breakpoint_with_condition(self):
|
|
48
|
+
bp = Breakpoint(module="test.module", function_name="test_func", condition="x > 10")
|
|
49
|
+
self.assertEqual(bp.condition, "x > 10")
|
|
50
|
+
self.assertIn("if x > 10", str(bp))
|
|
4
51
|
|
|
5
52
|
|
|
6
53
|
class TestDebugger(TestCase):
|
|
7
|
-
"""
|
|
8
|
-
python -m unittest pygeai.tests.dbg.test_debugger.TestDebugger
|
|
9
|
-
"""
|
|
54
|
+
"""Test Debugger class."""
|
|
10
55
|
|
|
11
56
|
def setUp(self):
|
|
12
|
-
# Mock logging to avoid actual log output during tests
|
|
13
57
|
self.logging_patch = patch('pygeai.dbg.debugger.logging')
|
|
14
58
|
self.mock_logging = self.logging_patch.start()
|
|
15
59
|
self.mock_logger = MagicMock()
|
|
16
60
|
self.mock_logging.getLogger.return_value = self.mock_logger
|
|
17
|
-
|
|
18
|
-
# Mock Console to avoid actual stdout writes
|
|
61
|
+
|
|
19
62
|
self.console_patch = patch('pygeai.dbg.debugger.Console')
|
|
20
63
|
self.mock_console = self.console_patch.start()
|
|
21
64
|
self.mock_console.write_stdout = MagicMock()
|
|
65
|
+
|
|
66
|
+
self.readline_patch = patch('pygeai.dbg.debugger.readline')
|
|
67
|
+
self.mock_readline = self.readline_patch.start()
|
|
22
68
|
|
|
23
69
|
def tearDown(self):
|
|
24
70
|
self.logging_patch.stop()
|
|
25
71
|
self.console_patch.stop()
|
|
72
|
+
self.readline_patch.stop()
|
|
26
73
|
|
|
27
|
-
def
|
|
74
|
+
def test_debugger_init_default(self):
|
|
28
75
|
debugger = Debugger()
|
|
29
76
|
self.assertEqual(len(debugger.breakpoints), 0)
|
|
30
77
|
self.assertFalse(debugger.paused)
|
|
31
|
-
self.
|
|
32
|
-
self.
|
|
78
|
+
self.assertIsNone(debugger.current_frame)
|
|
79
|
+
self.assertEqual(debugger.module_filter, "pygeai")
|
|
80
|
+
self.assertEqual(len(debugger.frame_stack), 0)
|
|
81
|
+
|
|
82
|
+
def test_debugger_init_custom_target(self):
|
|
83
|
+
def custom_target():
|
|
84
|
+
pass
|
|
85
|
+
|
|
86
|
+
debugger = Debugger(target=custom_target, module_filter="custom")
|
|
87
|
+
self.assertEqual(debugger.target, custom_target)
|
|
88
|
+
self.assertEqual(debugger.module_filter, "custom")
|
|
33
89
|
|
|
34
90
|
def test_add_breakpoint_module_only(self):
|
|
35
91
|
debugger = Debugger()
|
|
36
|
-
debugger.add_breakpoint(module="pygeai.cli.geai")
|
|
92
|
+
bp = debugger.add_breakpoint(module="pygeai.cli.geai")
|
|
37
93
|
self.assertEqual(len(debugger.breakpoints), 1)
|
|
38
|
-
self.
|
|
39
|
-
self.
|
|
40
|
-
self.assertTrue(
|
|
94
|
+
self.assertEqual(bp.module, "pygeai.cli.geai")
|
|
95
|
+
self.assertIsNone(bp.function_name)
|
|
96
|
+
self.assertTrue(bp.enabled)
|
|
41
97
|
|
|
42
98
|
def test_add_breakpoint_function_only(self):
|
|
43
99
|
debugger = Debugger()
|
|
44
|
-
debugger.add_breakpoint(function_name="main")
|
|
100
|
+
bp = debugger.add_breakpoint(function_name="main")
|
|
45
101
|
self.assertEqual(len(debugger.breakpoints), 1)
|
|
46
|
-
self.
|
|
47
|
-
self.
|
|
48
|
-
self.assertTrue(any("Breakpoint added: *:main" in str(call) for call in self.mock_logger.info.call_args_list))
|
|
102
|
+
self.assertIsNone(bp.module)
|
|
103
|
+
self.assertEqual(bp.function_name, "main")
|
|
49
104
|
|
|
50
105
|
def test_add_breakpoint_both(self):
|
|
51
106
|
debugger = Debugger()
|
|
52
|
-
debugger.add_breakpoint(module="pygeai.cli.geai", function_name="main")
|
|
107
|
+
bp = debugger.add_breakpoint(module="pygeai.cli.geai", function_name="main")
|
|
53
108
|
self.assertEqual(len(debugger.breakpoints), 1)
|
|
54
|
-
self.
|
|
55
|
-
self.
|
|
56
|
-
self.assertTrue(any("Breakpoint added: pygeai.cli.geai:main" in str(call) for call in self.mock_logger.info.call_args_list))
|
|
109
|
+
self.assertEqual(bp.module, "pygeai.cli.geai")
|
|
110
|
+
self.assertEqual(bp.function_name, "main")
|
|
57
111
|
|
|
58
|
-
def
|
|
112
|
+
def test_add_breakpoint_with_condition(self):
|
|
59
113
|
debugger = Debugger()
|
|
60
|
-
|
|
61
|
-
self.
|
|
62
|
-
|
|
63
|
-
|
|
114
|
+
bp = debugger.add_breakpoint(module="test", function_name="func", condition="x > 10")
|
|
115
|
+
self.assertEqual(bp.condition, "x > 10")
|
|
116
|
+
|
|
117
|
+
def test_add_breakpoint_duplicate(self):
|
|
118
|
+
debugger = Debugger()
|
|
119
|
+
bp1 = debugger.add_breakpoint(module="test", function_name="func")
|
|
120
|
+
bp2 = debugger.add_breakpoint(module="test", function_name="func")
|
|
121
|
+
self.assertEqual(bp1, bp2)
|
|
122
|
+
self.assertEqual(len(debugger.breakpoints), 1)
|
|
123
|
+
|
|
124
|
+
def test_remove_breakpoint(self):
|
|
125
|
+
debugger = Debugger()
|
|
126
|
+
debugger.add_breakpoint(module="test", function_name="func")
|
|
127
|
+
self.assertEqual(len(debugger.breakpoints), 1)
|
|
128
|
+
|
|
129
|
+
result = debugger.remove_breakpoint(module="test", function_name="func")
|
|
130
|
+
self.assertTrue(result)
|
|
131
|
+
self.assertEqual(len(debugger.breakpoints), 0)
|
|
132
|
+
|
|
133
|
+
def test_remove_breakpoint_not_found(self):
|
|
134
|
+
debugger = Debugger()
|
|
135
|
+
result = debugger.remove_breakpoint(module="test", function_name="func")
|
|
136
|
+
self.assertFalse(result)
|
|
137
|
+
|
|
138
|
+
def test_list_breakpoints(self):
|
|
139
|
+
debugger = Debugger()
|
|
140
|
+
debugger.add_breakpoint(module="test1", function_name="func1")
|
|
141
|
+
debugger.add_breakpoint(module="test2", function_name="func2")
|
|
142
|
+
|
|
143
|
+
bps = debugger.list_breakpoints()
|
|
144
|
+
self.assertEqual(len(bps), 2)
|
|
145
|
+
|
|
146
|
+
def test_enable_disable_breakpoint(self):
|
|
147
|
+
debugger = Debugger()
|
|
148
|
+
debugger.add_breakpoint(module="test", function_name="func")
|
|
149
|
+
|
|
150
|
+
result = debugger.disable_breakpoint(module="test", function_name="func")
|
|
151
|
+
self.assertTrue(result)
|
|
152
|
+
bp = debugger.breakpoints[("test", "func")]
|
|
153
|
+
self.assertFalse(bp.enabled)
|
|
154
|
+
|
|
155
|
+
result = debugger.enable_breakpoint(module="test", function_name="func")
|
|
156
|
+
self.assertTrue(result)
|
|
157
|
+
self.assertTrue(bp.enabled)
|
|
158
|
+
|
|
159
|
+
def test_clear_breakpoints(self):
|
|
160
|
+
debugger = Debugger()
|
|
161
|
+
debugger.add_breakpoint(module="test1", function_name="func1")
|
|
162
|
+
debugger.add_breakpoint(module="test2", function_name="func2")
|
|
163
|
+
self.assertEqual(len(debugger.breakpoints), 2)
|
|
164
|
+
|
|
165
|
+
debugger.clear_breakpoints()
|
|
166
|
+
self.assertEqual(len(debugger.breakpoints), 0)
|
|
167
|
+
|
|
168
|
+
def test_reset(self):
|
|
169
|
+
debugger = Debugger()
|
|
170
|
+
debugger.add_breakpoint(module="test", function_name="func")
|
|
171
|
+
debugger.paused = True
|
|
172
|
+
debugger.step_mode = "step"
|
|
173
|
+
|
|
174
|
+
debugger.reset()
|
|
175
|
+
self.assertEqual(len(debugger.breakpoints), 0)
|
|
176
|
+
self.assertFalse(debugger.paused)
|
|
177
|
+
self.assertIsNone(debugger.step_mode)
|
|
178
|
+
|
|
179
|
+
def test_should_trace_module(self):
|
|
180
|
+
debugger = Debugger(module_filter="pygeai")
|
|
181
|
+
self.assertTrue(debugger._should_trace_module("pygeai.cli"))
|
|
182
|
+
self.assertTrue(debugger._should_trace_module("pygeai.core"))
|
|
183
|
+
self.assertFalse(debugger._should_trace_module("other.module"))
|
|
184
|
+
self.assertFalse(debugger._should_trace_module(None))
|
|
185
|
+
|
|
186
|
+
def test_check_condition_true(self):
|
|
187
|
+
debugger = Debugger()
|
|
188
|
+
bp = Breakpoint(condition="x > 5")
|
|
189
|
+
|
|
190
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
191
|
+
mock_frame.f_locals = {"x": 10}
|
|
192
|
+
mock_frame.f_globals = {}
|
|
193
|
+
|
|
194
|
+
result = debugger._check_condition(bp, mock_frame)
|
|
195
|
+
self.assertTrue(result)
|
|
196
|
+
|
|
197
|
+
def test_check_condition_false(self):
|
|
198
|
+
debugger = Debugger()
|
|
199
|
+
bp = Breakpoint(condition="x > 5")
|
|
200
|
+
|
|
201
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
202
|
+
mock_frame.f_locals = {"x": 3}
|
|
203
|
+
mock_frame.f_globals = {}
|
|
204
|
+
|
|
205
|
+
result = debugger._check_condition(bp, mock_frame)
|
|
206
|
+
self.assertFalse(result)
|
|
207
|
+
|
|
208
|
+
def test_check_condition_no_condition(self):
|
|
209
|
+
debugger = Debugger()
|
|
210
|
+
bp = Breakpoint()
|
|
211
|
+
|
|
212
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
213
|
+
result = debugger._check_condition(bp, mock_frame)
|
|
214
|
+
self.assertTrue(result)
|
|
215
|
+
|
|
216
|
+
def test_check_condition_error(self):
|
|
217
|
+
debugger = Debugger()
|
|
218
|
+
bp = Breakpoint(condition="invalid syntax !!!")
|
|
219
|
+
|
|
220
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
221
|
+
mock_frame.f_locals = {}
|
|
222
|
+
mock_frame.f_globals = {}
|
|
223
|
+
|
|
224
|
+
result = debugger._check_condition(bp, mock_frame)
|
|
225
|
+
self.assertFalse(result)
|
|
226
|
+
|
|
227
|
+
def test_build_frame_stack(self):
|
|
228
|
+
debugger = Debugger()
|
|
229
|
+
|
|
230
|
+
frame3 = MagicMock(spec=FrameType)
|
|
231
|
+
frame3.f_back = None
|
|
232
|
+
|
|
233
|
+
frame2 = MagicMock(spec=FrameType)
|
|
234
|
+
frame2.f_back = frame3
|
|
235
|
+
|
|
236
|
+
frame1 = MagicMock(spec=FrameType)
|
|
237
|
+
frame1.f_back = frame2
|
|
238
|
+
|
|
239
|
+
stack = debugger._build_frame_stack(frame1)
|
|
240
|
+
self.assertEqual(len(stack), 3)
|
|
241
|
+
self.assertEqual(stack[0], frame1)
|
|
242
|
+
self.assertEqual(stack[1], frame2)
|
|
243
|
+
self.assertEqual(stack[2], frame3)
|
|
244
|
+
|
|
245
|
+
def test_trace_function_ignores_non_filtered_modules(self):
|
|
246
|
+
debugger = Debugger(module_filter="pygeai")
|
|
247
|
+
debugger.add_breakpoint(function_name="main")
|
|
248
|
+
|
|
249
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
250
|
+
mock_frame.f_globals = {"__name__": "other.module"}
|
|
64
251
|
mock_frame.f_code.co_name = "main"
|
|
252
|
+
|
|
65
253
|
result = debugger.trace_function(mock_frame, "call", None)
|
|
66
|
-
self.
|
|
254
|
+
self.assertIsNone(result)
|
|
67
255
|
self.assertFalse(debugger.paused)
|
|
68
|
-
self.mock_logger.info.assert_not_called() # No breakpoint hit log after reset
|
|
69
256
|
|
|
70
|
-
def
|
|
71
|
-
debugger = Debugger()
|
|
72
|
-
debugger.add_breakpoint(module="pygeai.cli.geai")
|
|
73
|
-
|
|
74
|
-
mock_frame = MagicMock()
|
|
257
|
+
def test_trace_function_breakpoint_hit(self):
|
|
258
|
+
debugger = Debugger(module_filter="pygeai")
|
|
259
|
+
debugger.add_breakpoint(module="pygeai.cli.geai", function_name="main")
|
|
260
|
+
|
|
261
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
75
262
|
mock_frame.f_globals = {"__name__": "pygeai.cli.geai"}
|
|
76
|
-
mock_frame.f_code.co_name = "
|
|
263
|
+
mock_frame.f_code.co_name = "main"
|
|
264
|
+
mock_frame.f_code.co_filename = __file__
|
|
265
|
+
mock_frame.f_lineno = 1
|
|
266
|
+
mock_frame.f_back = None
|
|
267
|
+
|
|
77
268
|
with patch('builtins.input', return_value="continue"):
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
269
|
+
with patch.object(debugger, '_get_source_lines', return_value=[(1, "test")]):
|
|
270
|
+
result = debugger.trace_function(mock_frame, "call", None)
|
|
271
|
+
self.assertIsNotNone(result)
|
|
272
|
+
bp = debugger.breakpoints[("pygeai.cli.geai", "main")]
|
|
273
|
+
self.assertEqual(bp.hit_count, 1)
|
|
83
274
|
|
|
84
|
-
def
|
|
85
|
-
debugger = Debugger()
|
|
86
|
-
debugger.add_breakpoint(function_name="main")
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
mock_frame
|
|
275
|
+
def test_trace_function_disabled_breakpoint(self):
|
|
276
|
+
debugger = Debugger(module_filter="pygeai")
|
|
277
|
+
debugger.add_breakpoint(module="pygeai.cli.geai", function_name="main")
|
|
278
|
+
debugger.disable_breakpoint(module="pygeai.cli.geai", function_name="main")
|
|
279
|
+
|
|
280
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
281
|
+
mock_frame.f_globals = {"__name__": "pygeai.cli.geai"}
|
|
90
282
|
mock_frame.f_code.co_name = "main"
|
|
283
|
+
|
|
284
|
+
result = debugger.trace_function(mock_frame, "call", None)
|
|
285
|
+
self.assertIsNotNone(result)
|
|
286
|
+
self.assertFalse(debugger.paused)
|
|
287
|
+
|
|
288
|
+
def test_trace_function_conditional_breakpoint_met(self):
|
|
289
|
+
debugger = Debugger(module_filter="pygeai")
|
|
290
|
+
debugger.add_breakpoint(module="pygeai.test", function_name="func", condition="x > 5")
|
|
291
|
+
|
|
292
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
293
|
+
mock_frame.f_globals = {"__name__": "pygeai.test"}
|
|
294
|
+
mock_frame.f_locals = {"x": 10}
|
|
295
|
+
mock_frame.f_code.co_name = "func"
|
|
296
|
+
mock_frame.f_code.co_filename = __file__
|
|
297
|
+
mock_frame.f_lineno = 1
|
|
298
|
+
mock_frame.f_back = None
|
|
299
|
+
|
|
91
300
|
with patch('builtins.input', return_value="continue"):
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
any("Breakpoint hit at some.module.main" in str(call) for call in self.mock_logger.info.call_args_list))
|
|
301
|
+
with patch.object(debugger, '_get_source_lines', return_value=[(1, "test")]):
|
|
302
|
+
result = debugger.trace_function(mock_frame, "call", None)
|
|
303
|
+
bp = debugger.breakpoints[("pygeai.test", "func")]
|
|
304
|
+
self.assertEqual(bp.hit_count, 1)
|
|
97
305
|
|
|
98
|
-
def
|
|
306
|
+
def test_trace_function_conditional_breakpoint_not_met(self):
|
|
307
|
+
debugger = Debugger(module_filter="pygeai")
|
|
308
|
+
debugger.add_breakpoint(module="pygeai.test", function_name="func", condition="x > 5")
|
|
309
|
+
|
|
310
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
311
|
+
mock_frame.f_globals = {"__name__": "pygeai.test"}
|
|
312
|
+
mock_frame.f_locals = {"x": 3}
|
|
313
|
+
mock_frame.f_code.co_name = "func"
|
|
314
|
+
|
|
315
|
+
result = debugger.trace_function(mock_frame, "call", None)
|
|
316
|
+
bp = debugger.breakpoints[("pygeai.test", "func")]
|
|
317
|
+
self.assertEqual(bp.hit_count, 0)
|
|
318
|
+
self.assertFalse(debugger.paused)
|
|
319
|
+
|
|
320
|
+
def test_move_frame_up(self):
|
|
99
321
|
debugger = Debugger()
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
322
|
+
|
|
323
|
+
frame2 = MagicMock(spec=FrameType)
|
|
324
|
+
frame2.f_globals = {"__name__": "module2"}
|
|
325
|
+
frame2.f_code.co_name = "func2"
|
|
326
|
+
|
|
327
|
+
frame1 = MagicMock(spec=FrameType)
|
|
328
|
+
frame1.f_globals = {"__name__": "module1"}
|
|
329
|
+
frame1.f_code.co_name = "func1"
|
|
330
|
+
|
|
331
|
+
debugger.frame_stack = [frame1, frame2]
|
|
332
|
+
debugger.current_frame_index = 0
|
|
333
|
+
debugger.current_frame = frame1
|
|
334
|
+
|
|
335
|
+
result = debugger._move_frame(1)
|
|
336
|
+
self.assertTrue(result)
|
|
337
|
+
self.assertEqual(debugger.current_frame_index, 1)
|
|
338
|
+
self.assertEqual(debugger.current_frame, frame2)
|
|
105
339
|
|
|
106
|
-
def
|
|
340
|
+
def test_move_frame_down(self):
|
|
107
341
|
debugger = Debugger()
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
342
|
+
|
|
343
|
+
frame2 = MagicMock(spec=FrameType)
|
|
344
|
+
frame2.f_globals = {"__name__": "module2"}
|
|
345
|
+
frame2.f_code.co_name = "func2"
|
|
346
|
+
|
|
347
|
+
frame1 = MagicMock(spec=FrameType)
|
|
348
|
+
frame1.f_globals = {"__name__": "module1"}
|
|
349
|
+
frame1.f_code.co_name = "func1"
|
|
350
|
+
|
|
351
|
+
debugger.frame_stack = [frame1, frame2]
|
|
352
|
+
debugger.current_frame_index = 1
|
|
353
|
+
debugger.current_frame = frame2
|
|
354
|
+
|
|
355
|
+
result = debugger._move_frame(-1)
|
|
356
|
+
self.assertTrue(result)
|
|
357
|
+
self.assertEqual(debugger.current_frame_index, 0)
|
|
358
|
+
self.assertEqual(debugger.current_frame, frame1)
|
|
359
|
+
|
|
360
|
+
def test_move_frame_out_of_bounds(self):
|
|
361
|
+
debugger = Debugger()
|
|
362
|
+
|
|
363
|
+
frame1 = MagicMock(spec=FrameType)
|
|
364
|
+
frame1.f_globals = {"__name__": "module1"}
|
|
365
|
+
frame1.f_code.co_name = "func1"
|
|
366
|
+
|
|
367
|
+
debugger.frame_stack = [frame1]
|
|
368
|
+
debugger.current_frame_index = 0
|
|
369
|
+
debugger.current_frame = frame1
|
|
370
|
+
|
|
371
|
+
result = debugger._move_frame(1)
|
|
372
|
+
self.assertFalse(result)
|
|
373
|
+
self.assertEqual(debugger.current_frame_index, 0)
|
|
118
374
|
|
|
119
375
|
def test_run_successful(self):
|
|
120
376
|
debugger = Debugger()
|
|
121
377
|
with patch('sys.settrace') as mock_settrace:
|
|
122
|
-
with patch(
|
|
378
|
+
with patch.object(debugger, 'target') as mock_target:
|
|
123
379
|
debugger.run()
|
|
124
|
-
|
|
125
|
-
mock_settrace.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
380
|
+
mock_target.assert_called_once()
|
|
381
|
+
self.assertEqual(mock_settrace.call_count, 2)
|
|
382
|
+
|
|
383
|
+
def test_run_with_exception(self):
|
|
384
|
+
debugger = Debugger()
|
|
385
|
+
with patch('sys.settrace') as mock_settrace:
|
|
386
|
+
with patch.object(debugger, 'target', side_effect=Exception("Test error")):
|
|
387
|
+
with self.assertRaises(Exception):
|
|
388
|
+
debugger.run()
|
|
389
|
+
self.assertEqual(mock_settrace.call_count, 2)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
class TestDebuggerCommands(TestCase):
|
|
393
|
+
"""Test debugger interactive commands."""
|
|
394
|
+
|
|
395
|
+
def setUp(self):
|
|
396
|
+
self.logging_patch = patch('pygeai.dbg.debugger.logging')
|
|
397
|
+
self.mock_logging = self.logging_patch.start()
|
|
398
|
+
self.mock_logger = MagicMock()
|
|
399
|
+
self.mock_logging.getLogger.return_value = self.mock_logger
|
|
400
|
+
|
|
401
|
+
self.console_patch = patch('pygeai.dbg.debugger.Console')
|
|
402
|
+
self.mock_console = self.console_patch.start()
|
|
403
|
+
|
|
404
|
+
self.readline_patch = patch('pygeai.dbg.debugger.readline')
|
|
405
|
+
self.mock_readline = self.readline_patch.start()
|
|
406
|
+
|
|
407
|
+
self.pprint_patch = patch('pygeai.dbg.debugger.pprint')
|
|
408
|
+
self.mock_pprint = self.pprint_patch.start()
|
|
409
|
+
|
|
410
|
+
def tearDown(self):
|
|
411
|
+
self.logging_patch.stop()
|
|
412
|
+
self.console_patch.stop()
|
|
413
|
+
self.readline_patch.stop()
|
|
414
|
+
self.pprint_patch.stop()
|
|
415
|
+
|
|
416
|
+
def test_handle_breakpoint_continue(self):
|
|
417
|
+
debugger = Debugger()
|
|
418
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
419
|
+
mock_frame.f_globals = {"__name__": "test"}
|
|
420
|
+
mock_frame.f_code.co_name = "func"
|
|
421
|
+
mock_frame.f_lineno = 10
|
|
422
|
+
mock_frame.f_back = None
|
|
423
|
+
|
|
424
|
+
with patch('builtins.input', side_effect=["c"]):
|
|
425
|
+
with patch.object(debugger, '_get_source_lines', return_value=[(10, "test")]):
|
|
426
|
+
debugger.handle_breakpoint(mock_frame)
|
|
427
|
+
|
|
428
|
+
def test_handle_breakpoint_quit(self):
|
|
429
|
+
debugger = Debugger()
|
|
430
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
431
|
+
mock_frame.f_globals = {"__name__": "test"}
|
|
432
|
+
mock_frame.f_code.co_name = "func"
|
|
433
|
+
mock_frame.f_lineno = 10
|
|
434
|
+
|
|
435
|
+
with patch('builtins.input', return_value="q"):
|
|
436
|
+
with patch.object(debugger, '_get_source_lines', return_value=[(10, "test")]):
|
|
437
|
+
with self.assertRaises(SystemExit):
|
|
438
|
+
debugger.handle_breakpoint(mock_frame)
|
|
439
|
+
|
|
440
|
+
def test_handle_breakpoint_print_expression(self):
|
|
441
|
+
debugger = Debugger()
|
|
442
|
+
debugger.current_frame = MagicMock(spec=FrameType)
|
|
443
|
+
debugger.current_frame.f_globals = {"__name__": "test"}
|
|
444
|
+
debugger.current_frame.f_locals = {"x": 42}
|
|
445
|
+
debugger.current_frame.f_code.co_name = "func"
|
|
446
|
+
debugger.current_frame.f_lineno = 10
|
|
447
|
+
debugger.current_frame.f_back = None
|
|
448
|
+
debugger.frame_stack = [debugger.current_frame]
|
|
449
|
+
debugger.current_frame_index = 0
|
|
450
|
+
|
|
451
|
+
with patch('builtins.input', side_effect=["p x", "c"]):
|
|
452
|
+
with patch.object(debugger, '_get_source_lines', return_value=[(10, "test")]):
|
|
453
|
+
debugger.handle_breakpoint(debugger.current_frame)
|
|
454
|
+
calls = [str(call) for call in self.mock_console.write_stdout.call_args_list]
|
|
455
|
+
self.assertTrue(any("42" in str(call) for call in calls))
|
|
456
|
+
|
|
457
|
+
def test_handle_breakpoint_list_breakpoints(self):
|
|
458
|
+
debugger = Debugger()
|
|
459
|
+
debugger.add_breakpoint(module="test", function_name="func")
|
|
460
|
+
|
|
461
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
462
|
+
mock_frame.f_globals = {"__name__": "test"}
|
|
463
|
+
mock_frame.f_code.co_name = "func"
|
|
464
|
+
mock_frame.f_lineno = 10
|
|
465
|
+
|
|
466
|
+
with patch('builtins.input', side_effect=["b", "c"]):
|
|
467
|
+
with patch.object(debugger, '_get_source_lines', return_value=[(10, "test")]):
|
|
468
|
+
debugger.handle_breakpoint(mock_frame)
|
|
469
|
+
self.mock_console.write_stdout.assert_any_call(" 1. test:func (enabled, hits: 0)")
|
|
470
|
+
|
|
471
|
+
def test_handle_breakpoint_add_breakpoint(self):
|
|
472
|
+
debugger = Debugger()
|
|
473
|
+
|
|
474
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
475
|
+
mock_frame.f_globals = {"__name__": "test"}
|
|
476
|
+
mock_frame.f_code.co_name = "func"
|
|
477
|
+
mock_frame.f_lineno = 10
|
|
478
|
+
|
|
479
|
+
with patch('builtins.input', side_effect=["b new_func", "c"]):
|
|
480
|
+
with patch.object(debugger, '_get_source_lines', return_value=[(10, "test")]):
|
|
481
|
+
debugger.handle_breakpoint(mock_frame)
|
|
482
|
+
self.assertEqual(len(debugger.breakpoints), 1)
|
|
483
|
+
self.assertIn((None, "new_func"), debugger.breakpoints)
|
|
484
|
+
|
|
485
|
+
def test_handle_breakpoint_keyboard_interrupt(self):
|
|
486
|
+
debugger = Debugger()
|
|
487
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
488
|
+
mock_frame.f_globals = {"__name__": "test"}
|
|
489
|
+
mock_frame.f_code.co_name = "func"
|
|
490
|
+
mock_frame.f_lineno = 10
|
|
491
|
+
|
|
492
|
+
with patch('builtins.input', side_effect=KeyboardInterrupt()):
|
|
493
|
+
with patch.object(debugger, '_get_source_lines', return_value=[(10, "test")]):
|
|
494
|
+
debugger.handle_breakpoint(mock_frame)
|
|
495
|
+
|
|
496
|
+
def test_handle_breakpoint_eof(self):
|
|
497
|
+
debugger = Debugger()
|
|
498
|
+
mock_frame = MagicMock(spec=FrameType)
|
|
499
|
+
mock_frame.f_globals = {"__name__": "test"}
|
|
500
|
+
mock_frame.f_code.co_name = "func"
|
|
501
|
+
mock_frame.f_lineno = 10
|
|
502
|
+
|
|
503
|
+
with patch('builtins.input', side_effect=EOFError()):
|
|
504
|
+
with patch.object(debugger, '_get_source_lines', return_value=[(10, "test")]):
|
|
505
|
+
with self.assertRaises(SystemExit):
|
|
506
|
+
debugger.handle_breakpoint(mock_frame)
|
|
@@ -2,6 +2,7 @@ import unittest
|
|
|
2
2
|
from unittest.mock import patch, MagicMock, mock_open
|
|
3
3
|
import json
|
|
4
4
|
from pathlib import Path
|
|
5
|
+
from pygeai.core.base.session import Session
|
|
5
6
|
|
|
6
7
|
from pygeai.evaluation.dataset.clients import EvaluationDatasetClient
|
|
7
8
|
|
|
@@ -12,9 +13,10 @@ class TestEvaluationDatasetClient(unittest.TestCase):
|
|
|
12
13
|
"""
|
|
13
14
|
|
|
14
15
|
def setUp(self):
|
|
15
|
-
self.client = EvaluationDatasetClient()
|
|
16
|
+
self.client = EvaluationDatasetClient(api_key="test-key", base_url="http://test.com", eval_url="http://eval.com")
|
|
16
17
|
self.mock_response = MagicMock()
|
|
17
18
|
self.mock_response.json.return_value = {"id": "dataset-123", "status": "success"}
|
|
19
|
+
self.mock_response.status_code = 200
|
|
18
20
|
|
|
19
21
|
@patch('pygeai.core.services.rest.ApiService.get')
|
|
20
22
|
def test_list_datasets(self, mock_get):
|
|
@@ -2,6 +2,7 @@ import unittest
|
|
|
2
2
|
from unittest.mock import patch, MagicMock
|
|
3
3
|
import json
|
|
4
4
|
|
|
5
|
+
from pygeai.core.base.session import Session
|
|
5
6
|
from pygeai.evaluation.plan.clients import EvaluationPlanClient
|
|
6
7
|
|
|
7
8
|
|
|
@@ -11,9 +12,10 @@ class TestEvaluationPlanClient(unittest.TestCase):
|
|
|
11
12
|
"""
|
|
12
13
|
|
|
13
14
|
def setUp(self):
|
|
14
|
-
self.client = EvaluationPlanClient()
|
|
15
|
+
self.client = EvaluationPlanClient(api_key="test-key", base_url="http://test.com", eval_url="http://eval.com")
|
|
15
16
|
self.mock_response = MagicMock()
|
|
16
|
-
self.mock_response.
|
|
17
|
+
self.mock_response.json.return_value = {"id": "plan-123", "status": "success"}
|
|
18
|
+
self.mock_response.status_code = 200
|
|
17
19
|
|
|
18
20
|
@patch('pygeai.core.services.rest.ApiService.get')
|
|
19
21
|
def test_list_evaluation_plans(self, mock_get):
|