Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/style/checker_unittest.py

Issue 2373063002: Clean up most style warnings in webkitpy/style/checker_unittest.py. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # -*- coding: utf-8; -*- 1 # -*- coding: utf-8; -*-
2 # 2 #
3 # Copyright (C) 2009 Google Inc. All rights reserved. 3 # Copyright (C) 2009 Google Inc. All rights reserved.
4 # Copyright (C) 2009 Torch Mobile Inc. 4 # Copyright (C) 2009 Torch Mobile Inc.
5 # Copyright (C) 2009 Apple Inc. All rights reserved. 5 # Copyright (C) 2009 Apple Inc. All rights reserved.
6 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com) 6 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com)
7 # 7 #
8 # Redistribution and use in source and binary forms, with or without 8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are 9 # modification, are permitted provided that the following conditions are
10 # met: 10 # met:
(...skipping 19 matching lines...) Expand all
30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 33
34 """Unit tests for style.py.""" 34 """Unit tests for style.py."""
35 35
36 import logging 36 import logging
37 import os 37 import os
38 import unittest 38 import unittest
39 39
40 import checker as style 40 from webkitpy.common.system.logtesting import LoggingTestCase
41 from webkitpy.common.system.logtesting import LogTesting
42 from webkitpy.common.system.logtesting import TestLogStream 41 from webkitpy.common.system.logtesting import TestLogStream
43 from checker import _BASE_FILTER_RULES 42 from webkitpy.style import checker as style
44 from checker import _MAX_REPORTS_PER_CATEGORY 43 from webkitpy.style.checker import _all_categories
45 from checker import _PATH_RULES_SPECIFIER as PATH_RULES_SPECIFIER 44 from webkitpy.style.checker import _BASE_FILTER_RULES
46 from checker import _all_categories 45 from webkitpy.style.checker import _MAX_REPORTS_PER_CATEGORY
47 from checker import check_webkit_style_configuration 46 from webkitpy.style.checker import _PATH_RULES_SPECIFIER as PATH_RULES_SPECIFIER
48 from checker import check_webkit_style_parser 47 from webkitpy.style.checker import check_webkit_style_configuration
49 from checker import configure_logging 48 from webkitpy.style.checker import check_webkit_style_parser
50 from checker import CheckerDispatcher 49 from webkitpy.style.checker import CheckerDispatcher
51 from checker import ProcessorBase 50 from webkitpy.style.checker import configure_logging
52 from checker import StyleProcessor 51 from webkitpy.style.checker import StyleProcessor
53 from checker import StyleProcessorConfiguration 52 from webkitpy.style.checker import StyleProcessorConfiguration
54 from checkers.cpp import CppChecker 53 from webkitpy.style.checkers.cpp import CppChecker
55 from checkers.jsonchecker import JSONChecker 54 from webkitpy.style.checkers.jsonchecker import JSONChecker
56 from checkers.python import PythonChecker 55 from webkitpy.style.checkers.python import PythonChecker
57 from checkers.text import TextChecker 56 from webkitpy.style.checkers.text import TextChecker
58 from checkers.xml import XMLChecker 57 from webkitpy.style.checkers.xml import XMLChecker
59 from error_handlers import DefaultStyleErrorHandler 58 from webkitpy.style.error_handlers import DefaultStyleErrorHandler
60 from filter import validate_filter_rules 59 from webkitpy.style.filter import FilterConfiguration
61 from filter import FilterConfiguration 60 from webkitpy.style.filter import validate_filter_rules
62 from optparser import ArgumentParser 61 from webkitpy.style.optparser import ArgumentParser
63 from optparser import CommandOptionValues 62 from webkitpy.style.optparser import CommandOptionValues
64 from webkitpy.common.system.logtesting import LoggingTestCase
65 from webkitpy.style.filereader import TextFileReader
66 63
67 64
68 class ConfigureLoggingTestBase(unittest.TestCase): 65 class ConfigureLoggingTestBase(unittest.TestCase):
69 66
70 """Base class for testing configure_logging(). 67 """Base class for testing configure_logging().
71 68
72 Sub-classes should implement: 69 Sub-classes should implement:
73 70
74 is_verbose: The is_verbose value to pass to configure_logging(). 71 is_verbose: The is_verbose value to pass to configure_logging().
75 """ 72 """
76 73
74 is_verbose = False
qyearsley 2016/09/27 17:15:31 Adding this line adds a default value for self.is_
75
77 def setUp(self): 76 def setUp(self):
78 is_verbose = self.is_verbose 77 is_verbose = self.is_verbose
79 78
80 log_stream = TestLogStream(self) 79 log_stream = TestLogStream(self)
81 80
82 # Use a logger other than the root logger or one prefixed with 81 # Use a logger other than the root logger or one prefixed with
83 # webkit so as not to conflict with test-webkitpy logging. 82 # webkit so as not to conflict with test-webkitpy logging.
84 logger = logging.getLogger("unittest") 83 logger = logging.getLogger("unittest")
85 84
86 # Configure the test logger not to pass messages along to the 85 # Configure the test logger not to pass messages along to the
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 # 186 #
188 # The default options are valid: no error or SystemExit. 187 # The default options are valid: no error or SystemExit.
189 parser.parse(args=[]) 188 parser.parse(args=[])
190 189
191 def test_path_rules_specifier(self): 190 def test_path_rules_specifier(self):
192 for _, path_rules in PATH_RULES_SPECIFIER: 191 for _, path_rules in PATH_RULES_SPECIFIER:
193 validate_filter_rules(path_rules, self._all_categories()) 192 validate_filter_rules(path_rules, self._all_categories())
194 193
195 config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER) 194 config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)
196 195
197 def assertCheck(path, category): 196 def assert_check(path, category):
198 """Assert that the given category should be checked.""" 197 """Assert that the given category should be checked."""
199 self.assertTrue(config.should_check(category, path)) 198 self.assertTrue(config.should_check(category, path))
200 199
201 def assertNoCheck(path, category): 200 def assert_no_check(path, category):
202 """Assert that the given category should not be checked.""" 201 """Assert that the given category should not be checked."""
203 message = ('Should not check category "%s" for path "%s".' 202 message = ('Should not check category "%s" for path "%s".'
204 % (category, path)) 203 % (category, path))
205 self.assertFalse(config.should_check(category, path), message) 204 self.assertFalse(config.should_check(category, path), message)
206 205
207 assertCheck("random_path.cpp", 206 assert_check("random_path.cpp",
208 "build/include") 207 "build/include")
209 assertCheck("random_path.cpp", 208 assert_check("random_path.cpp",
210 "readability/naming") 209 "readability/naming")
211 assertNoCheck("Source/core/css/CSSParser-in.cpp", 210 assert_no_check("Source/core/css/CSSParser-in.cpp",
212 "readability/naming") 211 "readability/naming")
213 212
214 # Third-party Python code: webkitpy/thirdparty 213 # Third-party Python code: webkitpy/thirdparty
215 path = "Tools/Scripts/webkitpy/thirdparty/mock.py" 214 path = "Tools/Scripts/webkitpy/thirdparty/mock.py"
216 assertNoCheck(path, "build/include") 215 assert_no_check(path, "build/include")
217 assertNoCheck(path, "pep8/E401") # A random pep8 category. 216 assert_no_check(path, "pep8/E401") # A random pep8 category.
218 assertCheck(path, "pep8/W191") 217 assert_check(path, "pep8/W191")
219 assertCheck(path, "pep8/W291") 218 assert_check(path, "pep8/W291")
220 assertCheck(path, "whitespace/carriage_return") 219 assert_check(path, "whitespace/carriage_return")
qyearsley 2016/09/27 17:15:31 These helper function names are changed to fit the
221 220
222 def test_max_reports_per_category(self): 221 def test_max_reports_per_category(self):
223 """Check that _MAX_REPORTS_PER_CATEGORY is valid.""" 222 """Check that _MAX_REPORTS_PER_CATEGORY is valid."""
224 all_categories = self._all_categories() 223 all_categories = self._all_categories()
225 for category in _MAX_REPORTS_PER_CATEGORY.iterkeys(): 224 for category in _MAX_REPORTS_PER_CATEGORY.iterkeys():
226 self.assertIn(category, all_categories, 225 self.assertIn(category, all_categories,
227 'Key "%s" is not a category' % category) 226 'Key "%s" is not a category' % category)
228 227
229 228
230 class CheckWebKitStyleFunctionTest(unittest.TestCase): 229 class CheckWebKitStyleFunctionTest(unittest.TestCase):
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 515
517 for path in paths: 516 for path in paths:
518 self.assert_checker_none(path) 517 self.assert_checker_none(path)
519 518
520 519
521 class StyleProcessorConfigurationTest(unittest.TestCase): 520 class StyleProcessorConfigurationTest(unittest.TestCase):
522 521
523 """Tests the StyleProcessorConfiguration class.""" 522 """Tests the StyleProcessorConfiguration class."""
524 523
525 def setUp(self): 524 def setUp(self):
526 self._error_messages = [] 525 self._error_messages = [] # The messages written to _mock_stderr_write( ) of this class.
527 """The messages written to _mock_stderr_write() of this class."""
528 526
529 def _mock_stderr_write(self, message): 527 def _mock_stderr_write(self, message):
530 self._error_messages.append(message) 528 self._error_messages.append(message)
531 529
532 def _style_checker_configuration(self, output_format="vs7"): 530 def _style_checker_configuration(self, output_format="vs7"):
533 """Return a StyleProcessorConfiguration instance for testing.""" 531 """Return a StyleProcessorConfiguration instance for testing."""
534 base_rules = ["-whitespace", "+whitespace/tab"] 532 base_rules = ["-whitespace", "+whitespace/tab"]
535 filter_configuration = FilterConfiguration(base_rules=base_rules) 533 filter_configuration = FilterConfiguration(base_rules=base_rules)
536 534
537 return StyleProcessorConfiguration( 535 return StyleProcessorConfiguration(
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 """ 632 """
635 633
636 class MockDispatchedChecker(object): 634 class MockDispatchedChecker(object):
637 635
638 """A mock checker dispatched by the MockDispatcher.""" 636 """A mock checker dispatched by the MockDispatcher."""
639 637
640 def __init__(self, file_path, min_confidence, style_error_handler): 638 def __init__(self, file_path, min_confidence, style_error_handler):
641 self.file_path = file_path 639 self.file_path = file_path
642 self.min_confidence = min_confidence 640 self.min_confidence = min_confidence
643 self.style_error_handler = style_error_handler 641 self.style_error_handler = style_error_handler
642 self.lines = None
qyearsley 2016/09/27 17:15:31 (This line is added so that attributes are all def
644 643
645 def check(self, lines): 644 def check(self, lines):
646 self.lines = lines 645 self.lines = lines
647 646
648 class MockDispatcher(object): 647 class MockDispatcher(object):
649 648
650 """A mock CheckerDispatcher class.""" 649 """A mock CheckerDispatcher class."""
651 650
652 def __init__(self): 651 def __init__(self):
653 self.dispatched_checker = None 652 self.dispatched_checker = None
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 """Test that carriage returns aren't stripped from files that are allowe d to contain them.""" 803 """Test that carriage returns aren't stripped from files that are allowe d to contain them."""
805 file_path = 'carriage_returns_allowed.txt' 804 file_path = 'carriage_returns_allowed.txt'
806 lines = ['line1\r', 'line2\r'] 805 lines = ['line1\r', 'line2\r']
807 line_numbers = [100] 806 line_numbers = [100]
808 self._processor.process(lines=lines, 807 self._processor.process(lines=lines,
809 file_path=file_path, 808 file_path=file_path,
810 line_numbers=line_numbers) 809 line_numbers=line_numbers)
811 # The carriage return checker should never have been invoked, and so 810 # The carriage return checker should never have been invoked, and so
812 # should not have saved off any lines. 811 # should not have saved off any lines.
813 self.assertFalse(hasattr(self.carriage_checker, 'lines')) 812 self.assertFalse(hasattr(self.carriage_checker, 'lines'))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698