Skip to content

Commit 3a89910

Browse files
committed
tests(doctest): Pass factory functions (speeds up setup)
1 parent 9df60ff commit 3a89910

4 files changed

Lines changed: 18 additions & 15 deletions

File tree

libvcs/conftest.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""pytest fixtures. Live inside libvcs for doctest."""
2+
import functools
23
import getpass
34
import pathlib
45
import shutil
@@ -327,14 +328,16 @@ def add_doctest_fixtures(
327328
doctest_namespace["tmp_path"] = tmp_path
328329
if which("git"):
329330
doctest_namespace["gitconfig"] = gitconfig
330-
doctest_namespace["git_remote_repo"] = create_git_remote_repo(
331-
remote_repo_post_init=git_remote_repo_single_commit_post_init
331+
doctest_namespace["create_git_remote_repo"] = functools.partial(
332+
create_git_remote_repo,
333+
remote_repo_post_init=git_remote_repo_single_commit_post_init,
332334
)
333-
doctest_namespace["git_remote_repo_bare"] = create_git_remote_repo()
335+
doctest_namespace["create_git_remote_repo_bare"] = create_git_remote_repo
334336
if which("svn"):
335-
doctest_namespace["svn_remote_repo"] = create_svn_remote_repo()
337+
doctest_namespace["create_svn_remote_repo"] = create_svn_remote_repo
336338
if which("hg"):
337-
doctest_namespace["hg_remote_repo_bare"] = create_hg_remote_repo()
338-
doctest_namespace["hg_remote_repo"] = create_hg_remote_repo(
339-
remote_repo_post_init=hg_remote_repo_single_commit_post_init
339+
doctest_namespace["create_hg_remote_repo_bare"] = create_hg_remote_repo
340+
doctest_namespace["create_hg_remote_repo"] = functools.partial(
341+
create_hg_remote_repo,
342+
remote_repo_post_init=hg_remote_repo_single_commit_post_init,
340343
)

libvcs/shortcuts.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def create_repo(
1414
--------
1515
>>> from libvcs.shortcuts import create_repo
1616
>>> r = create_repo(
17-
... url=f'file://{str(git_remote_repo)}',
17+
... url=f'file://{create_git_remote_repo()}',
1818
... vcs='git',
19-
... repo_dir=str(tmp_path)
19+
... repo_dir=tmp_path
2020
... )
2121
2222
>>> isinstance(r, GitRepo)
@@ -42,8 +42,8 @@ def create_repo_from_pip_url(
4242
4343
>>> from libvcs.shortcuts import create_repo_from_pip_url
4444
>>> r = create_repo_from_pip_url(
45-
... pip_url=f'git+{str(git_remote_repo)}',
46-
... repo_dir=str(tmp_path)
45+
... pip_url=f'git+{create_git_remote_repo()}',
46+
... repo_dir=tmp_path
4747
... )
4848
>>> isinstance(r, GitRepo)
4949
True

libvcs/states/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import NamedTuple
55
from urllib import parse as urlparse
66

7-
from ..util import CmdLoggingAdapter, mkdir_p, run
7+
from libvcs.util import CmdLoggingAdapter, mkdir_p, run
88

99
logger = logging.getLogger(__name__)
1010

@@ -62,7 +62,7 @@ def __init__(self, url, repo_dir, progress_callback=None, *args, **kwargs):
6262
... log_in_real_time=True
6363
... )
6464
>>> r = Repo(
65-
... url=f'file://{str(git_remote_repo)}',
65+
... url=f'file://{create_git_remote_repo()}',
6666
... repo_dir=str(tmp_path),
6767
... progress_callback=progress_cb
6868
... )

libvcs/states/git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ def status(self) -> dict:
591591
Examples
592592
--------
593593
>>> git_repo = GitRepo(
594-
... url=f'file://{str(git_remote_repo)}',
595-
... repo_dir=str(tmp_path)
594+
... url=f'file://{create_git_remote_repo()}',
595+
... repo_dir=tmp_path
596596
... )
597597
>>> git_repo.obtain()
598598
>>> git_repo.status()

0 commit comments

Comments
 (0)