#!/usr/bin/env python # Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import cStringIO import logging import unittest import sys import isolate_common class TraceInputs(unittest.TestCase): def _test(self, value, expected): actual = cStringIO.StringIO() isolate_common.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_common.KEY_UNTRACKED: [ 'dir1', 'dir2', ], isolate_common.KEY_TRACKED: [ 'file4', 'file3', ], 'command': ['python', '-c', 'print "H\\i\'"'], 'read_only': True, 'relative_cwd': 'isol\'at\\e', }, }], ['OS=\"bar\"', { 'variables': {}, }, { 'variables': {}, }], ], } expected = ( "{\n" " 'variables': {\n" " 'bar': [\n" " 'file1',\n" " 'file2',\n" " ],\n" " },\n" " 'conditions': [\n" " ['OS=\"foo\"', {\n" " 'variables': {\n" " 'command': [\n" " 'python',\n" " '-c',\n" " 'print \"H\\i\'\"',\n" " ],\n" " 'relative_cwd': 'isol\\'at\\\\e',\n" " 'read_only': True\n" " 'isolate_dependency_tracked': [\n" " 'file4',\n" " 'file3',\n" " ],\n" " 'isolate_dependency_untracked': [\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__': VERBOSE = '-v' in sys.argv logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) unittest.main()