Skip to content

Commit 42f76be

Browse files
Fix basedpyright: replace PurePosixPath with Path/str in tests
PurePosixPath is not assignable to Path | str | None. Use tmp_path / "name" (Path without mkdir) for most tests, and string paths for Windows-problematic names ("..." and "project.") since usethis_config .set() accepts str and converts to Path internally. Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/06111449-4dd0-43b5-87cf-f13293af9a57 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
1 parent 220589e commit 42f76be

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

tests/usethis/_file/test_dir.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
from pathlib import PurePosixPath
1+
from pathlib import Path
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):
9-
with usethis_config.set(project_dir=PurePosixPath("/fake/my_project")):
8+
def test_simple_name(self, tmp_path: Path):
9+
with usethis_config.set(project_dir=tmp_path / "my_project"):
1010
assert get_project_name_from_dir() == "my_project"
1111

12-
def test_leading_dot(self):
13-
with usethis_config.set(project_dir=PurePosixPath("/fake/.github-private")):
12+
def test_leading_dot(self, tmp_path: Path):
13+
with usethis_config.set(project_dir=tmp_path / ".github-private"):
1414
assert get_project_name_from_dir() == "github-private"
1515

16-
def test_leading_dots(self):
17-
with usethis_config.set(project_dir=PurePosixPath("/fake/..hidden")):
16+
def test_leading_dots(self, tmp_path: Path):
17+
with usethis_config.set(project_dir=tmp_path / "..hidden"):
1818
assert get_project_name_from_dir() == "hidden"
1919

2020
def test_trailing_dot(self):
21-
with usethis_config.set(project_dir=PurePosixPath("/fake/project.")):
21+
with usethis_config.set(project_dir="/fake/project."):
2222
assert get_project_name_from_dir() == "project"
2323

24-
def test_leading_and_trailing_non_alphanumeric(self):
25-
with usethis_config.set(project_dir=PurePosixPath("/fake/-_project_-")):
24+
def test_leading_and_trailing_non_alphanumeric(self, tmp_path: Path):
25+
with usethis_config.set(project_dir=tmp_path / "-_project_-"):
2626
assert get_project_name_from_dir() == "project"
2727

2828
def test_only_dots(self):
29-
with usethis_config.set(project_dir=PurePosixPath("/fake/...")):
29+
with usethis_config.set(project_dir="/fake/..."):
3030
assert get_project_name_from_dir() == "hello_world"
3131

32-
def test_no_valid_chars(self):
33-
with usethis_config.set(project_dir=PurePosixPath("/fake/+")):
32+
def test_no_valid_chars(self, tmp_path: Path):
33+
with usethis_config.set(project_dir=tmp_path / "+"):
3434
assert get_project_name_from_dir() == "hello_world"
3535

36-
def test_drops_invalid_chars(self):
37-
with usethis_config.set(project_dir=PurePosixPath("/fake/h-e+l.l_o")):
36+
def test_drops_invalid_chars(self, tmp_path: Path):
37+
with usethis_config.set(project_dir=tmp_path / "h-e+l.l_o"):
3838
assert get_project_name_from_dir() == "h-el.l_o"

0 commit comments

Comments
 (0)