|
1 | | -import os |
| 1 | +import re |
2 | 2 | import shutil |
3 | 3 | import tempfile |
4 | 4 | import pytest |
@@ -65,23 +65,38 @@ def copy_files(src_dir: Path, dst_dir: Path): |
65 | 65 | # Find and apply commands |
66 | 66 | commands = list(find_commands(chat_xml)) |
67 | 67 | assert commands, "No commands found in chat.xml" |
68 | | - editor.apply_commands(commands) |
| 68 | + |
| 69 | + # Check if test expects an exception |
| 70 | + throws_match = re.search(r'<throws value="([^"]+)">', chat_xml) |
| 71 | + if throws_match: |
| 72 | + expected_error = throws_match.group(1) |
| 73 | + with pytest.raises(Exception) as excinfo: |
| 74 | + editor.apply_commands(commands) |
| 75 | + # TODO excinfo.value is '<description>Unable to find function 'does-not-exist'</description>' |
| 76 | + actual_error = str(excinfo.value) |
| 77 | + match re.search(r'<description>(.+)</description>', actual_error): |
| 78 | + case None: |
| 79 | + pass |
| 80 | + case _ as found: |
| 81 | + actual_error = found.group(1) |
| 82 | + assert actual_error == expected_error, f"Expected error '{expected_error}', but got '{actual_error}'" |
| 83 | + else: |
| 84 | + editor.apply_commands(commands) |
69 | 85 |
|
70 | | - # For each file in the scratch directory, check its expected version |
71 | 86 | def check_expected_files(dir_path: Path): |
72 | 87 | for path in dir_path.iterdir(): |
73 | 88 | if path.is_dir(): |
74 | 89 | check_expected_files(path) |
75 | | - else: |
76 | | - # Find corresponding expected file in test directory |
77 | | - rel_path = path.relative_to(editor.root_path) |
78 | | - expected_file = test_dir / f"expected.{rel_path}" |
79 | | - assert expected_file.exists(), f"Expected file not found: {expected_file}" |
| 90 | + continue |
| 91 | + # Find corresponding expected file in test directory |
| 92 | + rel_path = path.relative_to(editor.root_path) |
| 93 | + expected_file = test_dir / f"expected.{rel_path}" |
| 94 | + assert expected_file.exists(), f"Expected file not found: {expected_file}" |
80 | 95 |
|
81 | | - expected_content = f"[{rel_path}] \n" + expected_file.read_text() |
82 | | - result_content = f"[{rel_path}] \n" + path.read_text() |
83 | | - assert result_content.strip() == expected_content.strip(), \ |
84 | | - f"Output does not match expected content for {rel_path}" |
| 96 | + expected_content = f"[{rel_path}] \n" + expected_file.read_text() |
| 97 | + result_content = f"[{rel_path}] \n" + path.read_text() |
| 98 | + assert result_content.strip() == expected_content.strip(), \ |
| 99 | + f"Output does not match expected content for {rel_path}" |
85 | 100 |
|
86 | 101 | check_expected_files(editor.root_path) |
87 | 102 |
|
|
0 commit comments