|
6 | 6 | import yaml |
7 | 7 |
|
8 | 8 | from treemapper import map_directory, to_json, to_text, to_yaml |
9 | | -from treemapper.writer import write_tree_json, write_tree_text, write_tree_to_file, write_tree_yaml |
| 9 | +from treemapper.writer import tree_to_string, write_string_to_file, write_tree_json, write_tree_text, write_tree_yaml |
10 | 10 |
|
11 | 11 | from .conftest import run_treemapper_subprocess |
12 | 12 | from .utils import load_yaml |
@@ -184,30 +184,30 @@ def test_write_tree_text_edge_cases(): |
184 | 184 | assert "file.txt" in non_blank_lines[-1] |
185 | 185 |
|
186 | 186 |
|
187 | | -def test_write_tree_to_file_creates_parent_dirs(tmp_path): |
| 187 | +def test_write_string_to_file_creates_parent_dirs(tmp_path): |
188 | 188 | tree = {"name": "test", "type": "directory", "children": []} |
189 | 189 | output_file = tmp_path / "nested" / "dir" / "output.yaml" |
190 | | - write_tree_to_file(tree, output_file, "yaml") |
| 190 | + write_string_to_file(tree_to_string(tree, "yaml"), output_file, "yaml") |
191 | 191 | assert output_file.exists() |
192 | 192 | assert output_file.parent.exists() |
193 | 193 |
|
194 | 194 |
|
195 | 195 | @pytest.mark.parametrize("fmt", ["yaml", "json", "txt"]) |
196 | | -def test_write_tree_to_file_formats(tmp_path, fmt): |
| 196 | +def test_write_string_to_file_formats(tmp_path, fmt): |
197 | 197 | tree = {"name": "test", "type": "directory", "children": [{"name": "file.txt", "type": "file", "content": "test\n"}]} |
198 | 198 | output_file = tmp_path / f"output.{fmt}" |
199 | | - write_tree_to_file(tree, output_file, fmt) |
| 199 | + write_string_to_file(tree_to_string(tree, fmt), output_file, fmt) |
200 | 200 | assert output_file.exists() |
201 | 201 | content = output_file.read_text(encoding="utf-8") |
202 | 202 | assert "test" in content |
203 | 203 |
|
204 | 204 |
|
205 | | -def test_write_tree_to_file_directory_error(tmp_path): |
| 205 | +def test_write_string_to_file_directory_error(tmp_path): |
206 | 206 | tree = {"name": "test", "type": "directory", "children": []} |
207 | 207 | output_dir = tmp_path / "output_dir" |
208 | 208 | output_dir.mkdir() |
209 | 209 | with pytest.raises(IOError, match="Is a directory"): |
210 | | - write_tree_to_file(tree, output_dir, "yaml") |
| 210 | + write_string_to_file(tree_to_string(tree, "yaml"), output_dir, "yaml") |
211 | 211 |
|
212 | 212 |
|
213 | 213 | def test_write_tree_yaml_multiline_content(): |
@@ -236,15 +236,15 @@ def test_write_tree_json_unicode(): |
236 | 236 |
|
237 | 237 |
|
238 | 238 | @pytest.mark.parametrize("fmt", ["yaml", "json", "txt"]) |
239 | | -def test_write_tree_to_file_stdout(fmt): |
| 239 | +def test_write_string_to_file_stdout(fmt): |
240 | 240 | import sys |
241 | 241 | from io import StringIO |
242 | 242 |
|
243 | 243 | tree = {"name": "test", "type": "directory", "children": []} |
244 | 244 | old_stdout = sys.stdout |
245 | 245 | sys.stdout = StringIO() |
246 | 246 | try: |
247 | | - write_tree_to_file(tree, None, fmt) |
| 247 | + write_string_to_file(tree_to_string(tree, fmt), None, fmt) |
248 | 248 | output = sys.stdout.getvalue() |
249 | 249 | finally: |
250 | 250 | sys.stdout = old_stdout |
|
0 commit comments