Skip to content

Commit 5e63cbe

Browse files
committed
test: double-decorated identifier
1 parent 7e82824 commit 5e63cbe

File tree

4 files changed

+81
-5
lines changed

4 files changed

+81
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import functools
2+
3+
4+
class SpyderKernel(IPythonKernel):
5+
"""Spyder kernel for Jupyter."""
6+
7+
shell_class = SpyderShell
8+
@comm_handler
9+
def safe_exec(self, filename):
10+
"""Safely execute a file using IPKernelApp._exec_file."""
11+
self.parent._exec_file(filename)
12+
13+
@comm_handler
14+
@functools.lru_cache(32)
15+
def get_fault_text(self, fault_filename, main_id, ignore_ids):
16+
"""Get fault text from old run."""
17+
# Read file
18+
try:
19+
with open(fault_filename, 'r') as f:
20+
fault = f.read()
21+
except FileNotFoundError:
22+
return
23+
return text
24+
25+
def get_system_threads_id(self):
26+
"""Return the list of system threads id."""
27+
ignore_threads = [
28+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<no-train>
2+
```CEDARScript
3+
-- 1. Move the `get_fault_text` method from the `SpyderKernel` class to be a top-level function
4+
UPDATE METHOD "SpyderKernel.get_fault_text"
5+
FROM FILE "1.py"
6+
MOVE WHOLE
7+
INSERT BEFORE CLASS "SpyderKernel"
8+
RELATIVE INDENTATION 0;
9+
10+
-- 2. Update the copied function to remove references to `self`
11+
UPDATE FUNCTION "get_fault_text"
12+
FROM FILE r"1.py"
13+
REPLACE WHOLE WITH CASE
14+
WHEN REGEX r'''def get_fault_text\(''' THEN SUB
15+
r'''def get_fault_text\(self, fault_filename, main_id, ignore_ids\):'''
16+
r'''def get_fault_text(fault_filename, main_id, ignore_ids):'''
17+
END;
18+
19+
```
20+
</no-train>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import functools
2+
3+
4+
@comm_handler
5+
@functools.lru_cache(32)
6+
def get_fault_text(fault_filename, main_id, ignore_ids):
7+
"""Get fault text from old run."""
8+
# Read file
9+
try:
10+
with open(fault_filename, 'r') as f:
11+
fault = f.read()
12+
except FileNotFoundError:
13+
return
14+
return text
15+
class SpyderKernel(IPythonKernel):
16+
"""Spyder kernel for Jupyter."""
17+
18+
shell_class = SpyderShell
19+
@comm_handler
20+
def safe_exec(self, filename):
21+
"""Safely execute a file using IPKernelApp._exec_file."""
22+
self.parent._exec_file(filename)
23+
24+
25+
def get_system_threads_id(self):
26+
"""Return the list of system threads id."""
27+
ignore_threads = [
28+
]

tests/test_corpus.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from cedarscript_editor import find_commands, CEDARScriptEditor
99

10+
_no_windows = '!nowindows'
1011

1112
def get_test_cases() -> list[str]:
1213
"""Get all test cases from tests/corpus directory.
@@ -41,9 +42,8 @@ def editor(tmp_path_factory):
4142
@pytest.mark.parametrize('test_case', get_test_cases())
4243
def test_corpus(editor: CEDARScriptEditor, test_case: str):
4344
"""Test CEDARScript commands from chat.xml files in corpus."""
44-
if test_case.casefold().endswith('!nowindows'):
45-
if sys.platform == 'win32':
46-
pytest.skip(f"Cannot run under Windows: {test_case.removesuffix('!nowindows')}")
45+
if test_case.casefold().endswith(_no_windows) and sys.platform == 'win32':
46+
pytest.skip(f"Cannot run under Windows: {test_case.removesuffix(_no_windows)}")
4747

4848
try:
4949
corpus_dir = Path(__file__).parent / 'corpus'
@@ -95,10 +95,10 @@ def check_expected_files(dir_path: Path):
9595
continue
9696
# Find corresponding expected file in test directory
9797
rel_path = path.relative_to(editor.root_path)
98-
if str(rel_path).startswith("."):
98+
if str(rel_path).startswith(".") or str(rel_path).endswith("~"):
9999
continue
100100
expected_file = test_dir / f"expected.{rel_path}"
101-
assert expected_file.exists(), f"'expected.*' file not found: {expected_file}"
101+
assert expected_file.exists(), f"'expected.*' file not found: '{expected_file}'"
102102

103103
expected_content = file_to_lines(expected_file, rel_path)
104104
actual_content = file_to_lines(path, rel_path)

0 commit comments

Comments
 (0)