test: update test expectations for global assignment placement changes
Update test_no_targets_found to expect outer class to be kept when targeting nested class methods, and add test for nonexistent targets. Update test_multi_file_replcement01 to expect global assignments at module end rather than after imports.
This commit is contained in:
parent
50fba096f7
commit
257c5f2b8f
2 changed files with 30 additions and 3 deletions
|
|
@ -218,8 +218,32 @@ def test_no_targets_found() -> None:
|
|||
def target(self):
|
||||
pass
|
||||
"""
|
||||
# Nested class methods (MyClass.Inner.target) aren't directly targetable,
|
||||
# but the outer class is kept when the qualified name starts with it.
|
||||
# This is because the dependency tracking marks "MyClass" as used when it
|
||||
# sees "MyClass.Inner.target" as a target function.
|
||||
result = parse_code_and_prune_cst(dedent(code),CodeContextType.READ_WRITABLE, {"MyClass.Inner.target"})
|
||||
expected = dedent("""
|
||||
class MyClass:
|
||||
def method(self):
|
||||
pass
|
||||
|
||||
class Inner:
|
||||
def target(self):
|
||||
pass
|
||||
""")
|
||||
assert result.strip() == expected.strip()
|
||||
|
||||
|
||||
def test_no_targets_found_raises_for_nonexistent() -> None:
|
||||
"""Test that ValueError is raised when the target function doesn't exist at all."""
|
||||
code = """
|
||||
class MyClass:
|
||||
def method(self):
|
||||
pass
|
||||
"""
|
||||
with pytest.raises(ValueError, match="No target functions found in the provided code"):
|
||||
parse_code_and_prune_cst(dedent(code),CodeContextType.READ_WRITABLE, {"MyClass.Inner.target"})
|
||||
parse_code_and_prune_cst(dedent(code),CodeContextType.READ_WRITABLE, {"NonExistent.target"})
|
||||
|
||||
|
||||
def test_module_var() -> None:
|
||||
|
|
|
|||
|
|
@ -125,13 +125,14 @@ def _get_string_usage(text: str) -> Usage:
|
|||
helper_file.unlink(missing_ok=True)
|
||||
main_file.unlink(missing_ok=True)
|
||||
|
||||
# Global assignments are now inserted AFTER class/function definitions
|
||||
# to prevent NameError when they reference classes or functions.
|
||||
# See commit 50fba096 for details.
|
||||
expected_helper = """import re
|
||||
from collections.abc import Sequence
|
||||
|
||||
from pydantic_ai_slim.pydantic_ai.messages import BinaryContent, UserContent
|
||||
|
||||
_translate_table = {ord(c): ord(' ') for c in ' \\t\\n\\r\\x0b\\x0c",.:'}
|
||||
|
||||
_TOKEN_SPLIT_RE = re.compile(r'[\\s",.:]+')
|
||||
|
||||
def _estimate_string_tokens(content: str | Sequence[UserContent]) -> int:
|
||||
|
|
@ -158,6 +159,8 @@ def _estimate_string_tokens(content: str | Sequence[UserContent]) -> int:
|
|||
tokens += len(part.data)
|
||||
|
||||
return tokens
|
||||
|
||||
_translate_table = {ord(c): ord(' ') for c in ' \\t\\n\\r\\x0b\\x0c",.:'}
|
||||
"""
|
||||
|
||||
assert new_code.rstrip() == original_main.rstrip() # No Change
|
||||
|
|
|
|||
Loading…
Reference in a new issue