Skip to content

Commit fe0246d

Browse files
committed
file-org-workflows: fix failing tests by using tmp_path
1 parent bd43921 commit fe0246d

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

Beginner/file_organiser/tests/unit/test_file_organiser.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77

88
# Test main with args
9-
def test_path():
10-
amount = main(["/mnt/c/Users/Adam/Desktop/adhd/"])
9+
def test_path(tmp_path):
10+
(tmp_path / "file1.txt").touch()
11+
amount = main([str(tmp_path)])
1112
assert amount > 0
1213

1314

@@ -21,18 +22,22 @@ def test_no_path_recursive():
2122
assert amount > 0
2223

2324

24-
def test_file_not_found():
25+
def test_file_not_found(tmp_path):
2526
with pytest.raises(FileNotFoundError, match="does not exist"):
26-
list(get_files("/tmp/file-org/not-here"))
27+
list(get_files(tmp_path / "not-here"))
2728

2829

29-
def test_not_dir():
30+
def test_not_dir(tmp_path):
31+
file = tmp_path / "text.txt"
32+
file.touch()
3033
with pytest.raises(NotADirectoryError, match="is not a directory"):
31-
list(main(["/tmp/file-org/text.txt"]))
34+
list(main([str(file)]))
3235

3336

34-
def test_with_file():
35-
file_type = main(["--file", "/mnt/c/Users/Adam/Desktop/adhd/20250820_160657.jpg"])
37+
def test_with_file(tmp_path):
38+
fake_jpeg = tmp_path / "test.jpg"
39+
fake_jpeg.write_bytes(b'\xff\xd8\xff\xe0')
40+
file_type = main(["--file", str(fake_jpeg)])
3641
assert file_type == "image/jpeg"
3742

3843

@@ -80,15 +85,17 @@ def test_process_files_recursive(tmp_path):
8085

8186

8287
# Test get_type
83-
def test_get_type_image():
84-
type = get_type("/mnt/c/Users/Adam/Desktop/adhd/20250820_160657.jpg")
88+
def test_get_type_image(tmp_path):
89+
fake_jpeg = tmp_path / "test.jpg"
90+
fake_jpeg.write_bytes(b'\xff\xd8\xff\xe0')
91+
type = get_type(str(fake_jpeg))
8592
assert type == "image/jpeg"
8693

8794

88-
def test_get_type_with_temp_file():
95+
def test_get_type_with_temp_file(tmp_path):
8996
# Create a dummy txt file
9097
txt_content = b"This is a dummy text file."
91-
txt_file = "/tmp/dummy.txt"
98+
txt_file = tmp_path / "dummy.txt"
9299
with open(txt_file, "wb") as f:
93100
f.write(txt_content)
94101
# test with get_type

0 commit comments

Comments
 (0)