From db12448a6ecddb69359e203399e88f5f120af401 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Mon, 16 Oct 2017 21:26:11 +0300 Subject: [PATCH] tests: fix cache tests Signed-off-by: Ruslan Kuprieiev --- tests/basic_env.py | 5 +++-- tests/test_data_file_obj.py | 18 +++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/basic_env.py b/tests/basic_env.py index bd8c51722..b5645b429 100644 --- a/tests/basic_env.py +++ b/tests/basic_env.py @@ -105,10 +105,11 @@ class DirHierarchyEnvironment(BasicEnvironment): 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) - self.create_content_file(state_result, 'state content') + 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"}') if cache_file: - cache_result = os.path.join(ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR, data_file + DataItem.CACHE_FILE_SEP + self._commit) + 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) diff --git a/tests/test_data_file_obj.py b/tests/test_data_file_obj.py index e686e3235..848dd3672 100644 --- a/tests/test_data_file_obj.py +++ b/tests/test_data_file_obj.py @@ -16,7 +16,8 @@ class TestDataFileObjBasic(BasicEnvironment): config = ConfigI('data') file = os.path.join('data', 'file.txt') - self._data_path = DataItem(file, git, config) + self.cache_file_full_path = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR, 'file.txt_ad45ba8') + self._data_path = DataItem(file, git, config, cache_file=self.cache_file_full_path) pass def test_data_file(self): @@ -24,8 +25,7 @@ class TestDataFileObjBasic(BasicEnvironment): self.assertEqual(self._data_path.data.abs, data_file_full_path) def test_cache_file(self): - cache_file_full_path = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR, 'file.txt_ad45ba8') - self.assertEqual(self._data_path.cache.abs, cache_file_full_path) + 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') @@ -156,7 +156,8 @@ class TestDataPathInDataDir(BasicEnvironment): self.path_factory = PathFactory(git, config) deep_path = os.path.join(self.data_dir, 'dir1', 'd2', 'file.txt') - self.data_path = self.path_factory.data_item(deep_path) + self.cache_file = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR, 'dir1', 'd2', 'file.txt_eeeff8f') + self.data_path = self.path_factory.data_item(deep_path, cache_file=self.cache_file) pass def test_data_file(self): @@ -164,8 +165,7 @@ class TestDataPathInDataDir(BasicEnvironment): self.assertEqual(self.data_path.data.abs, target) def test_cache_file(self): - target = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR, 'dir1', 'd2', 'file.txt_eeeff8f') - self.assertEqual(self.data_path.cache.abs, target) + 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') @@ -193,7 +193,8 @@ class TestDataFileObjLongPath(BasicEnvironment): self._config = ConfigI('data') self.path_factory = PathFactory(self._git, self._config) - self.data_path = self.path_factory.data_item(os.path.join('..', '..', 'data', 'file1.txt')) + self.cache_file = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR, 'file1.txt_123ed8') + self.data_path = self.path_factory.data_item(os.path.join('..', '..', 'data', 'file1.txt'), cache_file=self.cache_file) pass def test_data_file(self): @@ -201,8 +202,7 @@ class TestDataFileObjLongPath(BasicEnvironment): self.assertEqual(self.data_path.data.abs, target) def test_cache_file(self): - target = os.path.join(self._test_git_dir, ConfigI.CONFIG_DIR, ConfigI.CACHE_DIR, 'file1.txt_123ed8') - self.assertEqual(self.data_path.cache.abs, target) + 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')