diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-05 07:23:24 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-05 07:23:24 +0000 |
commit | 7095e6987be13e147e25fe142874b3a0583864fb (patch) | |
tree | ddce42c34a7b3a99f8098a23be74b315a958d151 /tools/isolate/trace_inputs_test.py | |
parent | ce2d3b50ce2291f86b03c14bf448ba223757738a (diff) | |
download | chromium_src-7095e6987be13e147e25fe142874b3a0583864fb.zip chromium_src-7095e6987be13e147e25fe142874b3a0583864fb.tar.gz chromium_src-7095e6987be13e147e25fe142874b3a0583864fb.tar.bz2 |
Add merge_gyp.py to merge OS specific dependencies into a single list and pretty print it.
Add more tests, rename trace_inputs_test.py to trace_inputs_smoke_test.py to add
proper unit test.
Rewrite trace_input.py gyp generation to be more generic.
R=rogerta@chromium.org
BUG=98834
TEST=
Review URL: http://codereview.chromium.org/9939005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130857 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/isolate/trace_inputs_test.py')
-rwxr-xr-x | tools/isolate/trace_inputs_test.py | 194 |
1 files changed, 57 insertions, 137 deletions
diff --git a/tools/isolate/trace_inputs_test.py b/tools/isolate/trace_inputs_test.py index 0ef644c..3830b79 100755 --- a/tools/isolate/trace_inputs_test.py +++ b/tools/isolate/trace_inputs_test.py @@ -3,153 +3,73 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import logging -import os -import shutil -import subprocess -import sys -import tempfile +import cStringIO import unittest -ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) - -VERBOSE = False - - -class CalledProcessError(subprocess.CalledProcessError): - """Makes 2.6 version act like 2.7""" - def __init__(self, returncode, cmd, output, cwd): - super(CalledProcessError, self).__init__(returncode, cmd) - self.output = output - self.cwd = cwd - - def __str__(self): - return super(CalledProcessError, self).__str__() + ( - '\n' - 'cwd=%s\n%s') % (self.cwd, self.output) +import trace_inputs class TraceInputs(unittest.TestCase): - def setUp(self): - self.tempdir = tempfile.mkdtemp() - self.log = os.path.join(self.tempdir, 'log') - os.chdir(ROOT_DIR) - - def tearDown(self): - shutil.rmtree(self.tempdir) - - def _execute(self, is_gyp): - cmd = [ - sys.executable, os.path.join('..', 'trace_inputs.py'), - '--log', self.log, - '--root-dir', ROOT_DIR, - ] - if is_gyp: - cmd.extend( - [ - '--cwd', 'data', - '--product', '.', # Not tested. - ]) - cmd.append(os.path.join('..', 'trace_inputs_test.py')) - if is_gyp: - # When the gyp argument is not specified, the command is started from - # --root-dir directory. - cmd.append('--child-gyp') - else: - # When the gyp argument is specified, the command is started from --cwd - # directory. - cmd.append('--child') - - cwd = 'data' - p = subprocess.Popen( - cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd) - out = p.communicate()[0] - if p.returncode: - raise CalledProcessError(p.returncode, cmd, out, cwd) - return out - - def test_trace(self): - if sys.platform not in ('linux2', 'darwin'): - print 'WARNING: unsupported: %s' % sys.platform - return - expected_end = [ - "Interesting: 4 reduced to 3", - " data/trace_inputs/", - " trace_inputs.py", - " trace_inputs_test.py", - ] - actual = self._execute(False).splitlines() - self.assertTrue(actual[0].startswith('Tracing... [')) - self.assertTrue(actual[1].startswith('Loading traces... ')) - self.assertTrue(actual[2].startswith('Total: ')) - self.assertEquals("Non existent: 0", actual[3]) - # Ignore any Unexpected part. - # TODO(maruel): Make sure there is no Unexpected part, even in the case of - # virtualenv usage. - self.assertEquals(expected_end, actual[-len(expected_end):]) - - def test_trace_gyp(self): - if sys.platform not in ('linux2', 'darwin'): - print 'WARNING: unsupported: %s' % sys.platform - return + def _test(self, value, expected): + actual = cStringIO.StringIO() + trace_inputs.pretty_print(value, actual) + self.assertEquals(expected, actual.getvalue()) + + def test_pretty_print_empty(self): + self._test({}, '{\n}\n') + + def test_pretty_print_mid_size(self): + value = { + 'variables': { + 'bar': [ + 'file1', + 'file2', + ], + }, + 'conditions': [ + ['OS=\"foo\"', { + 'variables': { + 'isolate': [ + 'dir1', + 'dir2', + ], + }, + }], + ['OS=\"bar\"', { + 'variables': {}, + }, { + 'variables': {}, + }], + ], + } expected = ( "{\n" " 'variables': {\n" - " 'isolate_files': [\n" - " '<(DEPTH)/trace_inputs.py',\n" - " '<(DEPTH)/trace_inputs_test.py',\n" - " ],\n" - " 'isolate_dirs': [\n" - " 'trace_inputs/',\n" + " 'bar': [\n" + " 'file1',\n" + " 'file2',\n" " ],\n" " },\n" - "},\n") - actual = self._execute(True) - self.assertEquals(expected, actual) - - -def child(): - """When the gyp argument is not specified, the command is started from - --root-dir directory. - """ - print 'child' - # Force file opening with a non-normalized path. - open(os.path.join('data', '..', 'trace_inputs.py'), 'rb').close() - # Do not wait for the child to exit. - # Use relative directory. - subprocess.Popen( - ['python', 'child2.py'], cwd=os.path.join('data', 'trace_inputs')) - return 0 - - -def child_gyp(): - """When the gyp argument is specified, the command is started from --cwd - directory. - """ - print 'child_gyp' - # Force file opening. - open(os.path.join('..', 'trace_inputs.py'), 'rb').close() - # Do not wait for the child to exit. - # Use relative directory. - subprocess.Popen(['python', 'child2.py'], cwd='trace_inputs') - return 0 - - -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] == '--child': - return child() - if sys.argv[1] == '--child-gyp': - return child_gyp() - - unittest.main() + " 'conditions': [\n" + " ['OS=\"foo\"', {\n" + " 'variables': {\n" + " 'isolate': [\n" + " 'dir1',\n" + " 'dir2',\n" + " ],\n" + " },\n" + " }],\n" + " ['OS=\"bar\"', {\n" + " 'variables': {\n" + " },\n" + " }, {\n" + " 'variables': {\n" + " },\n" + " }],\n" + " ],\n" + "}\n") + self._test(value, expected) if __name__ == '__main__': - sys.exit(main()) + unittest.main() |