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

Side by Side Diff: tests/mangle_test.py

Issue 6880115: Add post_processing code to update copyright year automatically. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/commit-queue
Patch Set: Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Unit tests for post_process/mangle.py."""
7
8 import os
9 import sys
10 import unittest
11
12 ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
13 PROJECT_DIR = os.path.join(ROOT_DIR, '..')
14 sys.path.insert(0, PROJECT_DIR)
15
16 import find_depot_tools # pylint: disable=W0611
17 from tests import trial_dir
18 import projects
19
20
21 class MangleTest(trial_dir.TestCase):
22 def setUp(self):
23 super(MangleTest, self).setUp()
24 class FakeCheckout(object):
25 project_path = self.root_dir
26 self.checkout = FakeCheckout()
27 self.filename = 'foo'
28 self.filepath = os.path.join(self.root_dir, self.filename)
29
30 class FakePatches(object):
31 class FakePatch(object):
32 filename = self.filename
33 is_delete = False
34 is_binary = False
35 patches = [FakePatch()]
36 self.patches = FakePatches()
37
38 def full_check(self, content, expected):
39 """End-to-end test. That's all that matters."""
40 open(self.filepath, 'w').write(content)
41 projects.COPYRIGHT_MANGLER.process(self.checkout, self.patches)
42 self.assertEquals(expected, open(self.filepath).read())
43
44 def test_2_times(self):
45 content = (
46 'Copyright (c) 2010 The Chromium Authors. All rights reserved.\n'
47 'Copyright (c) 2010 The Chromium Authors. All rights reserved.\n')
48 expected = (
49 'Copyright (c) 2011 The Chromium Authors. All rights reserved.\n'
50 'Copyright (c) 2010 The Chromium Authors. All rights reserved.\n')
51 self.full_check(content, expected)
52
53 def test_5_lines(self):
54 content = (
55 '0\n'
56 '1\n'
57 '2\n'
58 '3\n'
59 'Copyright (c) 2010 The Chromium Authors. All rights reserved.\n')
60 expected = (
61 '0\n'
62 '1\n'
63 '2\n'
64 '3\n'
65 'Copyright (c) 2011 The Chromium Authors. All rights reserved.\n')
66 self.full_check(content, expected)
67
68 def test_6_lines(self):
69 content = (
70 '0\n'
71 '1\n'
72 '2\n'
73 '3\n'
74 '4\n'
75 'Copyright (c) 2010 The Chromium Authors. All rights reserved.\n')
76 expected = content
77 self.full_check(content, expected)
78
79 def test_default_lines(self):
80 self.assertEquals(5, projects.COPYRIGHT_MANGLER.max_lines_search)
81
82 def test_re(self):
83 # It's easy to get the regexp wrong so leave this there to confirm it does
84 # the right thing.
85 def check(line, expected):
86 self.assertEquals(expected, projects.COPYRIGHT_MANGLER.process_line(line))
87
88 check(
89 'Copyright (c) 2010 The Chromium Authors. All rights reserved.',
90 'Copyright (c) 2011 The Chromium Authors. All rights reserved.')
91 check(
92 'a Copyright (c) 2010 The Chromium Authors. All rights reserved.',
93 'a Copyright (c) 2011 The Chromium Authors. All rights reserved.')
94 check(
95 '// Copyright (c) 2010 The Chromium Authors. All rights reserved.',
96 '// Copyright (c) 2011 The Chromium Authors. All rights reserved.')
97 check(
98 '// Copyright (c) 2010 The Chromium Authors. All rights reserved.\n',
99 '// Copyright (c) 2011 The Chromium Authors. All rights reserved.\n')
100 check(
101 'Copyright (c) 2010 The Chromium Authors. All rights reserved.\n',
102 'Copyright (c) 2011 The Chromium Authors. All rights reserved.\n')
103 ## \r are not supported.
104 #check(
105 # '// Copyright (c) 2010 The Chromium Authors. All rights reserved.\r\n',
106 # '// Copyright (c) 2011 The Chromium Authors. All rights reserved.\r\n')
107 check(
108 'Copyright 2010 The Chromium Authors. All rights reserved.',
109 'Copyright 2010 The Chromium Authors. All rights reserved.')
110
111
112 if __name__ == '__main__':
113 unittest.main()
OLDNEW
« projects.py ('K') | « projects.py ('k') | tests/pending_manager_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698