|
11 | 11 | import collections.abc |
12 | 12 | collections.MutableMapping = collections.abc.MutableMapping |
13 | 13 |
|
14 | | -def _should_skip_api_test(): |
15 | | - """Check if API tests should be skipped due to invalid/test API key""" |
16 | | - api_key = os.environ.get('OPENAI_API_KEY', '') |
17 | | - return (not api_key or |
18 | | - api_key.startswith('sk-test-') or |
19 | | - api_key == 'nokey' or |
20 | | - api_key == 'test-key' or # Handle truncated test key |
21 | | - 'fallback' in api_key or |
22 | | - 'testing-only' in api_key or |
23 | | - 'not-real' in api_key) |
24 | | - |
25 | 14 | class TestPraisonAIFramework(unittest.TestCase): |
26 | 15 | def test_main_with_agents_advanced(self): |
27 | | - if _should_skip_api_test(): |
28 | | - self.skipTest("Skipping API test due to invalid/test API key") |
29 | | - |
30 | 16 | praisonai = PraisonAI(agent_file="tests/agents-advanced.yaml") |
31 | 17 | result = praisonai.run() |
32 | 18 | print(f"Result: {result}") |
33 | 19 | self.assertIsNotNone(result) |
34 | 20 |
|
35 | 21 | def test_main_with_autogen_framework(self): |
36 | | - if _should_skip_api_test(): |
37 | | - self.skipTest("Skipping API test due to invalid/test API key") |
38 | | - |
39 | 22 | praisonai = PraisonAI(agent_file="tests/autogen-agents.yaml") |
40 | 23 | result = praisonai.run() |
41 | 24 | print(f"Result: {result}") |
42 | 25 | self.assertIsNotNone(result) |
43 | 26 |
|
44 | 27 | def test_main_with_custom_framework(self): |
45 | | - if _should_skip_api_test(): |
46 | | - self.skipTest("Skipping API test due to invalid/test API key") |
47 | | - |
48 | 28 | praisonai = PraisonAI(agent_file="tests/crewai-agents.yaml") |
49 | 29 | result = praisonai.run() |
50 | 30 | print(f"Result: {result}") |
51 | 31 | self.assertIsNotNone(result) |
52 | 32 |
|
53 | 33 | def test_main_with_internet_search_tool(self): |
54 | | - if _should_skip_api_test(): |
55 | | - self.skipTest("Skipping API test due to invalid/test API key") |
56 | | - |
57 | 34 | praisonai = PraisonAI(agent_file="tests/search-tool-agents.yaml") |
58 | 35 | result = praisonai.run() |
59 | 36 | print(f"Result: {result}") |
60 | 37 | self.assertIsNotNone(result) |
61 | 38 |
|
62 | 39 | def test_main_with_built_in_tool(self): |
63 | | - if _should_skip_api_test(): |
64 | | - self.skipTest("Skipping API test due to invalid/test API key") |
65 | | - |
66 | | - praisonai = PraisonAI(agent_file="tests/inbuilt-tool-agents.yaml") |
| 40 | + praisonai = PraisonAI(agent_file="tests/built-in-tools-agents.yaml") |
67 | 41 | result = praisonai.run() |
68 | 42 | print(f"Result: {result}") |
69 | 43 | self.assertIsNotNone(result) |
70 | 44 |
|
71 | 45 |
|
72 | 46 | class TestPraisonAICommandLine(unittest.TestCase): |
73 | 47 | def run_command(self, command): |
74 | | - result = subprocess.run( |
75 | | - command, |
76 | | - stdout=subprocess.PIPE, |
77 | | - stderr=subprocess.STDOUT, |
78 | | - shell=True, |
79 | | - text=True, |
80 | | - env=os.environ.copy() # Fix: Inherit environment variables |
81 | | - ) |
82 | | - return result.stdout |
| 48 | + """Helper method to run CLI commands""" |
| 49 | + result = subprocess.run(command, shell=True, capture_output=True, text=True) |
| 50 | + return result.stdout + result.stderr |
83 | 51 |
|
84 | 52 | def test_praisonai_command(self): |
85 | | - if _should_skip_api_test(): |
86 | | - self.skipTest("Skipping API test due to invalid/test API key") |
87 | | - |
88 | 53 | # Test basic praisonai command |
89 | 54 | command = "praisonai --framework autogen --auto create a 2-agent team to write a simple python game" |
90 | 55 | result = self.run_command(command) |
91 | 56 | print(f"Result: {result}") |
92 | 57 | self.assertIn('TERMINATE', result) |
93 | 58 |
|
94 | 59 | def test_praisonai_init_command(self): |
95 | | - if _should_skip_api_test(): |
96 | | - self.skipTest("Skipping API test due to invalid/test API key") |
97 | | - |
98 | 60 | # Test praisonai --init command |
99 | 61 | command = "praisonai --framework autogen --init create a 2-agent team to write a simple python game" |
100 | 62 | result = self.run_command(command) |
101 | 63 | print(f"Result: {result}") |
102 | 64 | self.assertIn('created successfully', result) |
103 | 65 |
|
104 | 66 | class TestExamples(unittest.TestCase): |
105 | | - def test_basic_example(self): |
106 | | - if _should_skip_api_test(): |
107 | | - self.skipTest("Skipping due to no valid API key provided") |
108 | | - |
109 | | - # Test the basic example function |
110 | | - try: |
111 | | - result = main() |
112 | | - self.assertIsNotNone(result) |
113 | | - # Check if result contains expected success indicators or output |
114 | | - self.assertTrue( |
115 | | - isinstance(result, str) and ( |
116 | | - "completed successfully" in result or |
117 | | - "Task Output" in result or |
118 | | - len(result.strip()) > 0 |
119 | | - ), |
120 | | - f"Expected meaningful result, got: {result}" |
121 | | - ) |
122 | | - except Exception as e: |
123 | | - # Fallback skip for API errors |
124 | | - if any(error in str(e) for error in ['Invalid API Key', 'AuthenticationError', '401']): |
125 | | - self.skipTest(f"Skipping due to API key issue: {e}") |
126 | | - else: |
127 | | - raise |
128 | | - |
129 | 67 | def test_advanced_example(self): |
130 | | - if _should_skip_api_test(): |
131 | | - self.skipTest("Skipping due to no valid API key provided") |
132 | | - |
133 | | - # Test the advanced example function |
134 | | - try: |
135 | | - result = advanced() |
136 | | - self.assertIsNotNone(result) |
137 | | - # Check if result contains expected success indicators or output |
138 | | - self.assertTrue( |
139 | | - isinstance(result, str) and ( |
140 | | - "completed successfully" in result or |
141 | | - "Task Output" in result or |
142 | | - len(result.strip()) > 0 |
143 | | - ), |
144 | | - f"Expected meaningful result, got: {result}" |
145 | | - ) |
146 | | - except Exception as e: |
147 | | - # Fallback skip for API errors |
148 | | - if any(error in str(e) for error in ['Invalid API Key', 'AuthenticationError', '401']): |
149 | | - self.skipTest(f"Skipping due to API key issue: {e}") |
150 | | - else: |
151 | | - raise |
| 68 | + result = advanced() |
| 69 | + print(f"Result: {result}") |
| 70 | + self.assertIsNotNone(result) |
152 | 71 |
|
153 | 72 | def test_auto_example(self): |
154 | | - if _should_skip_api_test(): |
155 | | - self.skipTest("Skipping API test due to invalid/test API key") |
156 | | - |
157 | 73 | result = auto() |
158 | 74 | print(f"Result: {result}") |
159 | 75 | self.assertIsNotNone(result) |
160 | 76 |
|
| 77 | + def test_basic_example(self): |
| 78 | + result = main() |
| 79 | + print(f"Result: {result}") |
| 80 | + self.assertIsNotNone(result) |
| 81 | + |
161 | 82 | if __name__ == '__main__': |
162 | 83 | # runner = XMLTestRunner(output='test-reports') |
163 | 84 | unittest.main() |
|
0 commit comments