-
Notifications
You must be signed in to change notification settings - Fork 14
add tests - part 1 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f5190df
07159e1
a85e385
85788f7
1846c21
de8d16a
a76b719
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [run] | ||
| branch = True | ||
| source = scmrepo | ||
|
|
||
| [report] | ||
| exclude_lines = | ||
| if TYPE_CHECKING: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| from collections.abc import Mapping | ||
| from contextlib import contextmanager | ||
| from functools import partialmethod | ||
| from typing import Dict, Iterable, Optional, Tuple, Type | ||
| from typing import Dict, Iterable, Optional, Tuple, Type, Union | ||
|
|
||
| from funcy import cached_property, first | ||
| from pathspec.patterns import GitWildMatchPattern | ||
|
|
@@ -260,6 +260,29 @@ def get_fs(self, rev: str): | |
|
|
||
| return GitFileSystem(scm=self, rev=rev) | ||
|
|
||
| @classmethod | ||
| def init( | ||
| cls, path: str, bare: bool = False, _backend: str = None | ||
| ) -> "Git": | ||
| for name, backend in GitBackends.DEFAULT.items(): | ||
| if _backend and name != _backend: | ||
| continue | ||
| try: | ||
| backend.init(path, bare=bare) | ||
| # TODO: reuse created object instead of initializing a new one. | ||
| return cls(path) | ||
| except NotImplementedError: | ||
| pass | ||
| raise NoGitBackendError("init") | ||
|
|
||
| def add_commit( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have |
||
| self, | ||
| paths: Union[str, Iterable[str]], | ||
| message: str, | ||
| ) -> None: | ||
| self.add(paths) | ||
| self.commit(msg=message) | ||
|
|
||
| is_ignored = partialmethod(_backend_func, "is_ignored") | ||
| add = partialmethod(_backend_func, "add") | ||
| commit = partialmethod(_backend_func, "commit") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import os | ||
| import sys | ||
|
|
||
| import pygit2 | ||
| import pytest | ||
| from pytest_test_utils import TempDirFactory, TmpDir | ||
|
|
||
| from scmrepo.git import Git | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def isolate(tmp_dir_factory: TempDirFactory, monkeypatch: pytest.MonkeyPatch): | ||
| path = tmp_dir_factory.mktemp("mock") | ||
| home_dir = path / "home" | ||
| home_dir.mkdir() | ||
|
|
||
| if sys.platform == "win32": | ||
| home_drive, home_path = os.path.splitdrive(home_dir) | ||
| monkeypatch.setenv("USERPROFILE", str(home_dir)) | ||
| monkeypatch.setenv("HOMEDRIVE", home_drive) | ||
| monkeypatch.setenv("HOMEPATH", home_path) | ||
| else: | ||
| monkeypatch.setenv("HOME", str(home_dir)) | ||
|
|
||
| monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1") | ||
| contents = b""" | ||
| [user] | ||
| name=DVC Tester | ||
| email=dvctester@example.com | ||
| [init] | ||
| defaultBranch=master | ||
| """ | ||
| (home_dir / ".gitconfig").write_bytes(contents) | ||
| pygit2.settings.search_path[pygit2.GIT_CONFIG_LEVEL_GLOBAL] = str(home_dir) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like |
||
|
|
||
|
|
||
| @pytest.fixture | ||
| def scm(tmp_dir: TmpDir): | ||
| git_ = Git.init(tmp_dir) | ||
| sig = git_.pygit2.default_signature | ||
|
|
||
| assert sig.email == "dvctester@example.com" | ||
| assert sig.name == "DVC Tester" | ||
|
|
||
| yield git_ | ||
| git_.close() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import pytest | ||
| from pytest_mock import MockerFixture | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "algorithm", [b"ssh-rsa", b"rsa-sha2-256", b"rsa-sha2-512"] | ||
| ) | ||
| def test_dulwich_github_compat(mocker: MockerFixture, algorithm: bytes): | ||
| from asyncssh.misc import ProtocolError | ||
|
|
||
| from scmrepo.git.backend.dulwich.asyncssh_vendor import ( | ||
| _process_public_key_ok_gh, | ||
| ) | ||
|
|
||
| key_data = b"foo" | ||
| auth = mocker.Mock( | ||
| _keypair=mocker.Mock(algorithm=algorithm, public_data=key_data), | ||
| ) | ||
| packet = mocker.Mock() | ||
|
|
||
| with pytest.raises(ProtocolError): | ||
| strings = iter((b"ed21556", key_data)) | ||
| packet.get_string = lambda: next(strings) | ||
| _process_public_key_ok_gh(auth, None, None, packet) | ||
|
|
||
| strings = iter((b"ssh-rsa", key_data)) | ||
| packet.get_string = lambda: next(strings) | ||
| _process_public_key_ok_gh(auth, None, None, packet) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented
initand added tests for all backends.