def test_load_isolated_good(self): data = { u"command": [u"foo", u"bar"], u"files": { u"a": {u"l": u"somewhere", u"m": 123}, u"b": {u"m": 123, u"h": u"0123456789abcdef0123456789abcdef01234567"}, }, u"includes": [u"0123456789abcdef0123456789abcdef01234567"], u"os": run_isolated.get_flavor(), u"read_only": False, u"relative_cwd": u"somewhere_else", } m = run_isolated.load_isolated(json.dumps(data)) self.assertEquals(data, m)
def test_load_isolated_good(self): data = { u'command': [u'foo', u'bar'], u'files': { u'a': { u'l': u'somewhere', u'm': 123, }, u'b': { u'm': 123, u'h': u'0123456789abcdef0123456789abcdef01234567' } }, u'includes': [u'0123456789abcdef0123456789abcdef01234567'], u'os': run_isolated.get_flavor(), u'read_only': False, u'relative_cwd': u'somewhere_else' } m = run_isolated.load_isolated(json.dumps(data)) self.assertEquals(data, m)
def test_load_isolated_good(self): data = { u'command': [u'foo', u'bar'], u'files': { u'a': { u'l': u'somewhere', u'm': 123, }, u'b': { u'm': 123, u'h': u'0123456789abcdef0123456789abcdef01234567' } }, u'includes': [u'0123456789abcdef0123456789abcdef01234567'], u'os': run_isolated.get_flavor(), u'read_only': False, u'relative_cwd': u'somewhere_else' } m = run_isolated.load_isolated(json.dumps(data)) self.assertEqual(data, m)
def test_load_isolated_os_only(self): data = { u'os': run_isolated.get_flavor(), } m = run_isolated.load_isolated(json.dumps(data)) self.assertEquals(data, m)
def test_simple(self): # Create a directory with nothing in it and progressively add more stuff. isolate = os.path.join(self.srcdir, 'gtest_fake_pass.isolate') chromeos_value = int(run_isolated.get_flavor() == 'linux') condition = 'OS=="%s" and chromeos==%d' % (run_isolated.get_flavor(), chromeos_value) with open(isolate, 'w') as f: # Write a minimal .isolate file. f.write(str({ 'conditions': [ [condition, { 'variables': { 'command': [ 'run_test_cases.py', 'gtest_fake_pass.py', ], }, }], ], })) def _copy(filename): shutil.copy( os.path.join(BASE_DIR, 'gtest_fake', filename), os.path.join(self.srcdir, filename)) _copy('gtest_fake_base.py') _copy('gtest_fake_pass.py') shutil.copy( os.path.join(ROOT_DIR, 'run_test_cases.py'), os.path.join(self.srcdir, 'run_test_cases.py')) shutil.copy( os.path.join(ROOT_DIR, 'run_isolated.py'), os.path.join(self.srcdir, 'run_isolated.py')) logging.debug('1. Create a .isolated file out of the .isolate file.') isolated = os.path.join(self.srcdir, 'gtest_fake_pass.isolated') out = self._run(['isolate.py', 'check', '-i', isolate, '-s', isolated, '-V', 'chromeos', str(chromeos_value)]) if not VERBOSE: self.assertEqual('', out) logging.debug('2. Run fix_test_cases.py on it.') # Give up on looking at stdout. _ = self._run(['fix_test_cases.py', '-s', isolated]) logging.debug('3. Asserting the content of the .isolated file.') with open(isolated) as f: actual_isolated = json.load(f) gtest_fake_base_py = os.path.join(self.srcdir, 'gtest_fake_base.py') gtest_fake_pass_py = os.path.join(self.srcdir, 'gtest_fake_pass.py') run_isolated_py = os.path.join(self.srcdir, 'run_isolated.py') run_test_cases_py = os.path.join(self.srcdir, 'run_test_cases.py') expected_isolated = { u'command': [u'run_test_cases.py', u'gtest_fake_pass.py'], u'files': { u'gtest_fake_base.py': { u'm': 416, u'h': unicode(hashlib.sha1( open(gtest_fake_base_py, 'rb').read()).hexdigest()), u's': os.stat(gtest_fake_base_py).st_size, }, u'gtest_fake_pass.py': { u'm': 488, u'h': unicode(hashlib.sha1( open(gtest_fake_pass_py, 'rb').read()).hexdigest()), u's': os.stat(gtest_fake_pass_py).st_size, }, u'run_isolated.py': { u'm': 488, u'h': unicode(hashlib.sha1( open(run_isolated_py, 'rb').read()).hexdigest()), u's': os.stat(run_isolated_py).st_size, }, u'run_test_cases.py': { u'm': 488, u'h': unicode(hashlib.sha1( open(run_test_cases_py, 'rb').read()).hexdigest()), u's': os.stat(run_test_cases_py).st_size, }, }, u'os': unicode(run_isolated.get_flavor()), u'relative_cwd': u'.', } if sys.platform == 'win32': for value in expected_isolated['files'].itervalues(): self.assertTrue(value.pop('m')) self.assertEquals(expected_isolated, actual_isolated) # Now verify the .isolate file was updated! (That's the magical part where # you say wow!) with open(isolate) as f: actual = eval(f.read(), {'__builtins__': None}, None) expected = { 'conditions': [ [condition, { 'variables': { 'command': [ 'run_test_cases.py', 'gtest_fake_pass.py' ], 'isolate_dependency_tracked': [ 'gtest_fake_base.py', 'gtest_fake_pass.py', 'run_isolated.py', 'run_test_cases.py', ], }, }], ], } self.assertEqual(expected, actual)
def test_load_isolated_os_only(self): data = { u'os': run_isolated.get_flavor(), } m = run_isolated.load_isolated(json.dumps(data)) self.assertEqual(data, m)
def test_simple(self): # Create a directory with nothing in it and progressively add more stuff. isolate = os.path.join(self.srcdir, 'gtest_fake_pass.isolate') chromeos_value = int(run_isolated.get_flavor() == 'linux') condition = 'OS=="%s" and chromeos==%d' % (run_isolated.get_flavor(), chromeos_value) with open(isolate, 'w') as f: # Write a minimal .isolate file. f.write( str({ 'conditions': [ [ condition, { 'variables': { 'command': [ 'run_test_cases.py', 'gtest_fake_pass.py', ], }, } ], ], })) def _copy(filename): shutil.copy(os.path.join(BASE_DIR, 'gtest_fake', filename), os.path.join(self.srcdir, filename)) _copy('gtest_fake_base.py') _copy('gtest_fake_pass.py') shutil.copy(os.path.join(ROOT_DIR, 'run_test_cases.py'), os.path.join(self.srcdir, 'run_test_cases.py')) shutil.copy(os.path.join(ROOT_DIR, 'run_isolated.py'), os.path.join(self.srcdir, 'run_isolated.py')) logging.debug('1. Create a .isolated file out of the .isolate file.') isolated = os.path.join(self.srcdir, 'gtest_fake_pass.isolated') out = self._run([ 'isolate.py', 'check', '-i', isolate, '-s', isolated, '-V', 'chromeos', str(chromeos_value) ]) if not VERBOSE: self.assertEqual('', out) logging.debug('2. Run fix_test_cases.py on it.') # Give up on looking at stdout. _ = self._run(['fix_test_cases.py', '-s', isolated]) logging.debug('3. Asserting the content of the .isolated file.') with open(isolated) as f: actual_isolated = json.load(f) gtest_fake_base_py = os.path.join(self.srcdir, 'gtest_fake_base.py') gtest_fake_pass_py = os.path.join(self.srcdir, 'gtest_fake_pass.py') run_isolated_py = os.path.join(self.srcdir, 'run_isolated.py') run_test_cases_py = os.path.join(self.srcdir, 'run_test_cases.py') expected_isolated = { u'command': [u'run_test_cases.py', u'gtest_fake_pass.py'], u'files': { u'gtest_fake_base.py': { u'm': 416, u'h': unicode( hashlib.sha1(open(gtest_fake_base_py, 'rb').read()).hexdigest()), u's': os.stat(gtest_fake_base_py).st_size, }, u'gtest_fake_pass.py': { u'm': 488, u'h': unicode( hashlib.sha1(open(gtest_fake_pass_py, 'rb').read()).hexdigest()), u's': os.stat(gtest_fake_pass_py).st_size, }, u'run_isolated.py': { u'm': 488, u'h': unicode( hashlib.sha1(open(run_isolated_py, 'rb').read()).hexdigest()), u's': os.stat(run_isolated_py).st_size, }, u'run_test_cases.py': { u'm': 488, u'h': unicode( hashlib.sha1(open(run_test_cases_py, 'rb').read()).hexdigest()), u's': os.stat(run_test_cases_py).st_size, }, }, u'os': unicode(run_isolated.get_flavor()), u'relative_cwd': u'.', } if sys.platform == 'win32': for value in expected_isolated['files'].itervalues(): self.assertTrue(value.pop('m')) self.assertEqual(expected_isolated, actual_isolated) # Now verify the .isolate file was updated! (That's the magical part where # you say wow!) with open(isolate) as f: actual = eval(f.read(), {'__builtins__': None}, None) expected = { 'conditions': [ [ condition, { 'variables': { 'command': ['run_test_cases.py', 'gtest_fake_pass.py'], 'isolate_dependency_tracked': [ 'gtest_fake_base.py', 'gtest_fake_pass.py', 'run_isolated.py', 'run_test_cases.py', ], }, } ], ], } self.assertEqual(expected, actual)