11 def fake_httplib2_response(code, **headers):
12 headers.update(status=str(code),
13 reason=httplib.responses.get(code, "Unknown Response"))
14 return httplib2.Response(headers)
16 class ArvadosBaseTestCase(unittest.TestCase):
17 # This class provides common utility functions for our tests.
23 for workdir in self._tempdirs:
24 shutil.rmtree(workdir, ignore_errors=True)
26 def make_tmpdir(self):
27 self._tempdirs.append(tempfile.mkdtemp())
28 return self._tempdirs[-1]
30 def data_file(self, filename):
32 basedir = os.path.dirname(__file__)
35 return open(os.path.join(basedir, 'data', filename))
37 def build_directory_tree(self, tree):
38 tree_root = self.make_tmpdir()
40 path = os.path.join(tree_root, leaf)
42 os.makedirs(os.path.dirname(path))
43 except OSError as error:
44 if error.errno != errno.EEXIST:
46 with open(path, 'w') as tmpfile:
50 def make_test_file(self, text="test"):
51 testfile = tempfile.NamedTemporaryFile()