8OI-520 regression tests — verify ``fix_func_pattern`` also handles
9``async def`` functions (previously only ``ast.FunctionDef`` was inspected,
10so async functions were silently skipped).
14- Plain async function missing ``func = "..."`` gets one injected.
15- Async function that already has the pattern is unchanged.
16- Mixed sync + async file: both get fixed in the same pass.
17- Async method inside a class is also covered.
21Domain: TESTS.FORMATTER
24 L3 — assertion details
29- The formatter must treat ``async def`` bodies identically to ``def`` bodies.
32from pathlib
import Path
38 lines = content.split(
"\n")
39 while len(lines) < 22:
40 lines.append(
"# padding")
41 return "\n".join(lines)
45 temp_project_root: Path, formatter_ctx_fix: FormatterContext
47 test_file = temp_project_root /
"async_single.py"
49 "#!/usr/bin/env python3\n"
50 "from oc_diagnostics import _dbg\n"
52 "async def my_async():\n"
53 " _dbg('TEST', 'start')\n"
56 test_file.write_text(content, encoding=
"utf-8")
58 changed, new_content, _ = fix_func_pattern(test_file, content, formatter_ctx_fix)
60 assert changed
is True
61 assert 'func = "my_async"' in new_content
65 temp_project_root: Path, formatter_ctx_fix: FormatterContext
67 test_file = temp_project_root /
"async_ok.py"
69 "#!/usr/bin/env python3\n"
70 "from oc_diagnostics import _dbg\n"
72 "async def ok_async():\n"
73 ' func = "ok_async"\n'
74 " _dbg('TEST', func, 'msg', 2)\n"
77 test_file.write_text(content, encoding=
"utf-8")
79 changed, _, _ = fix_func_pattern(test_file, content, formatter_ctx_fix)
81 assert changed
is False
85 temp_project_root: Path, formatter_ctx_fix: FormatterContext
87 test_file = temp_project_root /
"mixed.py"
89 "#!/usr/bin/env python3\n"
90 "from oc_diagnostics import _dbg\n"
93 " _dbg('TEST', 'a')\n"
96 "async def async_func():\n"
97 " _dbg('TEST', 'b')\n"
100 test_file.write_text(content, encoding=
"utf-8")
102 changed, new_content, _ = fix_func_pattern(test_file, content, formatter_ctx_fix)
104 assert changed
is True
105 assert 'func = "sync_func"' in new_content
106 assert 'func = "async_func"' in new_content
110 temp_project_root: Path, formatter_ctx_fix: FormatterContext
112 test_file = temp_project_root /
"async_method.py"
114 "#!/usr/bin/env python3\n"
115 "from oc_diagnostics import _dbg\n"
118 " async def bar(self):\n"
119 " _dbg('TEST', 'method')\n"
122 test_file.write_text(content, encoding=
"utf-8")
124 changed, new_content, _ = fix_func_pattern(test_file, content, formatter_ctx_fix)
126 assert changed
is True
127 assert 'func = "bar"' in new_content