diff --git a/tests/basic_env.py b/tests/basic_env.py index b5645b429..ebfdab9fd 100644 --- a/tests/basic_env.py +++ b/tests/basic_env.py @@ -35,7 +35,7 @@ class BasicEnvironment(TestCase): data_dir = os.path.join(self._test_git_dir, 'data') cache_dir = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR) - state_dir = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.STATE_DIR) + state_dir = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, 'data') os.makedirs(data_dir) os.makedirs(cache_dir) @@ -103,7 +103,7 @@ class DirHierarchyEnvironment(BasicEnvironment): def crate_data_item(self, data_file, cache_file=True, content='random text'): file_result = os.path.join('data', data_file) - state_result = os.path.join(ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, data_file + DataItem.STATE_FILE_SUFFIX) + state_result = os.path.join(ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, file_result + DataItem.STATE_FILE_SUFFIX) dummy_md5 = os.path.basename(data_file) + DataItem.CACHE_FILE_SEP + self._commit self.create_content_file(state_result, '{"Md5" : "' + dummy_md5 + '", "Command" : "run", "Cwd" : "dir"}') @@ -112,23 +112,13 @@ class DirHierarchyEnvironment(BasicEnvironment): cache_result = os.path.join(ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR, dummy_md5) self.create_content_file(cache_result, content) - relevant_dir = self.relevant_dir(data_file) - System.symlink(os.path.join(relevant_dir, cache_result), file_result) + System.hardlink(cache_result, file_result) else: cache_result = None self.create_content_file(file_result, content) return file_result, cache_result, state_result - @staticmethod - def relevant_dir(data_file): - deepth = data_file.count(os.path.sep) - relevant_path = '..' - for i in range(deepth): - relevant_path = os.path.join(relevant_path, '..') - return relevant_path - def create_dirs(self, dir): - os.mkdir(os.path.join('data', dir)) - os.mkdir(os.path.join(ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR, dir)) - os.mkdir(os.path.join(ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, dir)) + os.makedirs(os.path.join('data', dir)) + os.makedirs(os.path.join(ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, 'data', dir)) diff --git a/tests/test_cmd_remove.py b/tests/test_cmd_remove.py index 168f3a8c6..bbd24454d 100644 --- a/tests/test_cmd_remove.py +++ b/tests/test_cmd_remove.py @@ -139,8 +139,8 @@ class TestRemoveEndToEndWithAnError(DirHierarchyEnvironment): DirHierarchyEnvironment.init_environment(self) def test(self): - dir11_full = os.path.join(self._config.data_dir, self.dir11) - dir2_full = os.path.join(self._config.data_dir, self.dir2) + dir11_full = os.path.join('data', self.dir11) + dir2_full = os.path.join('data', self.dir2) self.settings.parse_args('remove --no-git-actions --keep-in-cloud --recursive {} {}'.format(dir11_full, self.file5)) cmd = CmdRemove(self.settings) diff --git a/tests/test_cmd_run.py b/tests/test_cmd_run.py index fb6fc249b..8c2772390 100644 --- a/tests/test_cmd_run.py +++ b/tests/test_cmd_run.py @@ -55,16 +55,6 @@ class RunBasicTest(TestCase): os.chdir(self._old_curr_dir_abs) -class TestRunOutsideData(RunBasicTest): - def test(self): - self.settings._args = [] - cmd_run = CmdRun(self.settings) - with self.assertRaises(RunError): - cmd_run.run_command(['echo', 'test'], [], [], shell=True, - stdout='file1', stderr='file2') - pass - - class RunTwoFilesBase(RunBasicTest): def setUp(self): super(RunTwoFilesBase, self).setUp() @@ -82,8 +72,8 @@ class RunTwoFilesBase(RunBasicTest): stdout=self.file_name1, stderr=self.file_name2) - self.state_file_name1 = os.path.join(ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, 'file1' + DataItem.STATE_FILE_SUFFIX) - self.state_file_name2 = os.path.join(ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, 'file2' + DataItem.STATE_FILE_SUFFIX) + self.state_file_name1 = os.path.join(ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, self.file_name1 + DataItem.STATE_FILE_SUFFIX) + self.state_file_name2 = os.path.join(ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, self.file_name2 + DataItem.STATE_FILE_SUFFIX) self.state_file1 = None self.state_file2 = None diff --git a/tests/test_data_file_obj.py b/tests/test_data_file_obj.py index 848dd3672..cc7ea821a 100644 --- a/tests/test_data_file_obj.py +++ b/tests/test_data_file_obj.py @@ -2,7 +2,7 @@ import os from dvc.config import ConfigI from dvc.git_wrapper import GitWrapperI -from dvc.path.data_item import NotInDataDirError, DataItemError, DataItem +from dvc.path.data_item import DataDirError, DataItemError, DataItem from dvc.path.factory import PathFactory from dvc.system import System from tests.basic_env import BasicEnvironment @@ -13,7 +13,7 @@ class TestDataFileObjBasic(BasicEnvironment): BasicEnvironment.init_environment(self, test_dir=os.path.join(os.path.sep, 'tmp', 'ntx_unit_test')) git = GitWrapperI(git_dir=self._test_git_dir, commit='ad45ba8') - config = ConfigI('data') + config = ConfigI() file = os.path.join('data', 'file.txt') self.cache_file_full_path = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR, 'file.txt_ad45ba8') @@ -28,13 +28,9 @@ class TestDataFileObjBasic(BasicEnvironment): self.assertEqual(self._data_path.cache.abs, self.cache_file_full_path) def test_state_file(self): - state_file_full_path = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, 'file.txt.state') + state_file_full_path = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, 'data', 'file.txt.state') self.assertEqual(self._data_path.state.abs, state_file_full_path) - def test_data_dvs_short(self): - self.assertEqual(self._data_path.data_dvc_short, 'file.txt') - pass - class TestDataItemWithGivenCache(BasicEnvironment): def setUp(self): @@ -53,9 +49,6 @@ class TestDataItemWithGivenCache(BasicEnvironment): self.assertEqual(self._data_item.data.relative, self._file) self.assertEqual(self._data_item.cache.relative, self._cache) - def test_resolve_unexist_symlink(self): - self.assertEqual(self._data_item.resolved_cache.relative, self._file) - class TestDeepDataItemWithGivenCache(BasicEnvironment): def setUp(self): @@ -80,18 +73,22 @@ class TestPathFactory(BasicEnvironment): BasicEnvironment.init_environment(self, test_dir=os.path.join(os.path.sep, 'tmp', 'ntx_unit_test')) git = GitWrapperI(git_dir=self._test_git_dir, commit='ad45ba8') - config = ConfigI('data') + config = ConfigI() self.path_factory = PathFactory(git, config) self.data_file = os.path.join('data', 'file.txt') - self.cache_file = os.path.join(ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR, 'fsymlinc.txt') + dummy_md5 = 'fsymlinc.txt' + self.cache_file = os.path.join(ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR, dummy_md5) + self.state_file = os.path.join(ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, 'data', 'file.txt' + DataItem.STATE_FILE_SUFFIX) - fd = open(self.cache_file, 'w+') - fd.write('some text') - fd.close() + with open(self.cache_file, 'w+') as fd: + fd.write('some text') + + with open(self.state_file, 'w+') as fd: + fd.write('{"Md5" : "' + dummy_md5 + '", "Command" : "run", "Cwd" : "dir"}') os.chdir('data') - System.symlink(os.path.join('..', self.cache_file), 'file.txt') + System.hardlink(os.path.join('..', self.cache_file), 'file.txt') os.chdir('..') pass @@ -104,17 +101,17 @@ class TestPathFactory(BasicEnvironment): self.assertEqual(data_path_indirect.data.dvc, self.data_file) pass - def test_data_symlink_factory(self): + def test_data_hardlink_factory(self): data_path = self.path_factory.existing_data_item(self.data_file) self.assertEqual(data_path.cache.dvc, self.cache_file) pass - def test_data_symlink_factory_cache(self): + def test_data_hardlink_factory_cache(self): data_path = self.path_factory.existing_data_item(self.data_file) self.assertEqual(data_path.data.dvc, self.data_file) pass - def test_data_symlink_factory_exception(self): + def test_data_hardlink_factory_exception(self): with self.assertRaises(DataItemError): self.path_factory.existing_data_item(self.cache_file) pass @@ -126,25 +123,6 @@ class TestPathFactory(BasicEnvironment): self.assertEqual(path.relative, file) self.assertTrue(path.abs.endswith(file)) - def test_to_data_path(self): - exclude_file = os.path.join(ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR, 'file2') - data_path_file1 = os.path.join('data', 'file1') - data_path_file2 = os.path.join('data', 'file2') - files = [ - data_path_file1, - exclude_file, - data_path_file2 - ] - - data_path_list, exclude_file_list = self.path_factory.to_data_items(files) - - self.assertEqual(len(data_path_list), 2) - self.assertEqual(len(exclude_file_list), 1) - - self.assertEqual(exclude_file_list[0], exclude_file) - data_path_set = set(x.data.dvc for x in data_path_list) - self.assertEqual(data_path_set, {data_path_file1, data_path_file2}) - class TestDataPathInDataDir(BasicEnvironment): def setUp(self): @@ -152,7 +130,7 @@ class TestDataPathInDataDir(BasicEnvironment): git = GitWrapperI(git_dir=self._test_git_dir, commit='eeeff8f') self.data_dir = 'da' - config = ConfigI(self.data_dir) + config = ConfigI() self.path_factory = PathFactory(git, config) deep_path = os.path.join(self.data_dir, 'dir1', 'd2', 'file.txt') @@ -168,18 +146,9 @@ class TestDataPathInDataDir(BasicEnvironment): self.assertEqual(self.data_path.cache.abs, self.cache_file) def test_state_file(self): - target = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, 'dir1', 'd2', 'file.txt.state') + target = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, 'da', 'dir1', 'd2', 'file.txt.state') self.assertEqual(self.data_path.state.abs, target) - def test_symlink(self): - expected = os.path.join('..', '..', '..', ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR, 'dir1', 'd2', 'file.txt_eeeff8f') - self.assertEqual(self.data_path.symlink_file, expected) - - def test_data_dir(self): - data_path = self.path_factory.data_item(self.data_dir) - self.assertEqual(data_path.data.dvc, self.data_dir) - self.assertEqual(data_path.data_dvc_short, '') - class TestDataFileObjLongPath(BasicEnvironment): def setUp(self): @@ -205,24 +174,9 @@ class TestDataFileObjLongPath(BasicEnvironment): self.assertEqual(self.data_path.cache.abs, self.cache_file) def test_state_file(self): - target = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, 'file1.txt.state') + target = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.STATE_DIR, 'data', 'file1.txt.state') self.assertEqual(self.data_path.state.abs, target) - def test_file_name_only(self): - with self.assertRaises(NotInDataDirError): - self.path_factory.data_item('file.txt') - pass - - def test_relative_git_dir(self): - with self.assertRaises(NotInDataDirError): - self.path_factory.data_item('data/file.txt') - pass - - def test_relative_path_error(self): - with self.assertRaises(NotInDataDirError): - self.path_factory.data_item('../data/file.txt') - pass - class RunOutsideGitRepoTest(BasicEnvironment): def setUp(self): @@ -237,6 +191,6 @@ class RunOutsideGitRepoTest(BasicEnvironment): config = ConfigI('data') path_factory = PathFactory(git, config) - with self.assertRaises(NotInDataDirError): + with self.assertRaises(DataDirError): path_factory.data_item('file.txt') pass diff --git a/tests/test_import.py b/tests/test_import.py index 96b24fcc6..8cec2ef39 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -1,5 +1,6 @@ import os import tempfile +import filecmp from copy import copy from dvc.command.import_file import CmdImportFile, ImportFileError @@ -26,7 +27,7 @@ class TestCmdRemove(DirHierarchyEnvironment): data_item = self.path_factory.existing_data_item(dvc_name) self.assertTrue(os.path.exists(data_item.data.relative)) - self.assertTrue(os.path.islink(data_item.data.relative)) + self.assertTrue(filecmp.cmp(data_item.data.relative, data_item.cache.relative)) self.assertEqual(open(data_item.data.relative).read(), content) self.assertTrue(os.path.exists(data_item.cache.relative)) diff --git a/tests/test_repository_change.py b/tests/test_repository_change.py index 2425464cb..cbce53338 100644 --- a/tests/test_repository_change.py +++ b/tests/test_repository_change.py @@ -26,7 +26,7 @@ class BasicTestRepositoryChange(TestCase): subprocess.Popen(['git', 'init'], stdout=self._devnull, stderr=None).wait() self.git = GitWrapperI(self.test_dir) - self.config = ConfigI('data', 'cache', 'state') + self.config = ConfigI() self.path_factory = PathFactory(self.git, self.config) self.settings = Settings([], self.git, self.config) @@ -96,16 +96,3 @@ class TestRepositoryChangeDeepInDirectory(BasicTestRepositoryChange): self.assertEqual([x.data.dvc for x in change.new_data_items], [deep_file]) -class TestRepositoryChangeExternallyCreated(BasicTestRepositoryChange): - def test(self): - not_in_data_dir_file = 'file1.txt' - self.create_file(not_in_data_dir_file) - - change = RepositoryChange(['echo', 'textsd'], - self.settings, - not_in_data_dir_file, - None, - shell=True) - - self.assertEqual([System.realpath(not_in_data_dir_file)], - change.externally_created_files)