Skip to content

Commit 8b47794

Browse files
authored
chore: Small fixes for docstrings, pytest plugin typings, add an HgSync test (#450)
2 parents a78779a + 532386f commit 8b47794

9 files changed

Lines changed: 81 additions & 43 deletions

File tree

CHANGES

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@ $ pip install --user --upgrade --pre libvcs
1515

1616
<!-- Maintainers, insert changes / features for the next release here -->
1717

18+
### Breaking changes
19+
20+
- Rename pytest plugin protocol typings (#450):
21+
22+
- `CreateProjectCallbackProtocol` -> `CreateRepoPostInitFn`
23+
- `CreateProjectCallbackFixtureProtocol` -> `CreateRepoPytestFixtureFn`
24+
25+
### Bug fixes
26+
27+
- Remove unused command: `Svn.mergelist` (#450)
28+
- Fix `Git.config` docstring (#450)
29+
30+
### Development
31+
32+
- Add test for direct usage of `HgSync` (#450)
33+
- pytest-watcher, Add configuration (#450):
34+
35+
- Run initially by default
36+
- Skip post-save files from vim
37+
1838
## libvcs 0.25.1 (2023-11-23)
1939

2040
### Packaging

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ filterwarnings = [
171171
"ignore:The frontend.Option(Parser)? class.*:DeprecationWarning::",
172172
]
173173

174+
[tool.pytest-watcher]
175+
now = true
176+
ignore_patterns = ["*.py.*.py"]
177+
174178
[build-system]
175179
requires = ["poetry_core>=1.0.0"]
176180
build-backend = "poetry.core.masonry.api"

src/libvcs/cmd/git.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,10 +1586,10 @@ def config(
15861586
check_returncode: Optional[bool] = None,
15871587
**kwargs: Any,
15881588
) -> str:
1589-
"""Status of working tree. Wraps
1590-
`git status <https://git-scm.com/docs/git-status>`_.
1589+
"""Get and set repo configuration.
15911590
1592-
`git ls-files` has similar params (e.g. `z`)
1591+
Status of working tree. Wraps
1592+
`git config <https://git-scm.com/docs/git-config>`_.
15931593
15941594
Parameters
15951595
----------

src/libvcs/cmd/svn.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -686,18 +686,6 @@ def merge(self, *args: Any, **kwargs: Any) -> str:
686686

687687
return self.run(["merge", *local_flags])
688688

689-
def mergelist(self, *args: Any, **kwargs: Any) -> str:
690-
"""
691-
Wraps `svn mergelist
692-
<https://svnbook.red-bean.com/en/1.7/svn.ref.svn.c.mergelist.html>`_.
693-
694-
Parameters
695-
----------
696-
"""
697-
local_flags: list[str] = [*args]
698-
699-
return self.run(["mergelist", *local_flags])
700-
701689
def mkdir(self, *args: Any, **kwargs: Any) -> str:
702690
"""
703691
Wraps `svn mkdir

src/libvcs/pytest_plugin.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,17 @@ def unique_repo_name(remote_repos_path: pathlib.Path, max_retries: int = 15) ->
194194
InitCmdArgs: "TypeAlias" = Optional[list[str]]
195195

196196

197-
class CreateProjectCallbackProtocol(Protocol):
197+
class CreateRepoPostInitFn(Protocol):
198198
def __call__(self, remote_repo_path: pathlib.Path) -> None:
199199
...
200200

201201

202-
class CreateProjectCallbackFixtureProtocol(Protocol):
202+
class CreateRepoPytestFixtureFn(Protocol):
203203
def __call__(
204204
self,
205205
remote_repos_path: pathlib.Path = ...,
206206
remote_repo_name: Optional[str] = ...,
207-
remote_repo_post_init: Optional[CreateProjectCallbackProtocol] = ...,
207+
remote_repo_post_init: Optional[CreateRepoPostInitFn] = ...,
208208
init_cmd_args: InitCmdArgs = ...,
209209
) -> pathlib.Path:
210210
...
@@ -216,7 +216,7 @@ def __call__(
216216
def _create_git_remote_repo(
217217
remote_repos_path: pathlib.Path,
218218
remote_repo_name: str,
219-
remote_repo_post_init: Optional[CreateProjectCallbackProtocol] = None,
219+
remote_repo_post_init: Optional[CreateRepoPostInitFn] = None,
220220
init_cmd_args: InitCmdArgs = DEFAULT_GIT_REMOTE_REPO_CMD_ARGS,
221221
) -> pathlib.Path:
222222
if init_cmd_args is None:
@@ -234,13 +234,13 @@ def _create_git_remote_repo(
234234
@skip_if_git_missing
235235
def create_git_remote_repo(
236236
remote_repos_path: pathlib.Path,
237-
) -> CreateProjectCallbackFixtureProtocol:
238-
"""Factory. Create git remote repo to for clone / push purposes"""
237+
) -> CreateRepoPytestFixtureFn:
238+
"""Factory. Create git remote repo to for clone / push purposes."""
239239

240240
def fn(
241241
remote_repos_path: pathlib.Path = remote_repos_path,
242242
remote_repo_name: Optional[str] = None,
243-
remote_repo_post_init: Optional[CreateProjectCallbackProtocol] = None,
243+
remote_repo_post_init: Optional[CreateRepoPostInitFn] = None,
244244
init_cmd_args: InitCmdArgs = DEFAULT_GIT_REMOTE_REPO_CMD_ARGS,
245245
) -> pathlib.Path:
246246
return _create_git_remote_repo(
@@ -278,7 +278,7 @@ def git_remote_repo(remote_repos_path: pathlib.Path) -> pathlib.Path:
278278
def _create_svn_remote_repo(
279279
remote_repos_path: pathlib.Path,
280280
remote_repo_name: str,
281-
remote_repo_post_init: Optional[CreateProjectCallbackProtocol] = None,
281+
remote_repo_post_init: Optional[CreateRepoPostInitFn] = None,
282282
init_cmd_args: InitCmdArgs = None,
283283
) -> pathlib.Path:
284284
"""Create a test SVN repo to for checkout / commit purposes"""
@@ -318,13 +318,13 @@ def svn_remote_repo_single_commit_post_init(remote_repo_path: pathlib.Path) -> N
318318
@skip_if_svn_missing
319319
def create_svn_remote_repo(
320320
remote_repos_path: pathlib.Path,
321-
) -> CreateProjectCallbackFixtureProtocol:
321+
) -> CreateRepoPytestFixtureFn:
322322
"""Pre-made svn repo, bare, used as a file:// remote to checkout and commit to."""
323323

324324
def fn(
325325
remote_repos_path: pathlib.Path = remote_repos_path,
326326
remote_repo_name: Optional[str] = None,
327-
remote_repo_post_init: Optional[CreateProjectCallbackProtocol] = None,
327+
remote_repo_post_init: Optional[CreateRepoPostInitFn] = None,
328328
init_cmd_args: InitCmdArgs = None,
329329
) -> pathlib.Path:
330330
return _create_svn_remote_repo(
@@ -355,7 +355,7 @@ def svn_remote_repo(remote_repos_path: pathlib.Path) -> pathlib.Path:
355355
def _create_hg_remote_repo(
356356
remote_repos_path: pathlib.Path,
357357
remote_repo_name: str,
358-
remote_repo_post_init: Optional[CreateProjectCallbackProtocol] = None,
358+
remote_repo_post_init: Optional[CreateRepoPostInitFn] = None,
359359
init_cmd_args: InitCmdArgs = None,
360360
) -> pathlib.Path:
361361
"""Create a test hg repo to for checkout / commit purposes"""
@@ -384,13 +384,13 @@ def create_hg_remote_repo(
384384
remote_repos_path: pathlib.Path,
385385
hgconfig: pathlib.Path,
386386
set_home: pathlib.Path,
387-
) -> CreateProjectCallbackFixtureProtocol:
387+
) -> CreateRepoPytestFixtureFn:
388388
"""Pre-made hg repo, bare, used as a file:// remote to checkout and commit to."""
389389

390390
def fn(
391391
remote_repos_path: pathlib.Path = remote_repos_path,
392392
remote_repo_name: Optional[str] = None,
393-
remote_repo_post_init: Optional[CreateProjectCallbackProtocol] = None,
393+
remote_repo_post_init: Optional[CreateRepoPostInitFn] = None,
394394
init_cmd_args: InitCmdArgs = None,
395395
) -> pathlib.Path:
396396
return _create_hg_remote_repo(
@@ -465,9 +465,9 @@ def add_doctest_fixtures(
465465
tmp_path: pathlib.Path,
466466
set_home: pathlib.Path,
467467
gitconfig: pathlib.Path,
468-
create_git_remote_repo: CreateProjectCallbackFixtureProtocol,
469-
create_svn_remote_repo: CreateProjectCallbackFixtureProtocol,
470-
create_hg_remote_repo: CreateProjectCallbackFixtureProtocol,
468+
create_git_remote_repo: CreateRepoPytestFixtureFn,
469+
create_svn_remote_repo: CreateRepoPytestFixtureFn,
470+
create_hg_remote_repo: CreateRepoPytestFixtureFn,
471471
git_repo: pathlib.Path,
472472
) -> None:
473473
from _pytest.doctest import DoctestItem

tests/sync/test_git.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from libvcs import exc
1313
from libvcs._internal.run import run
1414
from libvcs._internal.shortcuts import create_project
15-
from libvcs.pytest_plugin import CreateProjectCallbackFixtureProtocol
15+
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn
1616
from libvcs.sync.git import (
1717
GitRemote,
1818
GitStatus,
@@ -169,7 +169,7 @@ def test_repo_update_handle_cases(
169169
)
170170
def test_repo_update_stash_cases(
171171
tmp_path: pathlib.Path,
172-
create_git_remote_repo: CreateProjectCallbackFixtureProtocol,
172+
create_git_remote_repo: CreateRepoPytestFixtureFn,
173173
mocker: MockerFixture,
174174
has_untracked_files: bool,
175175
needs_stash: bool,
@@ -531,7 +531,7 @@ def test_remotes_update_repo(
531531
lazy_constructor_options: ProjectTestFactoryLazyKwargs,
532532
lazy_remote_dict: ProjectTestFactoryRemoteLazyExpected,
533533
lazy_remote_expected: ProjectTestFactoryRemoteLazyExpected,
534-
create_git_remote_repo: CreateProjectCallbackFixtureProtocol,
534+
create_git_remote_repo: CreateRepoPytestFixtureFn,
535535
) -> None:
536536
repo_name = "myrepo"
537537
remote_name = "myremote"
@@ -887,7 +887,7 @@ def test_GitRemote__from_stdout_c(fixture: str, expected_result: GitStatus) -> N
887887

888888

889889
def test_repo_git_remote_checkout(
890-
create_git_remote_repo: CreateProjectCallbackFixtureProtocol,
890+
create_git_remote_repo: CreateRepoPytestFixtureFn,
891891
tmp_path: pathlib.Path,
892892
projects_path: pathlib.Path,
893893
) -> None:

tests/sync/test_hg.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,42 @@
77
from libvcs import exc
88
from libvcs._internal.run import run
99
from libvcs._internal.shortcuts import create_project
10+
from libvcs.sync.hg import HgSync
1011

1112
if not shutil.which("hg"):
1213
pytestmark = pytest.mark.skip(reason="hg is not available")
1314

1415

15-
def test_repo_mercurial(
16+
def test_hg_sync(
1617
tmp_path: pathlib.Path,
1718
projects_path: pathlib.Path,
1819
hg_remote_repo: pathlib.Path,
1920
) -> None:
21+
"""Test HgSync."""
22+
repo_name = "my_mercurial_project"
23+
24+
mercurial_repo = HgSync(
25+
url=f"file://{hg_remote_repo}",
26+
dir=projects_path / repo_name,
27+
)
28+
29+
run(["hg", "init", mercurial_repo.repo_name], cwd=tmp_path)
30+
31+
mercurial_repo.update_repo()
32+
33+
test_repo_revision = run(
34+
["hg", "parents", "--template={rev}"], cwd=projects_path / repo_name
35+
)
36+
37+
assert mercurial_repo.get_revision() == test_repo_revision
38+
39+
40+
def test_repo_mercurial_via_create_project(
41+
tmp_path: pathlib.Path,
42+
projects_path: pathlib.Path,
43+
hg_remote_repo: pathlib.Path,
44+
) -> None:
45+
"""Test HgSync via create_project()."""
2046
repo_name = "my_mercurial_project"
2147

2248
mercurial_repo = create_project(

tests/sync/test_svn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
from libvcs.pytest_plugin import CreateProjectCallbackFixtureProtocol
7+
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn
88
from libvcs.sync.svn import SvnSync
99

1010
if not shutil.which("svn"):
@@ -29,7 +29,7 @@ def test_repo_svn(tmp_path: pathlib.Path, svn_remote_repo: pathlib.Path) -> None
2929

3030

3131
def test_repo_svn_remote_checkout(
32-
create_svn_remote_repo: CreateProjectCallbackFixtureProtocol,
32+
create_svn_remote_repo: CreateRepoPytestFixtureFn,
3333
tmp_path: pathlib.Path,
3434
projects_path: pathlib.Path,
3535
) -> None:

tests/test_pytest_plugin.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
import pytest
66

7-
from libvcs.pytest_plugin import CreateProjectCallbackFixtureProtocol
7+
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn
88

99

1010
@pytest.mark.skipif(not shutil.which("git"), reason="git is not available")
1111
def test_create_git_remote_repo(
12-
create_git_remote_repo: CreateProjectCallbackFixtureProtocol,
12+
create_git_remote_repo: CreateRepoPytestFixtureFn,
1313
tmp_path: pathlib.Path,
1414
projects_path: pathlib.Path,
1515
) -> None:
@@ -21,7 +21,7 @@ def test_create_git_remote_repo(
2121

2222
@pytest.mark.skipif(not shutil.which("svn"), reason="svn is not available")
2323
def test_create_svn_remote_repo(
24-
create_svn_remote_repo: CreateProjectCallbackFixtureProtocol,
24+
create_svn_remote_repo: CreateRepoPytestFixtureFn,
2525
tmp_path: pathlib.Path,
2626
projects_path: pathlib.Path,
2727
) -> None:
@@ -69,10 +69,10 @@ def setup(
6969
import pathlib
7070
7171
from libvcs.sync.git import GitSync
72-
from libvcs.pytest_plugin import CreateProjectCallbackFixtureProtocol
72+
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn
7373
7474
def test_repo_git_remote_checkout(
75-
create_git_remote_repo: CreateProjectCallbackFixtureProtocol,
75+
create_git_remote_repo: CreateRepoPytestFixtureFn,
7676
tmp_path: pathlib.Path,
7777
projects_path: pathlib.Path,
7878
) -> None:

0 commit comments

Comments
 (0)