mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-13 15:28:27 +01:00
tests: func: convert test_get.py test_utils.py to new fixtures
This commit is contained in:
+44
-56
@@ -1,84 +1,72 @@
|
||||
# encoding: utf-8
|
||||
import filecmp
|
||||
import os
|
||||
import shutil
|
||||
import stat
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc import utils
|
||||
from tests.basic_env import TestDvc
|
||||
|
||||
|
||||
class TestUtils(TestDvc):
|
||||
def test_copyfile(self):
|
||||
src = "file1"
|
||||
dest = "file2"
|
||||
dest_dir = "testdir"
|
||||
def test_copyfile(tmp_dir):
|
||||
src = "file1"
|
||||
dest = "file2"
|
||||
dest_dir = "testdir"
|
||||
|
||||
with open(src, "w+") as f:
|
||||
f.write("file1contents")
|
||||
tmp_dir.gen(src, "file1contents")
|
||||
|
||||
os.mkdir(dest_dir)
|
||||
os.mkdir(dest_dir)
|
||||
|
||||
utils.copyfile(src, dest)
|
||||
self.assertTrue(filecmp.cmp(src, dest, shallow=False))
|
||||
utils.copyfile(src, dest)
|
||||
assert (tmp_dir / dest).read_text() == "file1contents"
|
||||
|
||||
utils.copyfile(src, dest_dir)
|
||||
self.assertTrue(
|
||||
filecmp.cmp(src, "{}/{}".format(dest_dir, src), shallow=False)
|
||||
)
|
||||
utils.copyfile(src, dest_dir)
|
||||
assert (tmp_dir / dest_dir / src).read_text() == "file1contents"
|
||||
|
||||
shutil.rmtree(dest_dir)
|
||||
os.remove(src)
|
||||
os.remove(dest)
|
||||
|
||||
def test_file_md5_crlf(self):
|
||||
with open("cr", "wb+") as fd:
|
||||
fd.write(b"a\nb\nc")
|
||||
with open("crlf", "wb+") as fd:
|
||||
fd.write(b"a\r\nb\r\nc")
|
||||
def test_file_md5_crlf(tmp_dir):
|
||||
tmp_dir.gen("cr", b"a\nb\nc")
|
||||
tmp_dir.gen("crlf", b"a\r\nb\r\nc")
|
||||
assert utils.file_md5("cr")[0] == utils.file_md5("crlf")[0]
|
||||
|
||||
self.assertEqual(utils.file_md5("cr")[0], utils.file_md5("crlf")[0])
|
||||
|
||||
def test_dict_md5(self):
|
||||
d = {
|
||||
"cmd": "python code.py foo file1",
|
||||
"locked": "true",
|
||||
"outs": [
|
||||
{
|
||||
"path": "file1",
|
||||
"metric": {"type": "raw"},
|
||||
"cache": False,
|
||||
"md5": "acbd18db4cc2f85cedef654fccc4a4d8",
|
||||
}
|
||||
],
|
||||
"deps": [
|
||||
{"path": "foo", "md5": "acbd18db4cc2f85cedef654fccc4a4d8"},
|
||||
{"path": "code.py", "md5": "d05447644b89960913c7eee5fd776adb"},
|
||||
],
|
||||
}
|
||||
def test_dict_md5():
|
||||
d = {
|
||||
"cmd": "python code.py foo file1",
|
||||
"locked": "true",
|
||||
"outs": [
|
||||
{
|
||||
"path": "file1",
|
||||
"metric": {"type": "raw"},
|
||||
"cache": False,
|
||||
"md5": "acbd18db4cc2f85cedef654fccc4a4d8",
|
||||
}
|
||||
],
|
||||
"deps": [
|
||||
{"path": "foo", "md5": "acbd18db4cc2f85cedef654fccc4a4d8"},
|
||||
{"path": "code.py", "md5": "d05447644b89960913c7eee5fd776adb"},
|
||||
],
|
||||
}
|
||||
|
||||
md5 = "8b263fa05ede6c3145c164829be694b4"
|
||||
md5 = "8b263fa05ede6c3145c164829be694b4"
|
||||
|
||||
self.assertEqual(md5, utils.dict_md5(d, exclude=["metric", "locked"]))
|
||||
assert md5 == utils.dict_md5(d, exclude=["metric", "locked"])
|
||||
|
||||
def test_boxify(self):
|
||||
expected = (
|
||||
"+-----------------+\n"
|
||||
"| |\n"
|
||||
"| message |\n"
|
||||
"| |\n"
|
||||
"+-----------------+\n"
|
||||
)
|
||||
|
||||
assert expected == utils.boxify("message")
|
||||
def test_boxify():
|
||||
expected = (
|
||||
"+-----------------+\n"
|
||||
"| |\n"
|
||||
"| message |\n"
|
||||
"| |\n"
|
||||
"+-----------------+\n"
|
||||
)
|
||||
|
||||
assert expected == utils.boxify("message")
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name == "nt", reason="Not supported for Windows.")
|
||||
def test_makedirs_permissions(tmpdir):
|
||||
def test_makedirs_permissions(tmp_dir):
|
||||
dir_mode = 0o755
|
||||
os.chdir(str(tmpdir))
|
||||
intermediate_dir = "тестовая-директория"
|
||||
test_dir = os.path.join(intermediate_dir, "data")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user