Skip to content

Commit 220589e

Browse files
Fix Windows test failure: use PurePosixPath instead of real directories
The test_only_dots test created a directory named "..." which on Windows is interpreted as parent directory traversal (../..), causing FileExistsError. Since get_project_name_from_dir() only reads Path.name and never accesses the filesystem, all tests now use PurePosixPath synthetic paths instead of creating real directories. Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/b47fb40c-7e7c-44f9-89e3-258b10a5fe34 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
1 parent 78128a6 commit 220589e

1 file changed

Lines changed: 17 additions & 33 deletions

File tree

tests/usethis/_file/test_dir.py

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,38 @@
1-
from pathlib import Path
1+
from pathlib import PurePosixPath
22

33
from usethis._config import usethis_config
44
from usethis._file.dir import get_project_name_from_dir
55

66

77
class TestGetProjectNameFromDir:
8-
def test_simple_name(self, tmp_path: Path):
9-
path = tmp_path / "my_project"
10-
path.mkdir()
11-
with usethis_config.set(project_dir=path):
8+
def test_simple_name(self):
9+
with usethis_config.set(project_dir=PurePosixPath("/fake/my_project")):
1210
assert get_project_name_from_dir() == "my_project"
1311

14-
def test_leading_dot(self, tmp_path: Path):
15-
path = tmp_path / ".github-private"
16-
path.mkdir()
17-
with usethis_config.set(project_dir=path):
12+
def test_leading_dot(self):
13+
with usethis_config.set(project_dir=PurePosixPath("/fake/.github-private")):
1814
assert get_project_name_from_dir() == "github-private"
1915

20-
def test_leading_dots(self, tmp_path: Path):
21-
path = tmp_path / "..hidden"
22-
path.mkdir()
23-
with usethis_config.set(project_dir=path):
16+
def test_leading_dots(self):
17+
with usethis_config.set(project_dir=PurePosixPath("/fake/..hidden")):
2418
assert get_project_name_from_dir() == "hidden"
2519

26-
def test_trailing_dot(self, tmp_path: Path):
27-
path = tmp_path / "project."
28-
path.mkdir()
29-
with usethis_config.set(project_dir=path):
20+
def test_trailing_dot(self):
21+
with usethis_config.set(project_dir=PurePosixPath("/fake/project.")):
3022
assert get_project_name_from_dir() == "project"
3123

32-
def test_leading_and_trailing_non_alphanumeric(self, tmp_path: Path):
33-
path = tmp_path / "-_project_-"
34-
path.mkdir()
35-
with usethis_config.set(project_dir=path):
24+
def test_leading_and_trailing_non_alphanumeric(self):
25+
with usethis_config.set(project_dir=PurePosixPath("/fake/-_project_-")):
3626
assert get_project_name_from_dir() == "project"
3727

38-
def test_only_dots(self, tmp_path: Path):
39-
path = tmp_path / "..."
40-
path.mkdir()
41-
with usethis_config.set(project_dir=path):
28+
def test_only_dots(self):
29+
with usethis_config.set(project_dir=PurePosixPath("/fake/...")):
4230
assert get_project_name_from_dir() == "hello_world"
4331

44-
def test_no_valid_chars(self, tmp_path: Path):
45-
path = tmp_path / "+"
46-
path.mkdir()
47-
with usethis_config.set(project_dir=path):
32+
def test_no_valid_chars(self):
33+
with usethis_config.set(project_dir=PurePosixPath("/fake/+")):
4834
assert get_project_name_from_dir() == "hello_world"
4935

50-
def test_drops_invalid_chars(self, tmp_path: Path):
51-
path = tmp_path / "h-e+l.l_o"
52-
path.mkdir()
53-
with usethis_config.set(project_dir=path):
36+
def test_drops_invalid_chars(self):
37+
with usethis_config.set(project_dir=PurePosixPath("/fake/h-e+l.l_o")):
5438
assert get_project_name_from_dir() == "h-el.l_o"

0 commit comments

Comments
 (0)