12
12
13
13
14
14
@pytest .fixture
15
- def mock_codebase_context (tmp_path ):
15
+ def mock_codebase_graph (tmp_path ):
16
16
mock = MagicMock (spec = CodebaseContext )
17
17
mock .transaction_manager = MagicMock ()
18
18
mock .config = CodebaseConfig ()
19
19
mock .repo_path = tmp_path
20
20
mock .to_absolute = types .MethodType (CodebaseContext .to_absolute , mock )
21
21
mock .to_relative = types .MethodType (CodebaseContext .to_relative , mock )
22
+ mock .io = MagicMock ()
22
23
return mock
23
24
24
25
@@ -34,17 +35,17 @@ def dir_path(tmp_path):
34
35
35
36
@pytest .fixture
36
37
def sub_dir (subdir_path , tmp_path ):
37
- return Directory (path = subdir_path .absolute (), dirpath = subdir_path .relative_to (tmp_path ), parent = None )
38
+ return Directory (path = subdir_path .absolute (), dirpath = str ( subdir_path .relative_to (tmp_path ) ), parent = None )
38
39
39
40
40
41
@pytest .fixture
41
42
def mock_file (dir_path , mock_codebase_graph ):
42
- return File (filepath = dir_path / "example.py" , G = mock_codebase_graph )
43
+ return File (filepath = dir_path / "example.py" , ctx = mock_codebase_graph )
43
44
44
45
45
46
@pytest .fixture
46
47
def mock_directory (tmp_path , dir_path , sub_dir , mock_file ):
47
- directory = Directory (path = dir_path .absolute (), dirpath = dir_path .relative_to (tmp_path ), parent = None )
48
+ directory = Directory (path = dir_path .absolute (), dirpath = str ( dir_path .relative_to (tmp_path ) ), parent = None )
48
49
directory .add_file (mock_file )
49
50
directory .add_subdirectory (sub_dir )
50
51
return directory
@@ -53,7 +54,7 @@ def mock_directory(tmp_path, dir_path, sub_dir, mock_file):
53
54
def test_directory_init (tmp_path , mock_directory ):
54
55
"""Test initialization of Directory object."""
55
56
assert mock_directory .path == tmp_path / "mock_dir"
56
- assert mock_directory .dirpath == Path ( "mock_dir" )
57
+ assert mock_directory .dirpath == "mock_dir"
57
58
assert mock_directory .parent is None
58
59
assert len (mock_directory .items ) == 2
59
60
assert mock_directory .items ["subdir" ] is not None
@@ -67,7 +68,7 @@ def test_name_property(mock_directory):
67
68
68
69
def test_add_and_file (mock_directory , mock_codebase_graph ):
69
70
"""Test adding a file to the directory."""
70
- mock_file = File (filepath = Path ("mock_dir/example_2.py" ), G = mock_codebase_graph )
71
+ mock_file = File (filepath = Path ("mock_dir/example_2.py" ), ctx = mock_codebase_graph )
71
72
mock_directory .add_file (mock_file )
72
73
rel_path = os .path .relpath (mock_file .file_path , mock_directory .dirpath )
73
74
assert rel_path in mock_directory .items
@@ -84,7 +85,7 @@ def test_remove_file(mock_directory, mock_file):
84
85
85
86
def test_remove_file_by_path (mock_directory , mock_file ):
86
87
"""Test removing a file by path."""
87
- mock_directory .remove_file_by_path (mock_file .file_path )
88
+ mock_directory .remove_file_by_path (Path ( mock_file .file_path ) )
88
89
89
90
rel_path = os .path .relpath (mock_file .file_path , mock_directory .dirpath )
90
91
assert rel_path not in mock_directory .items
@@ -108,7 +109,7 @@ def test_get_file_not_found(mock_directory):
108
109
def test_add_subdirectory (mock_directory , dir_path ):
109
110
"""Test adding a subdirectory."""
110
111
new_subdir_path = dir_path / "new_subdir"
111
- subdir = Directory (path = new_subdir_path .absolute (), dirpath = new_subdir_path .relative_to (dir_path ), parent = mock_directory )
112
+ subdir = Directory (path = new_subdir_path .absolute (), dirpath = str ( new_subdir_path .relative_to (dir_path ) ), parent = mock_directory )
112
113
mock_directory .add_subdirectory (subdir )
113
114
rel_path = os .path .relpath (subdir .dirpath , mock_directory .dirpath )
114
115
assert rel_path in mock_directory .items
@@ -143,7 +144,7 @@ def test_files_property(mock_directory, sub_dir, mock_codebase_graph):
143
144
all_files = mock_directory .files
144
145
assert len (all_files ) == 1
145
146
146
- new_file = File (filepath = Path ("mock_dir/example_2.py" ), G = mock_codebase_graph )
147
+ new_file = File (filepath = Path ("mock_dir/example_2.py" ), ctx = mock_codebase_graph )
147
148
sub_dir .add_file (new_file )
148
149
149
150
all_files = mock_directory .files
@@ -162,7 +163,7 @@ def test_subdirectories_property(mock_directory, sub_dir):
162
163
assert len (all_subdirs ) == 1
163
164
assert sub_dir in all_subdirs
164
165
165
- new_sub_dir = Directory (path = sub_dir .path / "new_subdir" , dirpath = sub_dir .dirpath / "new_subdir" , parent = sub_dir )
166
+ new_sub_dir = Directory (path = sub_dir .path / "new_subdir" , dirpath = str ( Path ( sub_dir .dirpath ) / "new_subdir" ) , parent = sub_dir )
166
167
sub_dir .add_subdirectory (new_sub_dir )
167
168
168
169
all_subdirs = mock_directory .subdirectories
0 commit comments