mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
Unittest to pytest: moved few unittest tests to pytest (#6379)
* tests: rm TestGit in func/test_init.py * tests: func: rm TestSCMGit in test_scm.py * test: func: rm _check_dirs in test_init.py * tests: func: minor fixes in test_scm.py * Update tests/func/test_scm.py Co-authored-by: Peter Rowlands (변기호) <[email protected]> Co-authored-by: Peter Rowlands (변기호) <[email protected]>
This commit is contained in:
co-authored by
Peter Rowlands
parent
114a07e7a4
commit
3be395b3a7
+30
-36
@@ -1,53 +1,47 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.config import Config
|
||||
from dvc.exceptions import InitError
|
||||
from dvc.main import main
|
||||
from dvc.repo import Repo as DvcRepo
|
||||
from tests.basic_env import TestDir, TestGit
|
||||
|
||||
|
||||
class TestInit(TestGit):
|
||||
def _test_init(self):
|
||||
self.assertTrue(os.path.exists(DvcRepo.DVC_DIR))
|
||||
self.assertTrue(os.path.isdir(DvcRepo.DVC_DIR))
|
||||
|
||||
def test_api(self):
|
||||
DvcRepo.init().close()
|
||||
|
||||
self._test_init()
|
||||
|
||||
def test_cli(self):
|
||||
ret = main(["init"])
|
||||
self.assertEqual(ret, 0)
|
||||
|
||||
self._test_init()
|
||||
def test_api_init(scm):
|
||||
DvcRepo.init().close()
|
||||
assert os.path.isdir(DvcRepo.DVC_DIR)
|
||||
|
||||
|
||||
class TestDoubleInit(TestInit):
|
||||
def test(self):
|
||||
ret = main(["init"])
|
||||
self.assertEqual(ret, 0)
|
||||
self._test_init()
|
||||
|
||||
ret = main(["init"])
|
||||
self.assertNotEqual(ret, 0)
|
||||
self._test_init()
|
||||
|
||||
ret = main(["init", "--force"])
|
||||
self.assertEqual(ret, 0)
|
||||
self._test_init()
|
||||
def test_cli_init(scm):
|
||||
ret = main(["init"])
|
||||
assert ret == 0
|
||||
assert os.path.isdir(DvcRepo.DVC_DIR)
|
||||
|
||||
|
||||
class TestInitNoSCMFail(TestDir):
|
||||
def test_api(self):
|
||||
with self.assertRaises(InitError):
|
||||
DvcRepo.init()
|
||||
def test_double_init(scm):
|
||||
ret = main(["init"])
|
||||
assert ret == 0
|
||||
assert os.path.isdir(DvcRepo.DVC_DIR)
|
||||
|
||||
def test_cli(self):
|
||||
ret = main(["init"])
|
||||
self.assertNotEqual(ret, 0)
|
||||
ret = main(["init"])
|
||||
assert ret != 0
|
||||
assert os.path.isdir(DvcRepo.DVC_DIR)
|
||||
|
||||
ret = main(["init", "--force"])
|
||||
assert ret == 0
|
||||
assert os.path.isdir(DvcRepo.DVC_DIR)
|
||||
|
||||
|
||||
def test_init_no_scm_fail_api(tmp_dir):
|
||||
with pytest.raises(InitError):
|
||||
DvcRepo.init()
|
||||
|
||||
|
||||
def test_init_no_scm_fail_cli(tmp_dir):
|
||||
ret = main(["init"])
|
||||
assert ret != 0
|
||||
|
||||
|
||||
def test_init_no_scm_api(tmp_dir):
|
||||
|
||||
+21
-21
@@ -7,7 +7,7 @@ from git import Repo
|
||||
from dvc.scm import SCM, Git, NoSCM
|
||||
from dvc.scm.base import SCMError
|
||||
from dvc.system import System
|
||||
from tests.basic_env import TestGit, TestGitSubmodule
|
||||
from tests.basic_env import TestGitSubmodule
|
||||
from tests.utils import get_gitignore_content
|
||||
|
||||
|
||||
@@ -34,27 +34,27 @@ def test_init_sub_dir(tmp_dir):
|
||||
assert scm.root_dir == os.fspath(tmp_dir)
|
||||
|
||||
|
||||
class TestSCMGit(TestGit):
|
||||
def test_commit(self):
|
||||
G = Git(self._root_dir)
|
||||
G.add(["foo"])
|
||||
G.commit("add")
|
||||
self.assertIn("foo", self.git.git.ls_files())
|
||||
def test_commit(tmp_dir, scm):
|
||||
tmp_dir.gen({"foo": "foo"})
|
||||
scm.add(["foo"])
|
||||
scm.commit("add")
|
||||
assert "foo" in scm.gitpython.git.ls_files()
|
||||
|
||||
def test_is_tracked(self):
|
||||
foo = os.path.abspath(self.FOO)
|
||||
G = Git(self._root_dir)
|
||||
G.add([self.FOO, self.UNICODE])
|
||||
self.assertTrue(G.is_tracked(foo))
|
||||
self.assertTrue(G.is_tracked(self.FOO))
|
||||
self.assertTrue(G.is_tracked(self.UNICODE))
|
||||
G.commit("add")
|
||||
self.assertTrue(G.is_tracked(foo))
|
||||
self.assertTrue(G.is_tracked(self.FOO))
|
||||
G.gitpython.repo.index.remove([self.FOO], working_tree=True)
|
||||
self.assertFalse(G.is_tracked(foo))
|
||||
self.assertFalse(G.is_tracked(self.FOO))
|
||||
self.assertFalse(G.is_tracked("not-existing-file"))
|
||||
|
||||
def test_is_tracked(tmp_dir, scm):
|
||||
tmp_dir.gen({"foo": "foo", "тест": "проверка"})
|
||||
scm.add(["foo", "тест"])
|
||||
abs_foo = os.path.abspath("foo")
|
||||
assert scm.is_tracked(abs_foo)
|
||||
assert scm.is_tracked("foo")
|
||||
assert scm.is_tracked("тест")
|
||||
scm.commit("add")
|
||||
assert scm.is_tracked(abs_foo)
|
||||
assert scm.is_tracked("foo")
|
||||
scm.gitpython.repo.index.remove(["foo"], working_tree=True)
|
||||
assert not scm.is_tracked(abs_foo)
|
||||
assert not scm.is_tracked("foo")
|
||||
assert not scm.is_tracked("not-existing-file")
|
||||
|
||||
|
||||
class TestSCMGitSubmodule(TestGitSubmodule):
|
||||
|
||||
Reference in New Issue
Block a user