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

Unified Diff: tests/chromium_copyright_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: Significantly simplify code 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « projects.py ('k') | tests/pending_manager_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/chromium_copyright_test.py
diff --git a/tests/chromium_copyright_test.py b/tests/chromium_copyright_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..089c8a253ec1e33a6b27c7dacbab90f8a52eab6a
--- /dev/null
+++ b/tests/chromium_copyright_test.py
@@ -0,0 +1,105 @@
+#!/usr/bin/env python
+# Copyright (c) 2011 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.
+
+"""Unit tests for post_processors/chromium_copyright.py."""
+
+import os
+import sys
+import unittest
+
+ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
+PROJECT_DIR = os.path.join(ROOT_DIR, '..')
+sys.path.insert(0, PROJECT_DIR)
+
+import find_depot_tools # pylint: disable=W0611
+from tests import trial_dir
+from post_processors import chromium_copyright
+
+
+class CCTest(trial_dir.TestCase):
+ def setUp(self):
+ super(CCTest, self).setUp()
+ class FakeCheckout(object):
+ project_path = self.root_dir
+ self.checkout = FakeCheckout()
+ self.filename = 'foo'
+ self.filepath = os.path.join(self.root_dir, self.filename)
+
+ class FakePatches(object):
+ class FakePatch(object):
+ filename = self.filename
+ is_delete = False
+ is_binary = False
+ patches = [FakePatch()]
+ self.patches = FakePatches()
+
+ def full_check(self, content, expected):
+ """End-to-end test. That's all that matters."""
+ open(self.filepath, 'w').write(content)
+ chromium_copyright.process(self.checkout, self.patches)
+ self.assertEquals(expected, open(self.filepath).read())
+
+ def test_2_times(self):
+ content = (
+ 'Copyright (c) 2010 The Chromium Authors. All rights reserved.\n'
+ 'Copyright (c) 2010 The Chromium Authors. All rights reserved.\n')
+ expected = (
+ 'Copyright (c) 2011 The Chromium Authors. All rights reserved.\n'
+ 'Copyright (c) 2010 The Chromium Authors. All rights reserved.\n')
+ self.full_check(content, expected)
+
+ def test_5_lines(self):
+ content = (
+ '0\n'
+ '1\n'
+ '2\n'
+ '3\n'
+ 'Copyright (c) 2010 The Chromium Authors. All rights reserved.\n')
+ expected = (
+ '0\n'
+ '1\n'
+ '2\n'
+ '3\n'
+ 'Copyright (c) 2011 The Chromium Authors. All rights reserved.\n')
+ self.full_check(content, expected)
+
+ def test_6_lines(self):
+ content = (
+ '0\n'
+ '1\n'
+ '2\n'
+ '3\n'
+ '4\n'
+ 'Copyright (c) 2010 The Chromium Authors. All rights reserved.\n')
+ expected = content
+ self.full_check(content, expected)
+
+ def test_re(self):
+ self.full_check(
+ 'Copyright (c) 2010 The Chromium Authors. All rights reserved.',
+ 'Copyright (c) 2011 The Chromium Authors. All rights reserved.')
+ self.full_check(
+ 'a Copyright (c) 2010 The Chromium Authors. All rights reserved.',
+ 'a Copyright (c) 2011 The Chromium Authors. All rights reserved.')
+ self.full_check(
+ '// Copyright (c) 2010 The Chromium Authors. All rights reserved.',
+ '// Copyright (c) 2011 The Chromium Authors. All rights reserved.')
+ self.full_check(
+ '// Copyright (c) 2010 The Chromium Authors. All rights reserved.\n',
+ '// Copyright (c) 2011 The Chromium Authors. All rights reserved.\n')
+ self.full_check(
+ 'Copyright (c) 2010 The Chromium Authors. All rights reserved.\n',
+ 'Copyright (c) 2011 The Chromium Authors. All rights reserved.\n')
+ ## \r are not supported.
+ #self.full_check(
+ # '// Copyright (c) 2010 The Chromium Authors. All rights reserved.\r\n',
+ # '// Copyright (c) 2011 The Chromium Authors. All rights reserved.\r\n')
+ self.full_check(
+ 'Copyright 2010 The Chromium Authors. All rights reserved.',
+ 'Copyright 2010 The Chromium Authors. All rights reserved.')
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « projects.py ('k') | tests/pending_manager_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698