Skip to content

Commit 9944617

Browse files
authored
fix: agent is now a top level import (#1236)
# Motivation <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [x] I have added tests for my changes - [x] I have updated the documentation or added new documentation as needed
1 parent 0b990d7 commit 9944617

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

src/codegen/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# file generated by setuptools-scm
22
# don't change, don't track in version control
33

4-
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
4+
from codegen.agents import Agent
5+
6+
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple", "Agent"]
57

68
TYPE_CHECKING = False
79
if TYPE_CHECKING:
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""Test top-level imports from the codegen package."""
2+
3+
import pytest
4+
5+
6+
class TestTopLevelImports:
7+
"""Test that key classes can be imported at the top level of the codegen package."""
8+
9+
def test_can_import_agent_from_top_level(self):
10+
"""Test that Agent class can be imported from the top level."""
11+
# This should work: from codegen import Agent
12+
from codegen import Agent
13+
14+
# Verify Agent class is available
15+
assert Agent is not None
16+
assert callable(Agent)
17+
18+
# Verify it's the same class as importing from the submodule
19+
from codegen.agents.agent import Agent as DirectAgent
20+
assert Agent is DirectAgent
21+
22+
def test_agent_in_all_exports(self):
23+
"""Test that Agent is listed in __all__ exports."""
24+
import codegen
25+
26+
# Agent should be in the __all__ list
27+
assert hasattr(codegen, '__all__')
28+
assert 'Agent' in codegen.__all__
29+
30+
# Agent should be accessible as an attribute
31+
assert hasattr(codegen, 'Agent')
32+
assert codegen.Agent is not None
33+
34+
def test_agent_functionality_works_from_top_level(self):
35+
"""Test that Agent imported from top level is fully functional."""
36+
from codegen import Agent
37+
38+
# Test that the class has expected methods
39+
assert hasattr(Agent, 'run')
40+
assert hasattr(Agent, 'get_status')
41+
assert callable(getattr(Agent, 'run'))
42+
assert callable(getattr(Agent, 'get_status'))
43+
44+
# Test that we can create an Agent instance with None token (it should work)
45+
agent = Agent(token=None)
46+
assert agent is not None
47+
assert hasattr(agent, 'token')
48+
assert agent.token is None
49+
50+
def test_version_still_available(self):
51+
"""Test that version information is still available alongside Agent."""
52+
import codegen
53+
54+
# Version attributes should still be available
55+
assert hasattr(codegen, '__version__')
56+
assert hasattr(codegen, 'version')
57+
assert hasattr(codegen, '__version_tuple__')
58+
assert hasattr(codegen, 'version_tuple')
59+
60+
# They should be in __all__
61+
assert '__version__' in codegen.__all__
62+
assert 'version' in codegen.__all__
63+
assert '__version_tuple__' in codegen.__all__
64+
assert 'version_tuple' in codegen.__all__

0 commit comments

Comments
 (0)