Skip to content

Commit c375378

Browse files
committed
Convert temp_dir to Path in unit tests
1 parent 145dc85 commit c375378

3 files changed

Lines changed: 18 additions & 19 deletions

File tree

tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from pathlib import Path
23
from tempfile import TemporaryDirectory
34
from typing import Iterator
45
from unittest.mock import patch
@@ -32,6 +33,6 @@ def opt_update_expected_outputs(request: pytest.FixtureRequest) -> bool:
3233

3334

3435
@pytest.fixture
35-
def temp_dir() -> Iterator[str]:
36+
def temp_dir() -> Iterator[Path]:
3637
with TemporaryDirectory(prefix="cookie-python.unittest.") as td:
37-
yield os.path.join(td)
38+
yield Path(td)

tests/test_manage_cookie.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,25 @@
2020

2121
@pytest.fixture
2222
def environ() -> Iterator[None]:
23-
env = os.environ.copy()
24-
env.update(
25-
dict(
26-
GIT_AUTHOR_NAME=AUTHOR_NAME,
27-
GIT_AUTHOR_EMAIL=AUTHOR_EMAIL,
28-
GIT_COMMITTER_NAME=AUTHOR_NAME,
29-
GIT_COMMITTER_EMAIL=AUTHOR_EMAIL,
30-
GITHUB_API_TOKEN="unittest_token",
31-
)
23+
add_values = dict(
24+
GIT_AUTHOR_NAME=AUTHOR_NAME,
25+
GIT_AUTHOR_EMAIL=AUTHOR_EMAIL,
26+
GIT_COMMITTER_NAME=AUTHOR_NAME,
27+
GIT_COMMITTER_EMAIL=AUTHOR_EMAIL,
28+
GITHUB_API_TOKEN="unittest_token",
3229
)
33-
with patch.dict(os.environ, env):
30+
with patch.dict(os.environ, add_values):
3431
yield
3532

3633

3734
@pytest.fixture(params=["@"])
3835
def new_cookie(
39-
request: pytest.FixtureRequest, environ: None, temp_dir: str
36+
request: pytest.FixtureRequest, environ: None, temp_dir: Path
4037
) -> Iterator[Path]:
4138
testargs = [
4239
"new-cookie",
4340
"--local",
44-
temp_dir,
41+
str(temp_dir),
4542
"--",
4643
"-d",
4744
"-y",
@@ -60,7 +57,7 @@ def new_cookie(
6057
]
6158
with patch.object(sys, "argv", testargs):
6259
new_cookie_main()
63-
yield Path(temp_dir) / PROJECT_NAME
60+
yield temp_dir / PROJECT_NAME
6461

6562

6663
@pytest.fixture(autouse=True)
@@ -86,7 +83,7 @@ def mock_pygithub(new_cookie: Path) -> Iterator[MagicMock]:
8683

8784

8885
@pytest.fixture
89-
def new_cookie_with_lock(new_cookie: Path, temp_dir: str) -> Iterator[Path]:
86+
def new_cookie_with_lock(new_cookie: Path, temp_dir: Path) -> Iterator[Path]:
9087
for cmd in (
9188
["poetry", "sync"],
9289
["git", "add", "poetry.lock"],

tests/test_new_cookie.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
import os
33
import subprocess
44
import sys
5+
from pathlib import Path
56
from unittest import mock
67

78
from cookie_python.new import main
89

910

10-
def test_new_cookie_create(temp_dir: str) -> None:
11+
def test_new_cookie_create(temp_dir: Path) -> None:
1112
testargs = [
1213
"new-cookie",
1314
"--local",
14-
temp_dir,
15+
str(temp_dir),
1516
"--",
1617
"-d",
1718
"-y",
@@ -29,7 +30,7 @@ def test_new_cookie_create(temp_dir: str) -> None:
2930
]
3031
with mock.patch.object(sys, "argv", testargs):
3132
main()
32-
project_dir = os.path.join(temp_dir, "unit-test-1")
33+
project_dir = temp_dir / "unit-test-1"
3334
assert os.path.isdir(project_dir)
3435
assert not (
3536
subprocess.check_output(

0 commit comments

Comments
 (0)