| 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()
|
|
|