OLD | NEW |
(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_processors/chromium_copyright.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 from post_processors import chromium_copyright |
| 19 |
| 20 |
| 21 class CCTest(trial_dir.TestCase): |
| 22 def setUp(self): |
| 23 super(CCTest, 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 chromium_copyright.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_re(self): |
| 80 self.full_check( |
| 81 'Copyright (c) 2010 The Chromium Authors. All rights reserved.', |
| 82 'Copyright (c) 2011 The Chromium Authors. All rights reserved.') |
| 83 self.full_check( |
| 84 'a Copyright (c) 2010 The Chromium Authors. All rights reserved.', |
| 85 'a Copyright (c) 2011 The Chromium Authors. All rights reserved.') |
| 86 self.full_check( |
| 87 '// Copyright (c) 2010 The Chromium Authors. All rights reserved.', |
| 88 '// Copyright (c) 2011 The Chromium Authors. All rights reserved.') |
| 89 self.full_check( |
| 90 '// Copyright (c) 2010 The Chromium Authors. All rights reserved.\n', |
| 91 '// Copyright (c) 2011 The Chromium Authors. All rights reserved.\n') |
| 92 self.full_check( |
| 93 'Copyright (c) 2010 The Chromium Authors. All rights reserved.\n', |
| 94 'Copyright (c) 2011 The Chromium Authors. All rights reserved.\n') |
| 95 ## \r are not supported. |
| 96 #self.full_check( |
| 97 # '// Copyright (c) 2010 The Chromium Authors. All rights reserved.\r\n', |
| 98 # '// Copyright (c) 2011 The Chromium Authors. All rights reserved.\r\n') |
| 99 self.full_check( |
| 100 'Copyright 2010 The Chromium Authors. All rights reserved.', |
| 101 'Copyright 2010 The Chromium Authors. All rights reserved.') |
| 102 |
| 103 |
| 104 if __name__ == '__main__': |
| 105 unittest.main() |
OLD | NEW |