9 class ArvadosBaseTestCase(unittest.TestCase):
10 # This class provides common utility functions for our tests.
16 for workdir in self._tempdirs:
17 shutil.rmtree(workdir, ignore_errors=True)
19 def make_tmpdir(self):
20 self._tempdirs.append(tempfile.mkdtemp())
21 return self._tempdirs[-1]
23 def data_file(self, filename):
25 basedir = os.path.dirname(__file__)
28 return open(os.path.join(basedir, 'data', filename))
31 class ArvadosKeepLocalStoreTestCase(ArvadosBaseTestCase):
33 super(ArvadosKeepLocalStoreTestCase, self).setUp()
34 self._orig_keep_local_store = os.environ.get('KEEP_LOCAL_STORE')
35 os.environ['KEEP_LOCAL_STORE'] = self.make_tmpdir()
38 if self._orig_keep_local_store is None:
39 del os.environ['KEEP_LOCAL_STORE']
41 os.environ['KEEP_LOCAL_STORE'] = self._orig_keep_local_store
42 super(ArvadosKeepLocalStoreTestCase, self).tearDown()
44 def build_directory_tree(self, tree):
45 tree_root = self.make_tmpdir()
47 path = os.path.join(tree_root, leaf)
49 os.makedirs(os.path.dirname(path))
50 except OSError as error:
51 if error.errno != errno.EEXIST:
53 with open(path, 'w') as tmpfile:
57 def make_test_file(self, text="test"):
58 testfile = tempfile.NamedTemporaryFile()