mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
import os
|
|
|
|
from git import Repo
|
|
|
|
from dvc.scm import SCM, Base, Git
|
|
|
|
from tests.basic_env import TestDir, TestGit, TestGitSubmodule
|
|
from tests.utils import get_gitignore_content
|
|
|
|
|
|
class TestSCM(TestDir):
|
|
def test_none(self):
|
|
self.assertIsInstance(SCM(self._root_dir), Base)
|
|
|
|
def test_git(self):
|
|
Repo.init(os.curdir)
|
|
self.assertIsInstance(SCM(self._root_dir), Git)
|
|
|
|
|
|
class TestSCMGit(TestGit):
|
|
def test_is_repo(self):
|
|
self.assertTrue(Git.is_repo(os.curdir))
|
|
|
|
def test_commit(self):
|
|
G = Git(self._root_dir)
|
|
G.add(["foo"])
|
|
G.commit("add")
|
|
self.assertTrue("foo" in self.git.git.ls_files())
|
|
|
|
|
|
class TestSCMGitSubmodule(TestGitSubmodule):
|
|
def test_git_submodule(self):
|
|
self.assertIsInstance(SCM(os.curdir), Git)
|
|
|
|
def test_is_submodule(self):
|
|
self.assertTrue(Git.is_submodule(os.curdir))
|
|
|
|
def test_commit_in_submodule(self):
|
|
G = Git(self._root_dir)
|
|
G.add(["foo"])
|
|
G.commit("add")
|
|
self.assertTrue("foo" in self.git.git.ls_files())
|
|
|
|
|
|
class TestIgnore(TestGit):
|
|
def _count_gitignore(self):
|
|
lines = get_gitignore_content()
|
|
|
|
return len(list(filter(lambda x: x.strip() == "/" + self.FOO, lines)))
|
|
|
|
def test(self):
|
|
git = Git(self._root_dir)
|
|
foo = os.path.join(self._root_dir, self.FOO)
|
|
|
|
git.ignore(foo)
|
|
self.assertTrue(os.path.isfile(Git.GITIGNORE))
|
|
self.assertEqual(self._count_gitignore(), 1)
|
|
|
|
git.ignore(foo)
|
|
self.assertEqual(self._count_gitignore(), 1)
|
|
|
|
git.ignore_remove(foo)
|
|
self.assertEqual(self._count_gitignore(), 0)
|