|
3 | 3 | """ |
4 | 4 |
|
5 | 5 | import importlib |
| 6 | +import json |
6 | 7 | from pathlib import Path |
7 | 8 | from unittest.mock import MagicMock, patch |
8 | 9 | import pytest |
@@ -1166,3 +1167,59 @@ def test_api_subscription_required(self): |
1166 | 1167 |
|
1167 | 1168 | assert api.subscriptionRequired is False |
1168 | 1169 | assert api.to_dict()['subscriptionRequired'] is False |
| 1170 | + |
| 1171 | + |
| 1172 | +class TestProjectRootDetection: |
| 1173 | + """Test project root detection logic.""" |
| 1174 | + |
| 1175 | + def test_get_project_root_from_env_var(self, monkeypatch): |
| 1176 | + """Test get_project_root when PROJECT_ROOT env var is set.""" |
| 1177 | + expected_root = Path('/custom/project/root') |
| 1178 | + monkeypatch.setenv('PROJECT_ROOT', str(expected_root)) |
| 1179 | + |
| 1180 | + result = get_project_root() |
| 1181 | + assert result == expected_root |
| 1182 | + |
| 1183 | + def test_get_project_root_without_env_var(self, monkeypatch): |
| 1184 | + """Test get_project_root when PROJECT_ROOT env var is not set.""" |
| 1185 | + monkeypatch.delenv('PROJECT_ROOT', raising=False) |
| 1186 | + |
| 1187 | + # Should return a Path object (doesn't have to exist in tests) |
| 1188 | + result = get_project_root() |
| 1189 | + assert isinstance(result, Path) |
| 1190 | + |
| 1191 | + |
| 1192 | +class TestOutputGetEdgeCases: |
| 1193 | + """Additional edge case tests for Output.get() method.""" |
| 1194 | + |
| 1195 | + def test_output_get_with_missing_label_returns_none(self): |
| 1196 | + """Test Output.get() without label returns None on error.""" |
| 1197 | + output = apimtypes.Output(success=True, text='{}') |
| 1198 | + |
| 1199 | + # Should return None when key is missing and no label is provided |
| 1200 | + result = output.get('nonexistent_key') |
| 1201 | + assert result is None |
| 1202 | + |
| 1203 | + def test_output_get_json_with_syntax_error(self): |
| 1204 | + """Test Output.getJson() returns original value when parsing fails.""" |
| 1205 | + json_text = json.dumps({ |
| 1206 | + 'output1': { |
| 1207 | + 'value': 'invalid syntax {bracket' |
| 1208 | + } |
| 1209 | + }) |
| 1210 | + output = apimtypes.Output(success=True, text=json_text) |
| 1211 | + |
| 1212 | + # Should return the original value when parsing fails |
| 1213 | + result = output.getJson('output1') |
| 1214 | + assert result == 'invalid syntax {bracket' |
| 1215 | + |
| 1216 | + def test_output_get_json_with_non_dict_properties(self): |
| 1217 | + """Test Output.getJson() when properties is not a dict.""" |
| 1218 | + json_text = json.dumps({ |
| 1219 | + 'properties': 'not a dict' |
| 1220 | + }) |
| 1221 | + output = apimtypes.Output(success=True, text=json_text) |
| 1222 | + |
| 1223 | + # Should handle gracefully and return None |
| 1224 | + result = output.getJson('key') |
| 1225 | + assert result is None |
0 commit comments