Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Unified Diff: tools/isolate/isolate_smoke_test.py

Issue 10019014: Convert isolate.py to exclusively use .isolate files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Do not read as binary Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/isolate/isolate.py ('k') | tools/isolate/isolate_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/isolate/isolate_smoke_test.py
diff --git a/tools/isolate/isolate_smoke_test.py b/tools/isolate/isolate_smoke_test.py
index 721c3e031dc709f07c5bdd870e3d64c97f587589..727b9a1597a6407855a581635fc7d6c1f4540018 100755
--- a/tools/isolate/isolate_smoke_test.py
+++ b/tools/isolate/isolate_smoke_test.py
@@ -15,9 +15,11 @@ import sys
import tempfile
import unittest
+import isolate
+
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
VERBOSE = False
-FILENAME = os.path.basename(__file__)
+
class CalledProcessError(subprocess.CalledProcessError):
@@ -35,14 +37,18 @@ class CalledProcessError(subprocess.CalledProcessError):
class Isolate(unittest.TestCase):
def setUp(self):
- # The reason is that FILENAME --ok is run in a temporary directory
- # without access to isolate.py
- import isolate
- self.isolate = isolate
+ # The tests assume the current directory is the file's directory.
+ os.chdir(ROOT_DIR)
self.tempdir = tempfile.mkdtemp()
self.result = os.path.join(self.tempdir, 'result')
+ self.child = os.path.join('data', 'isolate', 'child.py')
if VERBOSE:
print
+ self.files = [
+ self.child,
+ os.path.join('data', 'isolate', 'files1', 'test_file1.txt'),
+ os.path.join('data', 'isolate', 'files1', 'test_file2.txt'),
+ ]
def tearDown(self):
shutil.rmtree(self.tempdir)
@@ -60,31 +66,51 @@ class Isolate(unittest.TestCase):
min_mode |= 0200
def mode(filename):
return (min_mode | 0111) if filename.endswith('.py') else min_mode
+
+ if not isinstance(files, dict):
+ # Update files to dict.
+ files = dict((unicode(f), {u'mode': mode(f)}) for f in files)
+ # Add size and timestamp.
+ files = files.copy()
+ for k, v in files.iteritems():
+ if v:
+ filestats = os.stat(k)
+ v[u'size'] = filestats.st_size
+ # Used the skip recalculating the hash. Use the most recent update
+ # time.
+ v[u'timestamp'] = int(round(
+ max(filestats.st_mtime, filestats.st_ctime)))
+
expected = {
- u'command':
- [unicode(sys.executable)] +
- [unicode(x) for x in args],
- u'files': dict((unicode(f), {u'mode': mode(f)}) for f in files),
- u'relative_cwd': u'.',
- u'read_only': False,
+ u'files': files,
+ u'relative_cwd': u'data/isolate',
+ u'read_only': None,
}
+ if args:
+ expected[u'command'] = [u'python'] + [unicode(x) for x in args]
+ else:
+ expected[u'command'] = []
if with_hash:
for filename in expected[u'files']:
# Calculate our hash.
h = hashlib.sha1()
h.update(open(os.path.join(ROOT_DIR, filename), 'rb').read())
- expected[u'files'][filename][u'sha-1'] = h.hexdigest()
+ expected[u'files'][filename][u'sha-1'] = unicode(h.hexdigest())
actual = json.load(open(self.result, 'rb'))
self.assertEquals(expected, actual)
return expected
- def _execute(self, args, need_output=False):
+ def _execute(self, filename, args, need_output=False):
cmd = [
sys.executable, os.path.join(ROOT_DIR, 'isolate.py'),
- '--root', ROOT_DIR,
+ '--variable', 'DEPTH=%s' % ROOT_DIR,
'--result', self.result,
- ]
+ os.path.join(ROOT_DIR, 'data', 'isolate', filename),
+ ] + args
+ env = os.environ.copy()
+ if 'ISOLATE_DEBUG' in env:
+ del env['ISOLATE_DEBUG']
if need_output or not VERBOSE:
stdout = subprocess.PIPE
stderr = subprocess.STDOUT
@@ -98,6 +124,7 @@ class Isolate(unittest.TestCase):
stdout=stdout,
stderr=stderr,
cwd=cwd,
+ env=env,
universal_newlines=True)
out = p.communicate()[0]
if p.returncode:
@@ -126,70 +153,40 @@ class Isolate(unittest.TestCase):
self._expected_tree([])
def test_check(self):
- cmd = [
- '--mode', 'check',
- FILENAME,
- ]
- self._execute(cmd)
+ self._execute('fail.isolate', ['--mode', 'check'])
self._expected_tree(['result'])
self._expected_result(
- False,
- [FILENAME],
- [os.path.join('.', FILENAME)],
- False)
+ False, dict((f, {}) for f in self.files), ['child.py', '--fail'], False)
- def test_check_non_existant(self):
- cmd = [
- '--mode', 'check',
- 'NonExistentFile',
- ]
+ def test_check_no_run(self):
+ self._execute('no_run.isolate', ['--mode', 'check'])
+ self._expected_tree(['result'])
+ self._expected_result(
+ False, dict((f, {}) for f in self.files), None, False)
+
+ def test_check_non_existent(self):
try:
- self._execute(cmd)
+ self._execute('non_existent.isolate', ['--mode', 'check'])
self.fail()
except subprocess.CalledProcessError:
pass
self._expected_tree([])
def test_check_directory_no_slash(self):
- cmd = [
- '--mode', 'check',
- # Trailing slash missing.
- os.path.join('data', 'isolate'),
- ]
try:
- self._execute(cmd)
+ self._execute('missing_trailing_slash.isolate', ['--mode', 'check'])
self.fail()
except subprocess.CalledProcessError:
pass
self._expected_tree([])
- def test_check_abs_path(self):
- cmd = [
- '--mode', 'check',
- FILENAME,
- '--',
- os.path.join(ROOT_DIR, FILENAME),
- ]
- self._execute(cmd)
- self._expected_tree(['result'])
- self._expected_result(
- False, [FILENAME], [FILENAME], False)
-
def test_hashtable(self):
cmd = [
'--mode', 'hashtable',
'--outdir', self.tempdir,
- FILENAME,
- os.path.join('data', 'isolate') + os.path.sep,
]
- self._execute(cmd)
- files = [
- FILENAME,
- os.path.join('data', 'isolate', 'test_file1.txt'),
- os.path.join('data', 'isolate', 'test_file2.txt'),
- ]
- data = self._expected_result(
- True, files, [os.path.join('.', FILENAME)], False)
+ self._execute('no_run.isolate', cmd)
+ data = self._expected_result(True, self.files, None, False)
self._expected_tree(
[f['sha-1'] for f in data['files'].itervalues()] + ['result'])
@@ -197,91 +194,60 @@ class Isolate(unittest.TestCase):
cmd = [
'--mode', 'remap',
'--outdir', self.tempdir,
- FILENAME,
]
- self._execute(cmd)
- self._expected_tree([FILENAME, 'result'])
+ self._execute('no_run.isolate', cmd)
+ self._expected_tree(['data', 'result'])
self._expected_result(
False,
- [FILENAME],
- [os.path.join('.', FILENAME)],
+ self.files,
+ None,
False)
def test_run(self):
- cmd = [
- '--mode', 'run',
- FILENAME,
- '--',
- sys.executable, FILENAME, '--ok',
- ]
- self._execute(cmd)
+ self._execute('ok.isolate', ['--mode', 'run'])
self._expected_tree(['result'])
# cmd[0] is not generated from infiles[0] so it's not using a relative path.
self._expected_result(
- False, [FILENAME], [FILENAME, '--ok'], False)
+ False, self.files, ['child.py', '--ok'], False)
def test_run_fail(self):
- cmd = [
- '--mode', 'run',
- FILENAME,
- '--',
- sys.executable, FILENAME, '--fail',
- ]
try:
- self._execute(cmd)
+ self._execute('fail.isolate', ['--mode', 'run'])
self.fail()
except subprocess.CalledProcessError:
pass
- self._expected_tree([])
+ self._expected_tree(['result'])
def test_trace(self):
- cmd = [
- '--mode', 'trace',
- FILENAME,
- '--',
- sys.executable, os.path.join(ROOT_DIR, FILENAME), '--ok',
- ]
- out = self._execute(cmd, True)
- expected_tree = ['result', 'result.log']
- if sys.platform == 'win32':
- expected_tree.append('result.log.etl')
- self._expected_tree(expected_tree)
+ out = self._execute('ok.isolate', ['--mode', 'trace'], True)
+ self._expected_tree(['result', 'result.log'])
# The 'result.log' log is OS-specific so we can't read it but we can read
# the gyp result.
# cmd[0] is not generated from infiles[0] so it's not using a relative path.
self._expected_result(
- False, [FILENAME], [FILENAME, '--ok'], False)
+ False, self.files, ['child.py', '--ok'], False)
expected_value = {
'conditions': [
- ['OS=="%s"' % self.isolate.trace_inputs.get_flavor(), {
+ ['OS=="%s"' % isolate.trace_inputs.get_flavor(), {
'variables': {
- 'isolate_files': [
- '<(DEPTH)/%s' % FILENAME,
+ isolate.trace_inputs.KEY_TRACKED: [
+ 'child.py',
+ ],
+ isolate.trace_inputs.KEY_UNTRACKED: [
+ 'files1/',
],
},
}],
],
}
expected_buffer = cStringIO.StringIO()
- self.isolate.trace_inputs.pretty_print(expected_value, expected_buffer)
+ isolate.trace_inputs.pretty_print(expected_value, expected_buffer)
self.assertEquals(expected_buffer.getvalue(), out)
-def main():
- global VERBOSE
- VERBOSE = '-v' in sys.argv
- level = logging.DEBUG if VERBOSE else logging.ERROR
- logging.basicConfig(level=level)
- if len(sys.argv) == 1:
- unittest.main()
- if sys.argv[1] == '--ok':
- return 0
- if sys.argv[1] == '--fail':
- return 1
-
- unittest.main()
-
if __name__ == '__main__':
- sys.exit(main())
+ VERBOSE = '-v' in sys.argv
+ logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR)
+ unittest.main()
« no previous file with comments | « tools/isolate/isolate.py ('k') | tools/isolate/isolate_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698