mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
stop using gitpython in tests (#10808)
This commit is contained in:
@@ -46,6 +46,7 @@ from global repo template to creating everything inplace, which:
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from dulwich.porcelain import remote_add as git_remote_add
|
||||
|
||||
__all__ = [
|
||||
"erepo_dir",
|
||||
@@ -96,7 +97,7 @@ class GitRemote:
|
||||
def git_upstream(tmp_dir, erepo_dir, git_dir, request):
|
||||
remote = erepo_dir if "dvc" in request.fixturenames else git_dir
|
||||
url = f"file://{remote.resolve().as_posix()}"
|
||||
tmp_dir.scm.gitpython.repo.create_remote("upstream", url)
|
||||
git_remote_add(tmp_dir, "upstream", url)
|
||||
return GitRemote(remote, "upstream", url)
|
||||
|
||||
|
||||
@@ -104,5 +105,5 @@ def git_upstream(tmp_dir, erepo_dir, git_dir, request):
|
||||
def git_downstream(tmp_dir, erepo_dir, git_dir, request):
|
||||
remote = erepo_dir if "dvc" in request.fixturenames else git_dir
|
||||
url = f"file://{tmp_dir.resolve().as_posix()}"
|
||||
remote.scm.gitpython.repo.create_remote("upstream", url)
|
||||
git_remote_add(remote, "upstream", url)
|
||||
return GitRemote(remote, "upstream", url)
|
||||
|
||||
@@ -227,7 +227,7 @@ def test_detached_parent(tmp_dir, scm, dvc, exp_stage, mocker):
|
||||
scm.commit("v2")
|
||||
|
||||
scm.checkout(detached_rev)
|
||||
assert scm.gitpython.repo.head.is_detached
|
||||
assert scm.pygit2.repo.head_is_detached
|
||||
results = dvc.experiments.run(exp_stage.addressing, params=["foo=3"])
|
||||
|
||||
exp_rev = first(results)
|
||||
@@ -792,4 +792,4 @@ def test_custom_commit_message(tmp_dir, scm, dvc, tmp):
|
||||
stage.addressing, tmp_dir=tmp, message="custom commit message"
|
||||
)
|
||||
)
|
||||
assert scm.gitpython.repo.commit(exp).message == "custom commit message"
|
||||
assert scm.resolve_commit(exp).message == "custom commit message"
|
||||
|
||||
@@ -61,4 +61,4 @@ def test_custom_commit_message_queue(tmp_dir, scm, dvc):
|
||||
dvc.experiments.run(stage.addressing, queue=True, message="custom commit message")
|
||||
|
||||
exp = first(dvc.experiments.run(run_all=True))
|
||||
assert scm.gitpython.repo.commit(exp).message == "custom commit message"
|
||||
assert scm.resolve_commit(exp).message == "custom commit message"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
from dulwich.porcelain import pull as git_pull
|
||||
from funcy import first
|
||||
|
||||
from dvc.repo.experiments.utils import exp_refs_by_rev
|
||||
@@ -180,10 +181,8 @@ def test_list_remote(tmp_dir, scm, dvc, git_downstream, exp_stage, use_url):
|
||||
def test_pull(tmp_dir, scm, dvc, git_downstream, exp_stage, use_url):
|
||||
from dvc.exceptions import InvalidArgumentError
|
||||
|
||||
# fetch and checkout to downstream so both repos start from same commit
|
||||
downstream_repo = git_downstream.tmp_dir.scm.gitpython.repo
|
||||
fetched = downstream_repo.remote(git_downstream.remote).fetch()
|
||||
downstream_repo.git.checkout(fetched)
|
||||
# pull to downstream so both repos start from same commit
|
||||
git_pull(git_downstream.tmp_dir, "upstream")
|
||||
|
||||
remote = git_downstream.url if use_url else git_downstream.remote
|
||||
downstream_exp = git_downstream.tmp_dir.dvc.experiments
|
||||
|
||||
@@ -165,7 +165,7 @@ def test_exp_save_custom_message(tmp_dir, dvc, scm):
|
||||
setup_stage(tmp_dir, dvc, scm)
|
||||
|
||||
exp = dvc.experiments.save(message="custom commit message")
|
||||
assert scm.gitpython.repo.commit(exp).message == "custom commit message"
|
||||
assert scm.resolve_commit(exp).message == "custom commit message"
|
||||
|
||||
|
||||
def test_exp_save_target(tmp_dir, dvc, scm):
|
||||
|
||||
@@ -102,7 +102,7 @@ def test_show_simple(tmp_dir, scm, dvc, exp_stage):
|
||||
def test_show_experiment(tmp_dir, scm, dvc, exp_stage, workspace):
|
||||
baseline_rev = scm.get_rev()
|
||||
timestamp = datetime.fromtimestamp( # noqa: DTZ006
|
||||
scm.gitpython.repo.rev_parse(baseline_rev).committed_date
|
||||
scm.resolve_commit(baseline_rev).commit_time
|
||||
)
|
||||
|
||||
exp_rev = first(
|
||||
@@ -424,7 +424,7 @@ def test_show_csv(tmp_dir, scm, dvc, exp_stage, capsys):
|
||||
|
||||
def _get_rev_isotimestamp(rev):
|
||||
return datetime.fromtimestamp( # noqa: DTZ006
|
||||
scm.gitpython.repo.rev_parse(rev).committed_date
|
||||
scm.resolve_commit(rev).commit_time
|
||||
).isoformat()
|
||||
|
||||
result1 = dvc.experiments.run(exp_stage.addressing, params=["foo=2"])
|
||||
@@ -653,7 +653,7 @@ def test_metrics_renaming(tmp_dir, dvc, scm, capsys, copy_script):
|
||||
|
||||
def _get_rev_isotimestamp(rev):
|
||||
return datetime.fromtimestamp( # noqa: DTZ006
|
||||
scm.gitpython.repo.rev_parse(rev).committed_date
|
||||
scm.resolve_commit(rev).commit_time
|
||||
).isoformat()
|
||||
|
||||
assert f",master,baseline,{_get_rev_isotimestamp(scores_rev)},,1,,1" in cap.out
|
||||
|
||||
@@ -5,6 +5,7 @@ import stat
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
from dulwich.porcelain import remove as git_rm
|
||||
|
||||
from dvc.cli import main
|
||||
from dvc.dvcfile import PROJECT_FILE, load_file
|
||||
@@ -379,7 +380,7 @@ def test_stats_on_checkout(tmp_dir, dvc, scm):
|
||||
|
||||
tmp_dir.gen({"lorem": "lorem", "bar": "new bar", "dir2": {"file": "file"}})
|
||||
(tmp_dir / "foo").unlink()
|
||||
scm.gitpython.repo.git.rm("foo.dvc")
|
||||
git_rm(tmp_dir, ["foo.dvc"])
|
||||
tmp_dir.dvc_add(["bar", "lorem", "dir2"], commit="second")
|
||||
|
||||
scm.checkout("HEAD~")
|
||||
|
||||
@@ -2,6 +2,8 @@ import filecmp
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from dulwich.porcelain import push as git_push
|
||||
from dulwich.porcelain import remote_add as git_remote_add
|
||||
from funcy import first
|
||||
|
||||
from dvc.cachemgr import CacheManager
|
||||
@@ -352,8 +354,8 @@ def test_push_wildcard_from_bare_git_repo(
|
||||
)
|
||||
erepo_dir.dvc.push([os.path.join(os.fspath(erepo_dir), "dire*")], glob=True)
|
||||
|
||||
erepo_dir.scm.gitpython.repo.create_remote("origin", os.fspath(tmp_dir))
|
||||
erepo_dir.scm.gitpython.repo.remote("origin").push("master")
|
||||
git_remote_add(erepo_dir, "origin", os.fspath(tmp_dir))
|
||||
git_push(erepo_dir, "origin")
|
||||
|
||||
dvc_repo = make_tmp_dir("dvc-repo", scm=True, dvc=True)
|
||||
with dvc_repo.chdir():
|
||||
@@ -435,8 +437,8 @@ def test_import_from_bare_git_repo(tmp_dir, make_tmp_dir, erepo_dir, local_cloud
|
||||
erepo_dir.dvc_gen({"foo": "foo"}, commit="initial")
|
||||
erepo_dir.dvc.push()
|
||||
|
||||
erepo_dir.scm.gitpython.repo.create_remote("origin", os.fspath(tmp_dir))
|
||||
erepo_dir.scm.gitpython.repo.remote("origin").push("master")
|
||||
git_remote_add(erepo_dir, "origin", os.fspath(tmp_dir))
|
||||
git_push(erepo_dir, "origin", "master")
|
||||
|
||||
dvc_repo = make_tmp_dir("dvc-repo", scm=True, dvc=True)
|
||||
with dvc_repo.chdir():
|
||||
|
||||
@@ -3,6 +3,7 @@ import pathlib
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from dulwich.porcelain import remote_add as git_remote_add
|
||||
from git import GitCommandError
|
||||
|
||||
from dvc.exceptions import DvcException
|
||||
@@ -81,8 +82,8 @@ class TestInstall:
|
||||
storage_path / "files" / "md5" / file_checksum[:2] / file_checksum[2:]
|
||||
)
|
||||
|
||||
scm.gitpython.repo.clone(os.fspath(git_remote))
|
||||
scm.gitpython.repo.create_remote("origin", os.fspath(git_remote))
|
||||
scm.clone(os.fspath(tmp_dir), os.fspath(git_remote))
|
||||
git_remote_add(tmp_dir, "origin", os.fspath(git_remote))
|
||||
|
||||
dvc.install()
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import os
|
||||
|
||||
from dulwich.porcelain import push as git_push
|
||||
from dulwich.porcelain import remote_add as git_remote_add
|
||||
|
||||
from dvc.cachemgr import CacheManager
|
||||
from dvc.dvcfile import LOCK_FILE, PROJECT_FILE
|
||||
from dvc.fs import system
|
||||
@@ -19,8 +22,8 @@ def test_open_bare(tmp_dir, scm, dvc, tmp_path_factory):
|
||||
url = os.fspath(tmp_path_factory.mktemp("bare"))
|
||||
Git.init(url, bare=True).close()
|
||||
|
||||
scm.gitpython.repo.create_remote("origin", url)
|
||||
scm.gitpython.repo.remote("origin").push("master")
|
||||
git_remote_add(tmp_dir, "origin", url)
|
||||
git_push(tmp_dir, "origin")
|
||||
|
||||
with Repo.open(url) as repo:
|
||||
assert repo.scm.root_dir != url
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from git import Repo
|
||||
|
||||
from dvc.scm import SCM, Git, NoSCM, SCMError, lfs_prefetch
|
||||
|
||||
@@ -11,7 +10,7 @@ def test_init_none(tmp_dir):
|
||||
|
||||
|
||||
def test_init_git(tmp_dir):
|
||||
Repo.init(os.fspath(tmp_dir))
|
||||
Git.init(os.fspath(tmp_dir))
|
||||
assert isinstance(SCM(os.fspath(tmp_dir)), Git)
|
||||
|
||||
|
||||
@@ -21,7 +20,7 @@ def test_init_no_git(tmp_dir):
|
||||
|
||||
|
||||
def test_init_sub_dir(tmp_dir):
|
||||
Repo.init(os.fspath(tmp_dir))
|
||||
Git.init(os.fspath(tmp_dir))
|
||||
subdir = tmp_dir / "dir"
|
||||
subdir.mkdir()
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from dulwich.porcelain import remove as git_rm
|
||||
|
||||
from dvc.cli import main
|
||||
from dvc.fs import localfs
|
||||
@@ -63,8 +64,7 @@ def test_status_before_and_after_dvc_init(tmp_dir, dvc, git_dir):
|
||||
|
||||
with git_dir.chdir():
|
||||
git_dir.init(dvc=True)
|
||||
git_dir.scm.gitpython.repo.index.remove(["file"])
|
||||
os.remove("file")
|
||||
git_rm(git_dir, ["file"])
|
||||
git_dir.dvc_gen("file", "second version", commit="with dvc")
|
||||
new_rev = git_dir.scm.get_rev()
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from dulwich.porcelain import remove as git_rm
|
||||
|
||||
from dvc.dependency import base
|
||||
from dvc.dvcfile import load_file
|
||||
@@ -89,7 +90,7 @@ def test_update_import_after_remote_updates_to_dvc(tmp_dir, dvc, erepo_dir):
|
||||
|
||||
new_rev = None
|
||||
with erepo_dir.branch("branch", new=False), erepo_dir.chdir():
|
||||
erepo_dir.scm.gitpython.repo.index.remove(["version"])
|
||||
git_rm(erepo_dir, ["version"], cached=True)
|
||||
erepo_dir.dvc_gen("version", "updated", commit="upgrade to DVC tracking")
|
||||
new_rev = erepo_dir.scm.get_rev()
|
||||
|
||||
@@ -124,8 +125,7 @@ def test_update_before_and_after_dvc_init(tmp_dir, dvc, git_dir):
|
||||
|
||||
with git_dir.chdir():
|
||||
git_dir.init(dvc=True)
|
||||
git_dir.scm.gitpython.repo.index.remove(["file"])
|
||||
os.remove("file")
|
||||
git_rm(git_dir, ["file"])
|
||||
git_dir.dvc_gen("file", "second version", commit="with dvc")
|
||||
new_rev = git_dir.scm.get_rev()
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ def commit_exp_ref(tmp_dir, scm, file="foo", contents="foo", name="foo"):
|
||||
tmp_dir.scm_gen(file, contents, commit="init")
|
||||
rev = scm.get_rev()
|
||||
ref = f"{EXPS_NAMESPACE}/ab/c123/{name}"
|
||||
scm.gitpython.set_ref(ref, rev)
|
||||
scm.dulwich.repo.refs[ref.encode("utf-8")] = rev.encode("utf-8")
|
||||
return ref, rev
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from urllib.parse import urljoin
|
||||
|
||||
import pytest
|
||||
from dulwich.porcelain import remote_add as git_remote_add
|
||||
from requests import Response
|
||||
|
||||
from dvc.env import (
|
||||
@@ -85,7 +86,8 @@ def test_env_to_config():
|
||||
],
|
||||
)
|
||||
def test_get_repo_url(dvc, scm, monkeypatch, exp_git_remote, repo_url):
|
||||
scm.gitpython.repo.create_remote("origin", "git@url")
|
||||
git_remote_add(scm.root_dir, "origin", "git@url")
|
||||
|
||||
if exp_git_remote:
|
||||
monkeypatch.setenv(DVC_EXP_GIT_REMOTE, exp_git_remote)
|
||||
assert get_repo_url(dvc) == repo_url
|
||||
|
||||
Reference in New Issue
Block a user