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

Side by Side Diff: Tools/Scripts/webkitpy/formatter/main_unittest.py

Issue 546613003: Add a new 'format-webkitpy' command that will reformat code to the style guide. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: remove hack from test/main.py Created 6 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import StringIO
6 import unittest
7
8 from webkitpy.common.system.systemhost_mock import MockSystemHost
9 from webkitpy.formatter.main import main
10
11
12 ACTUAL_INPUT = '''
13 def foo():
14 """triple-quoted docstring"""
15 try:
16 bar = "bar"
17 long_list = ['this is a list of strings that should be wrapped', "and co nsistently quoted"]
18 longer_list = ['this is a list of strings that should be wrapped', "and consistently quoted", "because it's important to test quoting"]
19 except Exception, e:
20 pass
21 '''
22
23
24 EXPECTED_BLINK_OUTPUT = '''
25 def foo():
26 """triple-quoted docstring"""
27 try:
28 bar = 'bar'
29 long_list = ['this is a list of strings that should be wrapped', 'and co nsistently quoted']
30 longer_list = [
31 'this is a list of strings that should be wrapped',
32 'and consistently quoted',
33 "because it's important to test quoting"]
34 except Exception as e:
35 pass
36 '''
37
38
39 EXPECTED_CHROMIUM_OUTPUT = '''
40 def foo():
41 """triple-quoted docstring"""
42 try:
43 bar = "bar"
44 long_list = [
45 "this is a list of strings that should be wrapped",
46 "and consistently quoted"]
47 longer_list = [
48 "this is a list of strings that should be wrapped",
49 "and consistently quoted",
50 "because it's important to test quoting"]
51 except Exception as e:
52 pass
53 '''
54
55
56 class TestMain(unittest.TestCase):
57 maxDiff = 4096
58
59 def test_stdin_blink(self):
60 host = MockSystemHost()
61 host.stdin = StringIO.StringIO(ACTUAL_INPUT)
62 main(host, ['-'])
63 self.assertMultiLineEqual(host.stdout.getvalue(), EXPECTED_BLINK_OUTPUT)
64
65 def test_stdin_chromium(self):
66 host = MockSystemHost()
67 host.stdin = StringIO.StringIO(ACTUAL_INPUT)
68 main(host, ['--chromium', '-'])
69 self.assertMultiLineEqual(host.stdout.getvalue(), EXPECTED_CHROMIUM_OUTP UT)
70
71 def test_files_blink(self):
72 host = MockSystemHost()
73 host.filesystem.files = {
74 'test.py': ACTUAL_INPUT}
75 main(host, ['test.py'])
76 self.assertEqual(host.filesystem.files, {
77 'test.py': EXPECTED_BLINK_OUTPUT,
78 'test.py.bak': ACTUAL_INPUT})
79
80 def test_files_blink_no_backup(self):
81 host = MockSystemHost()
82 host.filesystem.files = {
83 'test.py': ACTUAL_INPUT}
84 main(host, ['--no-backups', 'test.py'])
85 self.assertEqual(host.filesystem.files, {
86 'test.py': EXPECTED_BLINK_OUTPUT})
OLDNEW
« no previous file with comments | « Tools/Scripts/webkitpy/formatter/main.py ('k') | Tools/Scripts/webkitpy/thirdparty/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698