def test_load_isolated_os_only_bad(self): data = { u'os': 'HP/UX', u'version': isolated_format.ISOLATED_FILE_VERSION, } with self.assertRaises(isolated_format.IsolatedError): isolated_format.load_isolated(json.dumps(data), isolateserver_mock.ALGO)
def _expect_results( self, args, read_only, extra_vars, empty_file, root_dir=None): self._expected_isolated(args, read_only, empty_file) self._expected_saved_state( args, read_only, empty_file, extra_vars, root_dir) # Also verifies run_isolated.py will be able to read it. with open(self.isolated, 'rb') as f: isolated_format.load_isolated(f.read(), ALGO)
def test_load_isolated_bad_abs(self): for i in ('/a', 'a/..', 'a/', '\\\\a'): data = { u'files': {i: {u'l': u'somewhere'}}, u'version': isolated_format.ISOLATED_FILE_VERSION, } with self.assertRaises(isolated_format.IsolatedError): isolated_format.load_isolated(json.dumps(data), isolateserver_mock.ALGO)
def test_load_isolated_bad(self): data = { u'files': { u'a': { u'l': u'somewhere', u'h': u'0123456789abcdef0123456789abcdef01234567' } }, u'version': isolated_format.ISOLATED_FILE_VERSION, } with self.assertRaises(isolated_format.IsolatedError): isolated_format.load_isolated(json.dumps(data), isolateserver_mock.ALGO)
def test_load_isolated_os_only(self): # Tolerate 'os' on older version. data = { u'os': 'HP/UX', u'version': '1.3', } m = isolated_format.load_isolated(json.dumps(data), isolateserver_mock.ALGO) self.assertEqual(data, m)
def test_load_isolated_path(self): # Automatically convert the path case. wrong_path_sep = u'\\' if os.path.sep == '/' else u'/' def gen_data(path_sep): return { u'command': [u'foo', u'bar'], u'files': { path_sep.join(('a', 'b')): { u'l': path_sep.join(('..', 'somewhere')), }, }, u'relative_cwd': path_sep.join(('somewhere', 'else')), u'version': isolated_format.ISOLATED_FILE_VERSION, } data = gen_data(wrong_path_sep) actual = isolated_format.load_isolated( json.dumps(data), isolateserver_mock.ALGO) expected = gen_data(os.path.sep) self.assertEqual(expected, actual)
def test_load_isolated_good(self): data = { u'command': [u'foo', u'bar'], u'files': { u'a': { u'l': u'somewhere', }, u'b': { u'm': 123, u'h': u'0123456789abcdef0123456789abcdef01234567', u's': 3, } }, u'includes': [u'0123456789abcdef0123456789abcdef01234567'], u'read_only': 1, u'relative_cwd': u'somewhere_else', u'version': isolated_format.ISOLATED_FILE_VERSION, } m = isolated_format.load_isolated(json.dumps(data), isolateserver_mock.ALGO) self.assertEqual(data, m)
def test_load_isolated_empty(self): m = isolated_format.load_isolated('{}', isolateserver_mock.ALGO) self.assertEqual({}, m)