Skip to content

Commit 51ee631

Browse files
author
tomcodgen
authored
CG-10301: renaming file path bug (#392)
# Motivation renaming file should set the original file to None # Content UT to verify correct behavior # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [x] I have added tests for my changes - [x] I have updated the documentation or added new documentation as needed
1 parent 2fcdb6b commit 51ee631

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/unit/codegen/sdk/python/file/test_file_update_filepath.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,32 @@ def bar():
105105
assert c.filepath != new_file
106106
assert os.path.exists(tmpdir / foo_filepath)
107107
assert not os.path.exists(tmpdir / new_file)
108+
109+
110+
def test_rename_file_nullifies_old_file(tmpdir) -> None:
111+
# language=python
112+
foo_content = """
113+
def foo():
114+
return 1
115+
"""
116+
foo_filepath = "foo_file.py"
117+
new_filepath = "new_file.py"
118+
119+
with get_codebase_session(tmpdir=tmpdir, files={foo_filepath: foo_content}, commit=True) as codebase:
120+
file = codebase.get_file(foo_filepath)
121+
file.update_filepath(new_filepath)
122+
codebase.commit()
123+
124+
new_file = codebase.get_file(new_filepath, optional=True)
125+
126+
# Check that old file reference is None
127+
old_file = codebase.get_file(foo_filepath, optional=True)
128+
new_file = codebase.get_file(new_filepath)
129+
130+
assert old_file is None
131+
assert new_file is not None
132+
assert new_file.content == foo_content
133+
134+
# Verify file system state
135+
assert not os.path.exists(tmpdir / foo_filepath)
136+
assert os.path.exists(tmpdir / new_filepath)

0 commit comments

Comments
 (0)