mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
test: fix python 2, 3.5 and mac issues with new fixtures
This commit is contained in:
@@ -75,8 +75,6 @@ def _makedirs(name, mode=0o777, exist_ok=False):
|
||||
"""Source: https://github.com/python/cpython/blob/
|
||||
3ce3dea60646d8a5a1c952469a2eb65f937875b3/Lib/os.py#L196-L226
|
||||
"""
|
||||
name = fspath_py35(name)
|
||||
|
||||
head, tail = os.path.split(name)
|
||||
if not tail:
|
||||
head, tail = os.path.split(head)
|
||||
|
||||
+25
-19
@@ -1,9 +1,12 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import pytest
|
||||
|
||||
from funcy import lmap, retry
|
||||
from funcy.py3 import lmap, retry
|
||||
|
||||
from dvc.utils.compat import pathlib, fspath, makedirs, basestring
|
||||
from dvc.utils import makedirs
|
||||
from dvc.utils.compat import basestring, is_py2, pathlib, fspath, fspath_py35
|
||||
|
||||
|
||||
__all__ = ["tmp_dir", "scm", "dvc", "repo_template", "run_copy", "erepo_dir"]
|
||||
@@ -29,6 +32,10 @@ class TmpDir(pathlib.Path):
|
||||
self._init()
|
||||
return self
|
||||
|
||||
# Not needed in Python 3.6+
|
||||
def __fspath__(self):
|
||||
return str(self)
|
||||
|
||||
def _require(self, name):
|
||||
if not hasattr(self, name):
|
||||
raise TypeError(
|
||||
@@ -37,25 +44,24 @@ class TmpDir(pathlib.Path):
|
||||
)
|
||||
|
||||
def gen(self, struct, text=""):
|
||||
if isinstance(struct, str):
|
||||
if isinstance(struct, basestring):
|
||||
struct = {struct: text}
|
||||
|
||||
return self._gen(struct)
|
||||
self._gen(struct)
|
||||
return struct.keys()
|
||||
|
||||
def _gen(self, struct, prefix=None):
|
||||
paths = []
|
||||
|
||||
for name, contents in struct.items():
|
||||
path = (prefix or self) / name
|
||||
|
||||
if isinstance(contents, dict):
|
||||
paths.extend(self._gen(contents, prefix=path))
|
||||
self._gen(contents, prefix=path)
|
||||
else:
|
||||
makedirs(path.parent, exist_ok=True)
|
||||
path.write_text(contents)
|
||||
paths.append(path.relative_to(self))
|
||||
|
||||
return paths
|
||||
if is_py2 and isinstance(contents, str):
|
||||
path.write_bytes(contents)
|
||||
else:
|
||||
path.write_text(contents)
|
||||
|
||||
def dvc_gen(self, struct, text="", commit=None):
|
||||
paths = self.gen(struct, text)
|
||||
@@ -106,7 +112,7 @@ class PosixTmpDir(TmpDir, pathlib.PurePosixPath):
|
||||
@pytest.fixture
|
||||
def tmp_dir(tmp_path, monkeypatch):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
return TmpDir(tmp_path)
|
||||
return TmpDir(fspath_py35(tmp_path))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -183,7 +189,7 @@ def run_copy(tmp_dir, dvc, request):
|
||||
cmd="python copy.py {} {}".format(src, dst),
|
||||
outs=[dst],
|
||||
deps=[src, "copy.py"],
|
||||
**run_kwargs,
|
||||
**run_kwargs
|
||||
)
|
||||
|
||||
return run_copy
|
||||
@@ -194,25 +200,25 @@ def erepo_dir(tmp_path_factory, monkeypatch):
|
||||
from dvc.repo import Repo
|
||||
from dvc.remote.config import RemoteConfig
|
||||
|
||||
path = TmpDir(tmp_path_factory.mktemp("erepo"))
|
||||
path.gen(REPO_TEMPLATE)
|
||||
path = TmpDir(fspath_py35(tmp_path_factory.mktemp("erepo")))
|
||||
|
||||
# Chdir for git and dvc to work locally
|
||||
monkeypatch.chdir(path)
|
||||
monkeypatch.chdir(fspath_py35(path))
|
||||
|
||||
_git_init()
|
||||
path.dvc = Repo.init()
|
||||
path.scm = path.dvc.scm
|
||||
|
||||
path.dvc_add(["foo", "bar", "dir"], commit="init repo")
|
||||
path.dvc_gen(REPO_TEMPLATE, commit="init repo")
|
||||
|
||||
rconfig = RemoteConfig(path.dvc.config)
|
||||
rconfig.add("upstream", path.dvc.cache.local.cache_dir, default=True)
|
||||
path.scm_add([path.dvc.config.config_file], commit="add remote")
|
||||
|
||||
path.dvc_gen("version", "master", commit="master")
|
||||
path.dvc_gen("version", "master")
|
||||
path.scm_add([".gitignore", "version.dvc"], commit="master")
|
||||
|
||||
path.scm.checkout("branch", create_new=True)
|
||||
(path / "version").unlink() # For mac ???
|
||||
path.dvc_gen("version", "branch")
|
||||
path.scm_add([".gitignore", "version.dvc"], commit="branch")
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
@@ -106,7 +108,7 @@ def test_open_scm_controlled(dvc_repo, repo_dir):
|
||||
assert fd.read() == stage_content
|
||||
|
||||
|
||||
# TODO: simplify, we shouldn't need run. This also duplicates the previous one.
|
||||
# TODO: simplify, we shouldn't need run.
|
||||
def test_open_not_cached(dvc):
|
||||
metric_file = "metric.txt"
|
||||
metric_content = "0.6"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.stage import StageCommitError
|
||||
|
||||
Reference in New Issue
Block a user