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

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

Issue 2256793002: Make docstrings more consistent using format-webkitpy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make indentation of final quote based on parse tree (indentation prior to docstring node) rather th… Created 4 years, 3 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
OLDNEW
1 # -*- coding: utf-8; -*- 1 # -*- coding: utf-8; -*-
2 # 2 #
3 # Copyright (C) 2011 Google Inc. All rights reserved. 3 # Copyright (C) 2011 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 (cjerdonek@webkit.org) 6 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 # is in STYLE_CATEGORIES, to help keep that list up to date. 50 # is in STYLE_CATEGORIES, to help keep that list up to date.
51 51
52 52
53 class ErrorCollector: 53 class ErrorCollector:
54 _all_style_categories = CppChecker.categories 54 _all_style_categories = CppChecker.categories
55 # This is a list including all categories seen in any unit test. 55 # This is a list including all categories seen in any unit test.
56 _seen_style_categories = {} 56 _seen_style_categories = {}
57 57
58 def __init__(self, assert_fn, filter=None, lines_to_check=None): 58 def __init__(self, assert_fn, filter=None, lines_to_check=None):
59 """assert_fn: a function to call when we notice a problem. 59 """assert_fn: a function to call when we notice a problem.
60 filter: filters the errors that we are concerned about.""" 60 filter: filters the errors that we are concerned about.
61 """
61 self._assert_fn = assert_fn 62 self._assert_fn = assert_fn
62 self._errors = [] 63 self._errors = []
63 self._lines_to_check = lines_to_check 64 self._lines_to_check = lines_to_check
64 if not filter: 65 if not filter:
65 filter = FilterConfiguration() 66 filter = FilterConfiguration()
66 self._filter = filter 67 self._filter = filter
67 68
68 def __call__(self, line_number, category, confidence, message): 69 def __call__(self, line_number, category, confidence, message):
69 self._assert_fn(category in self._all_style_categories, 70 self._assert_fn(category in self._all_style_categories,
70 'Message "%s" has category "%s",' 71 'Message "%s" has category "%s",'
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 self.assertEqual(error_collector.results(), 231 self.assertEqual(error_collector.results(),
231 'The parameter name "ooF" adds no information, so it sh ould be removed. [readability/parameter_name] [5]') 232 'The parameter name "ooF" adds no information, so it sh ould be removed. [readability/parameter_name] [5]')
232 233
233 234
234 class CppStyleTestBase(unittest.TestCase): 235 class CppStyleTestBase(unittest.TestCase):
235 """Provides some useful helper functions for cpp_style tests. 236 """Provides some useful helper functions for cpp_style tests.
236 237
237 Attributes: 238 Attributes:
238 min_confidence: An integer that is the current minimum confidence 239 min_confidence: An integer that is the current minimum confidence
239 level for the tests. 240 level for the tests.
240
241 """ 241 """
242 242
243 # FIXME: Refactor the unit tests so the confidence level is passed 243 # FIXME: Refactor the unit tests so the confidence level is passed
244 # explicitly, just like it is in the real code. 244 # explicitly, just like it is in the real code.
245 min_confidence = 1 245 min_confidence = 1
246 246
247 # Helper function to avoid needing to explicitly pass confidence 247 # Helper function to avoid needing to explicitly pass confidence
248 # in all the unit test calls to cpp_style.process_file_data(). 248 # in all the unit test calls to cpp_style.process_file_data().
249 def process_file_data(self, filename, file_extension, lines, error, fs=None) : 249 def process_file_data(self, filename, file_extension, lines, error, fs=None) :
250 """Call cpp_style.process_file_data() with the min_confidence.""" 250 """Call cpp_style.process_file_data() with the min_confidence."""
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 self.assertEqual( 355 self.assertEqual(
356 end_errors, 356 end_errors,
357 error_collector.results().count( 357 error_collector.results().count(
358 'Blank line at the end of a code block. Is this needed?' 358 'Blank line at the end of a code block. Is this needed?'
359 ' [whitespace/blank_line] [3]')) 359 ' [whitespace/blank_line] [3]'))
360 360
361 def assert_positions_equal(self, position, tuple_position): 361 def assert_positions_equal(self, position, tuple_position):
362 """Checks if the two positions are equal. 362 """Checks if the two positions are equal.
363 363
364 position: a cpp_style.Position object. 364 position: a cpp_style.Position object.
365 tuple_position: a tuple (row, column) to compare against.""" 365 tuple_position: a tuple (row, column) to compare against.
366 """
366 self.assertEqual(position, cpp_style.Position(tuple_position[0], tuple_p osition[1]), 367 self.assertEqual(position, cpp_style.Position(tuple_position[0], tuple_p osition[1]),
367 'position %s, tuple_position %s' % (position, tuple_pos ition)) 368 'position %s, tuple_position %s' % (position, tuple_pos ition))
368 369
369 370
370 class FunctionDetectionTest(CppStyleTestBase): 371 class FunctionDetectionTest(CppStyleTestBase):
371 372
372 def perform_function_detection(self, lines, function_information, detection_ line=0): 373 def perform_function_detection(self, lines, function_information, detection_ line=0):
373 clean_lines = cpp_style.CleansedLines(lines) 374 clean_lines = cpp_style.CleansedLines(lines)
374 function_state = cpp_style._FunctionState(5) 375 function_state = cpp_style._FunctionState(5)
375 error_collector = ErrorCollector(self.assertTrue) 376 error_collector = ErrorCollector(self.assertTrue)
(...skipping 4884 matching lines...) Expand 10 before | Expand all | Expand 10 after
5260 def test_ne(self): 5261 def test_ne(self):
5261 """Test __ne__ inequality function.""" 5262 """Test __ne__ inequality function."""
5262 checker1 = self._checker() 5263 checker1 = self._checker()
5263 checker2 = self._checker() 5264 checker2 = self._checker()
5264 5265
5265 # != calls __ne__. 5266 # != calls __ne__.
5266 # By default, __ne__ always returns true on different objects. 5267 # By default, __ne__ always returns true on different objects.
5267 # Thus, just check the distinguishing case to verify that the 5268 # Thus, just check the distinguishing case to verify that the
5268 # code defines __ne__. 5269 # code defines __ne__.
5269 self.assertFalse(checker1 != checker2) 5270 self.assertFalse(checker1 != checker2)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698