| 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, expected_output): |
| 33 for data in test_data: |
| 34 self.input_api.ReadFile = lambda _1, _2: data |
| 35 actual_output = copyright_scanner.FindCopyrights(self.input_api, '', ['']) |
| 36 self.assertEqual( |
| 37 expected_output, |
| 38 actual_output, |
| 39 'Input """\n%s""", expected output: "%s", actual: "%s"' % \ |
| 40 (data, expected_output, actual_output)); |
| 41 |
| 42 def testCopyrightedFiles(self): |
| 43 test_data = [ |
| 44 '// (c) 2014 Google Inc.\n//\n// (a) One\n//\n// (b) Two\n//\n', |
| 45 'Copyright 2014 Google Inc.\n', |
| 46 'Copr. 2014 Google Inc.', |
| 47 '\xc2\xa9 2014 Google Inc.', |
| 48 'Copyright 2014 Google Inc.' |
| 49 ] |
| 50 self.ShouldMatchReferenceOutput(test_data, [['2014 Google Inc.']]) |
| 51 |
| 52 def testGeneratedFiles(self): |
| 53 test_data = [ |
| 54 'ALL CHANGES MADE IN THIS FILE WILL BE LOST\nCopyright 2014 Google\n', |
| 55 'GENERATED FILE. DO NOT EDIT\nCopyright 2014 Google\n', |
| 56 'GENERATED. DO NOT DELETE THIS FILE.\nCopyright 2014 Google\n', |
| 57 'DO NOT EDIT\nCopyright 2014 Google\n', |
| 58 'DO NOT DELETE THIS FILE\nCopyright 2014 Google\n', |
| 59 'All changes made in this file will be lost\nCopyright 2014 Google\n', |
| 60 'Automatically generated file\nCopyright 2014 Google\n', |
| 61 'Synthetically generated dummy file\nCopyright 2014 Google\n', |
| 62 'Generated data (by gnugnu)\nCopyright 2014 Google\n' |
| 63 ] |
| 64 self.ShouldMatchReferenceOutput(test_data, [['GENERATED FILE']]) |
| 65 |
| 66 def testNonCopyrightedFiles(self): |
| 67 test_data = [ |
| 68 'std::cout << "Copyright 2014 Google"\n', |
| 69 '// Several points can be made:\n//\n// (a) One\n//\n// (b) Two\n' |
| 70 '//\n// (c) Three\n//\n', |
| 71 'See \'foo\' for copyright information.\n', |
| 72 'See \'foo\' for the copyright notice.\n', |
| 73 'See \'foo\' for the copyright and other things.\n' |
| 74 ] |
| 75 self.ShouldMatchReferenceOutput(test_data, [['*No copyright*']]) |
| 76 |
| 77 def testNonGeneratedFiles(self): |
| 78 test_data = [ |
| 79 'This file was prohibited from being generated.\n', |
| 80 'Please do not delete our files! They are valuable to us.\n', |
| 81 'Manually generated from dice rolls.\n', |
| 82 '"""This Python script produces generated data\n"""\n', |
| 83 '\'\'\'This Python script produces generated data\n\'\'\'\n' |
| 84 ] |
| 85 self.ShouldMatchReferenceOutput(test_data, [['*No copyright*']]) |
| 86 |
| 87 if __name__ == '__main__': |
| 88 unittest.main() |
| OLD | NEW |