Skip to content

Commit 646f69b

Browse files
committed
pytest_plugin: pydocstyle manual fixes
1 parent 66ddeb5 commit 646f69b

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

src/libvcs/pytest_plugin.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""pytest fixtures. Live inside libvcs for doctest."""
1+
"""pytest plugin for VCS Repository testing and management."""
22
import functools
33
import getpass
44
import pathlib
@@ -20,7 +20,10 @@
2020

2121

2222
class MaxUniqueRepoAttemptsExceeded(exc.LibVCSException):
23+
"""Raised when exceeded threshold of attempts to find a unique repo destination."""
24+
2325
def __init__(self, attempts: int, *args: object):
26+
"""Raise LibVCSException exception with message including attempts tried."""
2427
return super().__init__(
2528
f"Could not find unused repo destination (attempts: {attempts})"
2629
)
@@ -38,22 +41,27 @@ def __init__(self, attempts: int, *args: object):
3841

3942

4043
class RandomStrSequence:
44+
"""Create a random string sequence."""
45+
4146
def __init__(
4247
self, characters: str = "abcdefghijklmnopqrstuvwxyz0123456789_"
4348
) -> None:
4449
self.characters: str = characters
4550

4651
def __iter__(self) -> "RandomStrSequence":
52+
"""Iterate across generated strings."""
4753
return self
4854

4955
def __next__(self) -> str:
56+
"""Iterate to next string possibility."""
5057
return "".join(random.sample(self.characters, k=8))
5158

5259

5360
namer = RandomStrSequence()
5461

5562

5663
def pytest_ignore_collect(collection_path: pathlib.Path, config: pytest.Config) -> bool:
64+
"""Skip tests if VCS binaries are missing."""
5765
if not shutil.which("svn") and any(
5866
needle in str(collection_path) for needle in ["svn", "subversion"]
5967
):
@@ -70,17 +78,19 @@ def pytest_ignore_collect(collection_path: pathlib.Path, config: pytest.Config)
7078

7179
@pytest.fixture(scope="session")
7280
def home_path(tmp_path_factory: pytest.TempPathFactory) -> pathlib.Path:
81+
"""Return temporary directory to use as user's home path, pytest fixture."""
7382
return tmp_path_factory.mktemp("home")
7483

7584

7685
@pytest.fixture(scope="session")
7786
def home_user_name() -> str:
78-
"""Default username to set for :func:`user_path` fixture."""
87+
"""Return default username to set for :func:`user_path` fixture."""
7988
return getpass.getuser()
8089

8190

8291
@pytest.fixture(scope="session")
8392
def user_path(home_path: pathlib.Path, home_user_name: str) -> pathlib.Path:
93+
"""Return user's home directory, pytest fixture."""
8494
p = home_path / home_user_name
8595
p.mkdir()
8696
return p
@@ -91,12 +101,14 @@ def set_home(
91101
monkeypatch: pytest.MonkeyPatch,
92102
user_path: pathlib.Path,
93103
) -> None:
104+
"""Set home directory, pytest fixture."""
94105
monkeypatch.setenv("HOME", str(user_path))
95106

96107

97108
@pytest.fixture
98109
@skip_if_git_missing
99110
def gitconfig(user_path: pathlib.Path, set_home: pathlib.Path) -> pathlib.Path:
111+
"""Return git configuration, pytest fixture."""
100112
gitconfig = user_path / ".gitconfig"
101113
user_email = "libvcs@git-pull.com"
102114
gitconfig.write_text(
@@ -131,6 +143,7 @@ def gitconfig(user_path: pathlib.Path, set_home: pathlib.Path) -> pathlib.Path:
131143
@pytest.fixture
132144
@skip_if_hg_missing
133145
def hgconfig(user_path: pathlib.Path, set_home: pathlib.Path) -> pathlib.Path:
146+
"""Return Mercurial configuration, pytest fixture."""
134147
hgrc = user_path / ".hgrc"
135148
hgrc.write_text(
136149
textwrap.dedent(
@@ -179,6 +192,7 @@ def clean() -> None:
179192

180193

181194
def unique_repo_name(remote_repos_path: pathlib.Path, max_retries: int = 15) -> str:
195+
"""Attempt to find and return a unique repo named based on path."""
182196
attempts = 1
183197
while True:
184198
if attempts > max_retries:
@@ -195,18 +209,24 @@ def unique_repo_name(remote_repos_path: pathlib.Path, max_retries: int = 15) ->
195209

196210

197211
class CreateRepoPostInitFn(Protocol):
212+
"""Typing for VCS repo creation callback."""
213+
198214
def __call__(self, remote_repo_path: pathlib.Path) -> None:
215+
"""Ran after creating a repo from pytest fixture."""
199216
...
200217

201218

202219
class CreateRepoPytestFixtureFn(Protocol):
220+
"""Typing for VCS pytest fixture callback."""
221+
203222
def __call__(
204223
self,
205224
remote_repos_path: pathlib.Path = ...,
206225
remote_repo_name: Optional[str] = ...,
207226
remote_repo_post_init: Optional[CreateRepoPostInitFn] = ...,
208227
init_cmd_args: InitCmdArgs = ...,
209228
) -> pathlib.Path:
229+
"""py.test fixture function to create a project in a remote repo."""
210230
...
211231

212232

@@ -235,7 +255,7 @@ def _create_git_remote_repo(
235255
def create_git_remote_repo(
236256
remote_repos_path: pathlib.Path,
237257
) -> CreateRepoPytestFixtureFn:
238-
"""Factory. Create git remote repo to for clone / push purposes."""
258+
"""Return factory to create git remote repo to for clone / push purposes."""
239259

240260
def fn(
241261
remote_repos_path: pathlib.Path = remote_repos_path,
@@ -256,6 +276,7 @@ def fn(
256276

257277

258278
def git_remote_repo_single_commit_post_init(remote_repo_path: pathlib.Path) -> None:
279+
"""Post-initialization: Create a test git repo with a single commit."""
259280
testfile_filename = "testfile.test"
260281
run(["touch", testfile_filename], cwd=remote_repo_path)
261282
run(["git", "add", testfile_filename], cwd=remote_repo_path)
@@ -298,6 +319,7 @@ def _create_svn_remote_repo(
298319

299320

300321
def svn_remote_repo_single_commit_post_init(remote_repo_path: pathlib.Path) -> None:
322+
"""Post-initialization: Create a test SVN repo with a single commit."""
301323
assert remote_repo_path.exists()
302324
repo_dumpfile = pathlib.Path(__file__).parent / "data" / "repotest.dump"
303325
run(
@@ -372,6 +394,7 @@ def _create_hg_remote_repo(
372394

373395

374396
def hg_remote_repo_single_commit_post_init(remote_repo_path: pathlib.Path) -> None:
397+
"""Post-initialization: Create a test mercurial repo with a single commit."""
375398
testfile_filename = "testfile.test"
376399
run(["touch", testfile_filename], cwd=remote_repo_path)
377400
run(["hg", "add", testfile_filename], cwd=remote_repo_path)
@@ -470,6 +493,7 @@ def add_doctest_fixtures(
470493
create_hg_remote_repo: CreateRepoPytestFixtureFn,
471494
git_repo: pathlib.Path,
472495
) -> None:
496+
"""Harness pytest fixtures to pytest's doctest namespace."""
473497
from _pytest.doctest import DoctestItem
474498

475499
if not isinstance(request._pyfuncitem, DoctestItem): # Only run on doctest items

0 commit comments

Comments
 (0)