def test(self): stages = self.dvc.add(self.DATA_DIR) self.assertEqual(len(stages), 1) self.dir_stage = stages[0] self.assertTrue(self.dir_stage is not None) sleep() self.file1 = 'file1' self.file1_stage = self.file1 + '.dvc' self.dvc.run(fname=self.file1_stage, outs=[self.file1], deps=[self.DATA, self.CODE], cmd='python {} {} {}'.format(self.CODE, self.DATA, self.file1)) self.assertTrue(filecmp.cmp(self.file1, self.DATA, shallow=False)) os.unlink(self.DATA) shutil.copyfile(self.FOO, self.DATA) sleep() stages = self.dvc.reproduce(self.file1_stage) self.assertEqual(len(stages), 2) self.assertTrue(filecmp.cmp(self.file1, self.FOO, shallow=False))
def test(self): if not self.should_test(): return cache = self.scheme + self.scheme_sep + self.bucket + self.sep + str(uuid.uuid4()) ret = main(['config', 'cache.' + self.cache_scheme, 'myrepo']) self.assertEqual(ret, 0) ret = main(['remote', 'add', 'myrepo', cache]) self.assertEqual(ret, 0) remote_name = 'myremote' remote_key = str(uuid.uuid4()) remote = self.scheme + self.scheme_sep + self.bucket + self.sep + remote_key ret = main(['remote', 'add', remote_name, remote]) self.assertEqual(ret, 0) self.dvc = Project('.') foo_key = remote_key + self.sep + self.FOO bar_key = remote_key + self.sep + self.BAR foo_path = self.scheme + self.scheme_sep + self.bucket + self.sep + foo_key bar_path = self.scheme + self.scheme_sep + self.bucket + self.sep + bar_key # Using both plain and remote notation out_foo_path = 'remote://' + remote_name + '/' + self.FOO out_bar_path = bar_path self.write(self.bucket, foo_key, self.FOO_CONTENTS) sleep() import_stage = self.dvc.imp(out_foo_path, 'import') self.assertTrue(os.path.exists('import')) self.assertTrue(filecmp.cmp('import', self.FOO)) import_remote_stage = self.dvc.imp(out_foo_path, out_foo_path + '_imported') cmd_stage = self.dvc.run(outs=[out_bar_path], deps=[out_foo_path], cmd=self.cmd(foo_path, bar_path)) self.write(self.bucket, foo_key, self.BAR_CONTENTS) sleep() stages = self.dvc.reproduce(import_stage.path) self.assertEqual(len(stages), 1) self.assertTrue(os.path.exists('import')) self.assertTrue(filecmp.cmp('import', self.BAR)) stages = self.dvc.reproduce(cmd_stage.path) self.assertEqual(len(stages), 1) self.dvc.gc() self.dvc.remove(cmd_stage.path, outs_only=True) self.dvc.checkout(cmd_stage.path)
def test(self, mock_prompt): from tests.test_data_cloud import sleep mock_prompt.return_value = True stages = self.dvc.add(self.DATA_DIR) stage = stages[0] sleep() working_dir_change = os.path.join(self.DATA_DIR, 'not_cached.txt') with open(working_dir_change, 'w') as f: f.write('not_cached') sleep() ret = main(['checkout', stage.relpath]) self.assertEqual(ret, 0) self.assertFalse(os.path.exists(working_dir_change))
def test(self): from tests.test_data_cloud import sleep # Use copy to test for changes in the inodes ret = main(['config', 'cache.type', 'copy']) self.assertEqual(ret, 0) stages = self.dvc.add(self.DATA_DIR) self.assertEqual(len(stages), 1) stage = stages[0] staged_files = self.outs_info(stage) sleep() os.remove(staged_files[0].path) sleep() ret = main(['checkout', '--force', stage.relpath]) self.assertEqual(ret, 0) sleep() checkedout_files = self.outs_info(stage) self.assertEqual(len(staged_files), len(checkedout_files)) self.assertEqual(staged_files[0].path, checkedout_files[0].path) self.assertNotEqual(staged_files[0].inode, checkedout_files[0].inode) self.assertEqual(staged_files[1].inode, checkedout_files[1].inode)
def test_force(self, mock_prompt): from tests.test_data_cloud import sleep mock_prompt.return_value = False stages = self.dvc.add(self.DATA_DIR) self.assertEqual(len(stages), 1) stage = stages[0] sleep() working_dir_change = os.path.join(self.DATA_DIR, 'not_cached.txt') with open(working_dir_change, 'w') as f: f.write('not_cached') sleep() ret = main(['checkout', stage.relpath]) self.assertNotEqual(ret, 0) mock_prompt.assert_called() self.assertNotEqual(ret, 0) self.assertRaises(DvcException)
def test(self): stages = self.dvc.add(self.DATA) self.assertEqual(len(stages), 1) self.assertTrue(stages[0] is not None) sleep() stages = self.dvc.add(self.DATA_SUB) self.assertEqual(len(stages), 1) self.assertTrue(stages[0] is not None) sleep() stage = self.dvc.run(fname='Dvcfile', deps=[self.DATA, self.DATA_SUB]) self.assertTrue(stage is not None) sleep() file1 = 'file1' file1_stage = file1 + '.dvc' stage = self.dvc.run(fname=file1_stage, deps=[self.DATA_DIR], outs=[file1], cmd='python {} {} {}'.format( self.CODE, self.DATA, file1)) self.assertTrue(stage is not None) sleep() os.unlink(self.DATA) shutil.copyfile(self.FOO, self.DATA) sleep() stages = self.dvc.reproduce(file1_stage) self.assertEqual(len(stages), 2)
def test(self): dir_name = 'dir' dir_code = 'dir_code.py' sleep() with open(dir_code, 'w+') as fd: fd.write( "import os; import sys; import shutil; shutil.copytree(sys.argv[1], sys.argv[2])" ) sleep() stage = self.dvc.run(outs=[dir_name], deps=[self.DATA_DIR, dir_code], cmd="python {} {} {}".format( dir_code, self.DATA_DIR, dir_name)) self.assertTrue(stage is not None) stages = self.dvc.reproduce(stage.path) self.assertEqual(len(stages), 0) sleep() with open(self.DATA_SUB, 'a') as fd: fd.write('add') sleep() stages = self.dvc.reproduce(stage.path) self.assertEqual(len(stages), 1) self.assertTrue(stages[0] is not None) sleep() # Check that dvc indeed registers changed output dir shutil.move(self.BAR, dir_name) sleep() stages = self.dvc.reproduce(stage.path) self.assertEqual(len(stages), 1) self.assertTrue(stages[0] is not None) # Check that dvc registers mtime change for the directory. System.hardlink(self.DATA_SUB, self.DATA_SUB + '.lnk') sleep() stages = self.dvc.reproduce(stage.path) self.assertEqual(len(stages), 1) self.assertTrue(stages[0] is not None)