Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2014 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 Copyright Scanner utilities.""" | |
| 7 | |
| 8 import os | |
| 9 import re | |
| 10 import sys | |
| 11 import unittest | |
| 12 | |
| 13 test_dir = os.path.dirname(os.path.abspath(__file__)) | |
| 14 sys.path.extend([ | |
| 15 os.path.normpath(os.path.join(test_dir, '..', '..', 'tools')), | |
| 16 os.path.join(test_dir), | |
| 17 ]) | |
| 18 | |
| 19 import find_depot_tools | |
| 20 from testing_support.super_mox import SuperMoxTestBase | |
| 21 | |
| 22 import copyright_scanner | |
| 23 | |
| 24 class FindCopyrightsTest(SuperMoxTestBase): | |
| 25 def setUp(self): | |
| 26 SuperMoxTestBase.setUp(self) | |
| 27 self.input_api = self.mox.CreateMockAnything() | |
| 28 self.input_api.re = re | |
| 29 self.input_api.os_path = os.path | |
| 30 self.input_api.os_walk = os.walk | |
| 31 | |
| 32 def ShouldMatchReferenceOutput(self, test_data): | |
| 33 test_data_pos = 0 | |
| 34 def ReadTestData(ignore1, ignore2): | |
| 35 return test_data[test_data_pos] | |
| 36 self.input_api.ReadFile = ReadTestData | |
| 37 for test_data_pos in range(0, len(test_data), 2): | |
| 38 actual = copyright_scanner.FindCopyrights(self.input_api, '', ['']) | |
| 39 self.assertEqual( | |
| 40 test_data[test_data_pos + 1], | |
| 41 actual, | |
| 42 'Input """\n%s""", expected output: "%s", actual: "%s"' % \ | |
| 43 (test_data[test_data_pos], test_data[test_data_pos + 1], actual)); | |
| 44 | |
| 45 def testCopyrightedFiles(self): | |
| 46 test_data = [ | |
| 47 '// (c) 2014 Google Inc.\n//\n// (a) One\n//\n// (b) Two\n//\n', | |
|
mkosiba (inactive)
2014/10/21 15:41:22
maybe use something like
Expectation = collection
mnaganov (inactive)
2014/10/22 09:27:29
I decided it's even simpler just to pass a single
| |
| 48 [['2014 Google Inc.']], | |
| 49 'Copyright 2014 Google Inc.\n', | |
| 50 [['2014 Google Inc.']], | |
| 51 'Copr. 2014 Google Inc.', | |
| 52 [['2014 Google Inc.']], | |
| 53 '\xc2\xa9 2014 Google Inc.', | |
| 54 [['2014 Google Inc.']], | |
| 55 'Copyright 2014 Google Inc.', | |
| 56 [['2014 Google Inc.']] | |
| 57 ] | |
| 58 self.ShouldMatchReferenceOutput(test_data) | |
| 59 | |
| 60 def testGeneratedFiles(self): | |
| 61 test_data = [ | |
| 62 'ALL CHANGES MADE IN THIS FILE WILL BE LOST\nCopyright 2014 Google\n', | |
| 63 [['GENERATED FILE']], | |
|
mkosiba (inactive)
2014/10/21 15:41:22
if you had these as tuples you could use an array
mnaganov (inactive)
2014/10/22 09:27:29
See the previous comment.
| |
| 64 'GENERATED FILE. DO NOT EDIT\nCopyright 2014 Google\n', | |
| 65 [['GENERATED FILE']], | |
| 66 'GENERATED. DO NOT DELETE THIS FILE.\nCopyright 2014 Google\n', | |
| 67 [['GENERATED FILE']], | |
| 68 'DO NOT EDIT\nCopyright 2014 Google\n', | |
| 69 [['GENERATED FILE']], | |
| 70 'DO NOT DELETE THIS FILE\nCopyright 2014 Google\n', | |
| 71 [['GENERATED FILE']], | |
| 72 'All changes made in this file will be lost\nCopyright 2014 Google\n', | |
| 73 [['GENERATED FILE']], | |
| 74 'Automatically generated file\nCopyright 2014 Google\n', | |
| 75 [['GENERATED FILE']], | |
| 76 'Synthetically generated dummy file\nCopyright 2014 Google\n', | |
| 77 [['GENERATED FILE']], | |
| 78 'Generated data (by gnugnu)\nCopyright 2014 Google\n', | |
| 79 [['GENERATED FILE']] | |
| 80 ] | |
| 81 self.ShouldMatchReferenceOutput(test_data) | |
| 82 | |
| 83 def testNonCopyrightedFiles(self): | |
| 84 test_data = [ | |
| 85 'std::cout << "Copyright 2014 Google"\n', | |
| 86 [['*No copyright*']], | |
| 87 '// Several points can be made:\n//\n// (a) One\n//\n// (b) Two\n' | |
| 88 '//\n// (c) Three\n//\n', | |
| 89 [['*No copyright*']], | |
| 90 'See \'foo\' for copyright information.\n', | |
| 91 [['*No copyright*']], | |
| 92 'See \'foo\' for the copyright notice.\n', | |
| 93 [['*No copyright*']], | |
| 94 'See \'foo\' for the copyright and other things.\n', | |
| 95 [['*No copyright*']] | |
| 96 ] | |
| 97 self.ShouldMatchReferenceOutput(test_data) | |
| 98 | |
| 99 def testNonGeneratedFiles(self): | |
| 100 test_data = [ | |
| 101 'This file was prohibited from being generated.\n', | |
| 102 [['*No copyright*']], | |
| 103 'Please do not delete our files! They are valuable to us.\n', | |
| 104 [['*No copyright*']], | |
| 105 'Manually generated from dice rolls.\n', | |
| 106 [['*No copyright*']], | |
| 107 '"""This Python script produces generated data\n"""\n', | |
| 108 [['*No copyright*']], | |
| 109 '\'\'\'This Python script produces generated data\n\'\'\'\n', | |
| 110 [['*No copyright*']] | |
| 111 ] | |
| 112 self.ShouldMatchReferenceOutput(test_data) | |
| 113 | |
| 114 if __name__ == '__main__': | |
| 115 unittest.main() | |
| OLD | NEW |