Chromium Code Reviews| Index: android_webview/tools/copyright_scanner_unittest.py |
| diff --git a/android_webview/tools/copyright_scanner_unittest.py b/android_webview/tools/copyright_scanner_unittest.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..aec0e39c3b23967e2c49bfcd84c5afc8816716a9 |
| --- /dev/null |
| +++ b/android_webview/tools/copyright_scanner_unittest.py |
| @@ -0,0 +1,115 @@ |
| +#!/usr/bin/env python |
| +# Copyright 2014 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 Copyright Scanner utilities.""" |
| + |
| +import os |
| +import re |
| +import sys |
| +import unittest |
| + |
| +test_dir = os.path.dirname(os.path.abspath(__file__)) |
| +sys.path.extend([ |
| + os.path.normpath(os.path.join(test_dir, '..', '..', 'tools')), |
| + os.path.join(test_dir), |
| +]) |
| + |
| +import find_depot_tools |
| +from testing_support.super_mox import SuperMoxTestBase |
| + |
| +import copyright_scanner |
| + |
| +class FindCopyrightsTest(SuperMoxTestBase): |
| + def setUp(self): |
| + SuperMoxTestBase.setUp(self) |
| + self.input_api = self.mox.CreateMockAnything() |
| + self.input_api.re = re |
| + self.input_api.os_path = os.path |
| + self.input_api.os_walk = os.walk |
| + |
| + def ShouldMatchReferenceOutput(self, test_data): |
| + test_data_pos = 0 |
| + def ReadTestData(ignore1, ignore2): |
| + return test_data[test_data_pos] |
| + self.input_api.ReadFile = ReadTestData |
| + for test_data_pos in range(0, len(test_data), 2): |
| + actual = copyright_scanner.FindCopyrights(self.input_api, '', ['']) |
| + self.assertEqual( |
| + test_data[test_data_pos + 1], |
| + actual, |
| + 'Input """\n%s""", expected output: "%s", actual: "%s"' % \ |
| + (test_data[test_data_pos], test_data[test_data_pos + 1], actual)); |
| + |
| + def testCopyrightedFiles(self): |
| + test_data = [ |
| + '// (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
|
| + [['2014 Google Inc.']], |
| + 'Copyright 2014 Google Inc.\n', |
| + [['2014 Google Inc.']], |
| + 'Copr. 2014 Google Inc.', |
| + [['2014 Google Inc.']], |
| + '\xc2\xa9 2014 Google Inc.', |
| + [['2014 Google Inc.']], |
| + 'Copyright 2014 Google Inc.', |
| + [['2014 Google Inc.']] |
| + ] |
| + self.ShouldMatchReferenceOutput(test_data) |
| + |
| + def testGeneratedFiles(self): |
| + test_data = [ |
| + 'ALL CHANGES MADE IN THIS FILE WILL BE LOST\nCopyright 2014 Google\n', |
| + [['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.
|
| + 'GENERATED FILE. DO NOT EDIT\nCopyright 2014 Google\n', |
| + [['GENERATED FILE']], |
| + 'GENERATED. DO NOT DELETE THIS FILE.\nCopyright 2014 Google\n', |
| + [['GENERATED FILE']], |
| + 'DO NOT EDIT\nCopyright 2014 Google\n', |
| + [['GENERATED FILE']], |
| + 'DO NOT DELETE THIS FILE\nCopyright 2014 Google\n', |
| + [['GENERATED FILE']], |
| + 'All changes made in this file will be lost\nCopyright 2014 Google\n', |
| + [['GENERATED FILE']], |
| + 'Automatically generated file\nCopyright 2014 Google\n', |
| + [['GENERATED FILE']], |
| + 'Synthetically generated dummy file\nCopyright 2014 Google\n', |
| + [['GENERATED FILE']], |
| + 'Generated data (by gnugnu)\nCopyright 2014 Google\n', |
| + [['GENERATED FILE']] |
| + ] |
| + self.ShouldMatchReferenceOutput(test_data) |
| + |
| + def testNonCopyrightedFiles(self): |
| + test_data = [ |
| + 'std::cout << "Copyright 2014 Google"\n', |
| + [['*No copyright*']], |
| + '// Several points can be made:\n//\n// (a) One\n//\n// (b) Two\n' |
| + '//\n// (c) Three\n//\n', |
| + [['*No copyright*']], |
| + 'See \'foo\' for copyright information.\n', |
| + [['*No copyright*']], |
| + 'See \'foo\' for the copyright notice.\n', |
| + [['*No copyright*']], |
| + 'See \'foo\' for the copyright and other things.\n', |
| + [['*No copyright*']] |
| + ] |
| + self.ShouldMatchReferenceOutput(test_data) |
| + |
| + def testNonGeneratedFiles(self): |
| + test_data = [ |
| + 'This file was prohibited from being generated.\n', |
| + [['*No copyright*']], |
| + 'Please do not delete our files! They are valuable to us.\n', |
| + [['*No copyright*']], |
| + 'Manually generated from dice rolls.\n', |
| + [['*No copyright*']], |
| + '"""This Python script produces generated data\n"""\n', |
| + [['*No copyright*']], |
| + '\'\'\'This Python script produces generated data\n\'\'\'\n', |
| + [['*No copyright*']] |
| + ] |
| + self.ShouldMatchReferenceOutput(test_data) |
| + |
| +if __name__ == '__main__': |
| + unittest.main() |