Skip to content

Commit 6fe1c06

Browse files
committed
fix: update tests to use write_string_to_file after removing write_tree_to_file
1 parent 8e955a1 commit 6fe1c06

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

tests/test_output_formats.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import yaml
77

88
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
1010

1111
from .conftest import run_treemapper_subprocess
1212
from .utils import load_yaml
@@ -184,30 +184,30 @@ def test_write_tree_text_edge_cases():
184184
assert "file.txt" in non_blank_lines[-1]
185185

186186

187-
def test_write_tree_to_file_creates_parent_dirs(tmp_path):
187+
def test_write_string_to_file_creates_parent_dirs(tmp_path):
188188
tree = {"name": "test", "type": "directory", "children": []}
189189
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")
191191
assert output_file.exists()
192192
assert output_file.parent.exists()
193193

194194

195195
@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):
197197
tree = {"name": "test", "type": "directory", "children": [{"name": "file.txt", "type": "file", "content": "test\n"}]}
198198
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)
200200
assert output_file.exists()
201201
content = output_file.read_text(encoding="utf-8")
202202
assert "test" in content
203203

204204

205-
def test_write_tree_to_file_directory_error(tmp_path):
205+
def test_write_string_to_file_directory_error(tmp_path):
206206
tree = {"name": "test", "type": "directory", "children": []}
207207
output_dir = tmp_path / "output_dir"
208208
output_dir.mkdir()
209209
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")
211211

212212

213213
def test_write_tree_yaml_multiline_content():
@@ -236,15 +236,15 @@ def test_write_tree_json_unicode():
236236

237237

238238
@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):
240240
import sys
241241
from io import StringIO
242242

243243
tree = {"name": "test", "type": "directory", "children": []}
244244
old_stdout = sys.stdout
245245
sys.stdout = StringIO()
246246
try:
247-
write_tree_to_file(tree, None, fmt)
247+
write_string_to_file(tree_to_string(tree, fmt), None, fmt)
248248
output = sys.stdout.getvalue()
249249
finally:
250250
sys.stdout = old_stdout

0 commit comments

Comments
 (0)