File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 55import pytest
66
77from codeflash .code_utils .config_parser import parse_config_file
8- from codeflash .code_utils .formatter import format_code , sort_imports
8+ from codeflash .code_utils .formatter import format_code , sort_imports , sort_imports_in_place
99
1010
1111def test_remove_duplicate_imports ():
@@ -30,6 +30,23 @@ def test_sorting_imports():
3030 new_code = sort_imports (original_code )
3131 assert new_code == "import os\n import sys\n import unittest\n "
3232
33+ def test_sort_imports_in_place ():
34+ """Test that sorting imports in place in multiple files works."""
35+ original_code = "import sys\n import unittest\n import os\n "
36+ expected_code = "import os\n import sys\n import unittest\n "
37+
38+ with tempfile .TemporaryDirectory () as tmpdir :
39+ file_paths = []
40+ for i in range (3 ):
41+ file_path = Path (tmpdir ) / f"test_file_{ i } .py"
42+ file_path .write_text (original_code , encoding = "utf8" )
43+ file_paths .append (file_path )
44+
45+ sort_imports_in_place (file_paths )
46+
47+ for file_path in file_paths :
48+ assert file_path .read_text (encoding = "utf8" ) == expected_code
49+
3350
3451def test_sort_imports_without_formatting ():
3552 """Test that imports are sorted when formatting is disabled and should_sort_imports is True."""
You can’t perform that action at this time.
0 commit comments