Files
dvc/tests/test_add.py
T
Ruslan Kuprieiev f47a2c7585 dvc: initial unittests
Initial unittests for new design.

Signed-off-by: Ruslan Kuprieiev <[email protected]>
2018-01-01 16:52:06 +02:00

46 lines
1.3 KiB
Python

import os
import shutil
import filecmp
from dvc.data_cloud import file_md5
from dvc.stage import Stage, OutputNoCacheError, OutputOutsideOfRepoError
from dvc.stage import OutputDoesNotExistError, OutputIsNotFileError
from dvc.project import StageNotFoundError
from tests.basic_env import TestDvc
class TestAdd(TestDvc):
def test(self):
md5 = file_md5(self.FOO)[0]
stage = self.dvc.add(self.FOO)
self.assertIsInstance(stage, Stage)
self.assertTrue(os.path.isfile(stage.path))
self.assertEqual(len(stage.outs), 1)
self.assertEqual(len(stage.deps), 0)
self.assertTrue(stage.locked)
self.assertEqual(stage.cmd, None)
self.assertEqual(stage.outs[0].md5, md5)
class TestAddNonExistentFile(TestDvc):
def test(self):
with self.assertRaises(OutputDoesNotExistError) as cx:
self.dvc.add('non_existent_file')
class TestAddFileOutsideOfRepo(TestDvc):
def test(self):
with self.assertRaises(OutputOutsideOfRepoError) as cx:
self.dvc.add(os.path.join(os.path.dirname(self.dvc.root_dir), self.FOO))
class TestAddDirectory(TestDvc):
def test(self):
dname = 'directory'
os.mkdir(dname)
with self.assertRaises(OutputIsNotFileError) as cx:
self.dvc.add(dname)