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