12 # Use this hostname when you want to make sure the traffic will be
13 # instantly refused. 100::/64 is a dedicated black hole.
16 skip_sleep = mock.patch('time.sleep', lambda n: None) # clown'll eat me
18 def fake_httplib2_response(code, **headers):
19 headers.update(status=str(code),
20 reason=httplib.responses.get(code, "Unknown Response"))
21 return httplib2.Response(headers)
23 def mock_responses(body, *codes, **headers):
24 return mock.patch('httplib2.Http.request', side_effect=(
25 (fake_httplib2_response(code, **headers), body) for code in codes))
27 class ArvadosBaseTestCase(unittest.TestCase):
28 # This class provides common utility functions for our tests.
34 for workdir in self._tempdirs:
35 shutil.rmtree(workdir, ignore_errors=True)
37 def make_tmpdir(self):
38 self._tempdirs.append(tempfile.mkdtemp())
39 return self._tempdirs[-1]
41 def data_file(self, filename):
43 basedir = os.path.dirname(__file__)
46 return open(os.path.join(basedir, 'data', filename))
48 def build_directory_tree(self, tree):
49 tree_root = self.make_tmpdir()
51 path = os.path.join(tree_root, leaf)
53 os.makedirs(os.path.dirname(path))
54 except OSError as error:
55 if error.errno != errno.EEXIST:
57 with open(path, 'w') as tmpfile:
61 def make_test_file(self, text="test"):
62 testfile = tempfile.NamedTemporaryFile()