Changeset 58251 in webkit


Ignore:
Timestamp:
Apr 26, 2010 6:01:39 AM (14 years ago)
Author:
Chris Jerdonek
Message:

2010-04-26 Chris Jerdonek <Chris Jerdonek>

Reviewed by Shinichiro Hamaji.

Deleted the StyleChecker-related classes that are no longer
being used.

https://bugs.webkit.org/show_bug.cgi?id=38118

  • Scripts/webkitpy/style/checker.py:
    • Deleted the DeprecatedStyleChecker class.
  • Scripts/webkitpy/style/checker_unittest.py:
    • Deleted the StyleCheckerTest, StyleCheckerCheckFileBase, StyleCheckerCheckFileTest, and StyleCheckerCheckPathsTest classes.
Location:
trunk/WebKitTools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r58249 r58251  
     12010-04-26  Chris Jerdonek  <cjerdonek@webkit.org>
     2
     3        Reviewed by Shinichiro Hamaji.
     4
     5        Deleted the StyleChecker-related classes that are no longer
     6        being used.
     7
     8        https://bugs.webkit.org/show_bug.cgi?id=38118
     9
     10        * Scripts/webkitpy/style/checker.py:
     11          - Deleted the DeprecatedStyleChecker class.
     12
     13        * Scripts/webkitpy/style/checker_unittest.py:
     14          - Deleted the StyleCheckerTest, StyleCheckerCheckFileBase,
     15            StyleCheckerCheckFileTest, and StyleCheckerCheckPathsTest classes.
     16
    1172010-04-26  Chris Jerdonek  <cjerdonek@webkit.org>
    218
  • trunk/WebKitTools/Scripts/webkitpy/style/checker.py

    r58249 r58251  
    567567
    568568
    569 # FIXME: Delete this class since it is no longer being used.
    570 class DeprecatedStyleChecker(object):
    571 
    572     """Supports checking style in files and patches.
    573 
    574        Attributes:
    575          error_count: An integer that is the total number of reported
    576                       errors for the lifetime of this StyleChecker
    577                       instance.
    578          file_count: An integer that is the total number of processed
    579                      files.  Note that the number of skipped files is
    580                      included in this value.
    581 
    582     """
    583 
    584     def __init__(self, configuration):
    585         """Create a StyleChecker instance.
    586 
    587         Args:
    588           configuration: A StyleCheckerConfiguration instance that controls
    589                          the behavior of style checking.
    590 
    591         """
    592         self._configuration = configuration
    593         self.error_count = 0
    594         self.file_count = 0
    595 
    596     def _increment_error_count(self):
    597         """Increment the total count of reported errors."""
    598         self.error_count += 1
    599 
    600     def _read_lines(self, file_path):
    601         """Read the file at a path, and return its lines.
    602 
    603         Raises:
    604           IOError: if the file does not exist or cannot be read.
    605 
    606         """
    607         # Support the UNIX convention of using "-" for stdin.
    608         if file_path == '-':
    609             file = codecs.StreamReaderWriter(sys.stdin,
    610                                              codecs.getreader('utf8'),
    611                                              codecs.getwriter('utf8'),
    612                                              'replace')
    613         else:
    614             # We do not open the file with universal newline support
    615             # (codecs does not support it anyway), so the resulting
    616             # lines contain trailing "\r" characters if we are reading
    617             # a file with CRLF endings.
    618             file = codecs.open(file_path, 'r', 'utf8', 'replace')
    619 
    620         contents = file.read()
    621 
    622         lines = contents.split("\n")
    623         return lines
    624 
    625     def _process_file(self, processor, file_path, handle_style_error):
    626         """Process the file using the given style processor."""
    627         try:
    628             lines = self._read_lines(file_path)
    629         except IOError:
    630             message = 'Could not read file. Skipping: "%s"' % file_path
    631             _log.warn(message)
    632             return
    633 
    634         # Check for and remove trailing carriage returns ("\r").
    635         #
    636         # FIXME: We should probably use the SVN "eol-style" property
    637         #        or a white list to decide whether or not to do
    638         #        the carriage-return check. Originally, we did the
    639         #        check only if (os.linesep != '\r\n').
    640         carriage_return_processor = CarriageReturnProcessor(handle_style_error)
    641         lines = carriage_return_processor.process(lines)
    642 
    643         processor.process(lines)
    644 
    645     def check_paths(self, paths, mock_check_file=None, mock_os=None):
    646         """Check style in the given files or directories.
    647 
    648         Args:
    649           paths: A list of file paths and directory paths.
    650           mock_check_file: A mock of self.check_file for unit testing.
    651           mock_os: A mock os for unit testing.
    652 
    653         """
    654         check_file = self.check_file if mock_check_file is None else \
    655                      mock_check_file
    656         os_module = os if mock_os is None else mock_os
    657 
    658         for path in paths:
    659             if os_module.path.isdir(path):
    660                 self._check_directory(directory=path,
    661                                       check_file=check_file,
    662                                       mock_os_walk=os_module.walk)
    663             else:
    664                 check_file(path)
    665 
    666     def _check_directory(self, directory, check_file, mock_os_walk=None):
    667         """Check style in all files in a directory, recursively.
    668 
    669         Args:
    670           directory: A path to a directory.
    671           check_file: The function to use in place of self.check_file().
    672           mock_os_walk: A mock os.walk for unit testing.
    673 
    674         """
    675         os_walk = os.walk if mock_os_walk is None else mock_os_walk
    676 
    677         for dir_path, dir_names, file_names in os_walk(directory):
    678             for file_name in file_names:
    679                 file_path = os.path.join(dir_path, file_name)
    680                 check_file(file_path)
    681 
    682     def check_file(self, file_path, line_numbers=None,
    683                    mock_handle_style_error=None,
    684                    mock_os_path_exists=None,
    685                    mock_process_file=None):
    686         """Check style in the given file.
    687 
    688         Args:
    689           file_path: The path of the file to process.  If possible, the path
    690                      should be relative to the source root.  Otherwise,
    691                      path-specific logic may not behave as expected.
    692           line_numbers: An array of line numbers of the lines for which
    693                         style errors should be reported, or None if errors
    694                         for all lines should be reported.  Normally, this
    695                         array contains the line numbers corresponding to the
    696                         modified lines of a patch.
    697           mock_handle_style_error: A unit-testing replacement for the function
    698                                    to call when a style error occurs. Defaults
    699                                    to a DefaultStyleErrorHandler instance.
    700           mock_os_path_exists: A unit-test replacement for os.path.exists.
    701                                This parameter should only be used for unit
    702                                tests.
    703           mock_process_file: The function to call to process the file. This
    704                              parameter should be used only for unit tests.
    705                              Defaults to the file processing method of this
    706                              class.
    707 
    708         Raises:
    709           SystemExit: if the file does not exist.
    710 
    711         """
    712         if mock_handle_style_error is None:
    713             increment = self._increment_error_count
    714             handle_style_error = DefaultStyleErrorHandler(
    715                                      configuration=self._configuration,
    716                                      file_path=file_path,
    717                                      increment_error_count=increment,
    718                                      line_numbers=line_numbers)
    719         else:
    720             handle_style_error = mock_handle_style_error
    721 
    722         os_path_exists = (os.path.exists if mock_os_path_exists is None else
    723                           mock_os_path_exists)
    724         process_file = (self._process_file if mock_process_file is None else
    725                         mock_process_file)
    726 
    727         if not os_path_exists(file_path) and file_path != "-":
    728             _log.error("File does not exist: %s" % file_path)
    729             sys.exit(1)
    730 
    731         _log.debug("Checking: " + file_path)
    732 
    733         self.file_count += 1
    734 
    735         dispatcher = ProcessorDispatcher()
    736 
    737         if dispatcher.should_skip_without_warning(file_path):
    738             return
    739         if dispatcher.should_skip_with_warning(file_path):
    740             _log.warn('File exempt from style guide. Skipping: "%s"'
    741                       % file_path)
    742             return
    743 
    744         min_confidence = self._configuration.min_confidence
    745         processor = dispatcher.dispatch_processor(file_path,
    746                                                   handle_style_error,
    747                                                   min_confidence)
    748         if processor is None:
    749             _log.debug('File not a recognized type to check. Skipping: "%s"'
    750                        % file_path)
    751             return
    752 
    753         _log.debug("Using class: " + processor.__class__.__name__)
    754 
    755         process_file(processor, file_path, handle_style_error)
    756 
    757 
    758569class StyleProcessor(ProcessorBase):
    759570
  • trunk/WebKitTools/Scripts/webkitpy/style/checker_unittest.py

    r58249 r58251  
    5050from checker import check_webkit_style_parser
    5151from checker import configure_logging
    52 from checker import DeprecatedStyleChecker
    5352from checker import ProcessorDispatcher
    5453from checker import PatchChecker
     
    742741
    743742
    744 # FIXME: Delete this class since it is no longer being used.
    745 class StyleCheckerTest(unittest.TestCase):
    746 
    747     """Test the StyleChecker class."""
    748 
    749     def _mock_stderr_write(self, message):
    750         pass
    751 
    752     def _style_checker(self, configuration):
    753         return DeprecatedStyleChecker(configuration)
    754 
    755     def test_init(self):
    756         """Test __init__ constructor."""
    757         configuration = StyleCheckerConfiguration(
    758                             filter_configuration=FilterConfiguration(),
    759                             max_reports_per_category={},
    760                             min_confidence=3,
    761                             output_format="vs7",
    762                             stderr_write=self._mock_stderr_write)
    763 
    764         style_checker = self._style_checker(configuration)
    765 
    766         self.assertEquals(style_checker._configuration, configuration)
    767         self.assertEquals(style_checker.error_count, 0)
    768         self.assertEquals(style_checker.file_count, 0)
    769 
    770 
    771 # FIXME: Delete this class since it is no longer being used.
    772 class StyleCheckerCheckFileBase(LoggingTestCase):
    773 
    774     def setUp(self):
    775         LoggingTestCase.setUp(self)
    776         self.warning_messages = ""
    777 
    778     def mock_stderr_write(self, warning_message):
    779         self.warning_messages += warning_message
    780 
    781     def _style_checker_configuration(self):
    782         return StyleCheckerConfiguration(
    783             filter_configuration=FilterConfiguration(),
    784             max_reports_per_category={"whitespace/newline": 1},
    785             min_confidence=3,
    786             output_format="vs7",
    787             stderr_write=self.mock_stderr_write)
    788 
    789 
    790 # FIXME: Delete this class since it is no longer being used.
    791 class StyleCheckerCheckFileTest(StyleCheckerCheckFileBase):
    792 
    793     """Test the check_file() method of the StyleChecker class.
    794 
    795     The check_file() method calls its process_file parameter when
    796     given a file that should not be skipped.
    797 
    798     The "got_*" attributes of this class are the parameters passed
    799     to process_file by calls to check_file() made by this test
    800     class. These attributes allow us to check the parameter values
    801     passed internally to the process_file function.
    802 
    803     Attributes:
    804       got_file_path: The file_path parameter passed by check_file()
    805                      to its process_file parameter.
    806       got_handle_style_error: The handle_style_error parameter passed
    807                               by check_file() to its process_file
    808                               parameter.
    809       got_processor: The processor parameter passed by check_file() to
    810                      its process_file parameter.
    811       warning_messages: A string containing all of the warning messages
    812                         written to the mock_stderr_write method of
    813                         this class.
    814 
    815     """
    816     def setUp(self):
    817         StyleCheckerCheckFileBase.setUp(self)
    818         self.got_file_path = None
    819         self.got_handle_style_error = None
    820         self.got_processor = None
    821 
    822     def mock_handle_style_error(self):
    823         pass
    824 
    825     def mock_os_path_exists(self, path):
    826         # We deliberately make it so that this method returns False unless
    827         # the caller has made an effort to put "does_exist" in the path.
    828         return path.find("does_exist") > -1
    829 
    830     def mock_process_file(self, processor, file_path, handle_style_error):
    831         """A mock _process_file().
    832 
    833         See the documentation for this class for more information
    834         on this function.
    835 
    836         """
    837         self.got_file_path = file_path
    838         self.got_handle_style_error = handle_style_error
    839         self.got_processor = processor
    840 
    841     def assert_attributes(self,
    842                           expected_file_path,
    843                           expected_handle_style_error,
    844                           expected_processor,
    845                           expected_warning_messages):
    846         """Assert that the attributes of this class equal the given values."""
    847         self.assertEquals(self.got_file_path, expected_file_path)
    848         self.assertEquals(self.got_handle_style_error, expected_handle_style_error)
    849         self.assertEquals(self.got_processor, expected_processor)
    850         self.assertEquals(self.warning_messages, expected_warning_messages)
    851 
    852     def call_check_file(self, file_path):
    853         """Call the check_file() method of a test StyleChecker instance."""
    854         # Confirm that the attributes are reset.
    855         self.assert_attributes(None, None, None, "")
    856 
    857         configuration = self._style_checker_configuration()
    858 
    859         style_checker = DeprecatedStyleChecker(configuration)
    860 
    861         style_checker.check_file(file_path=file_path,
    862             mock_handle_style_error=self.mock_handle_style_error,
    863             mock_os_path_exists=self.mock_os_path_exists,
    864             mock_process_file=self.mock_process_file)
    865 
    866         self.assertEquals(style_checker.file_count, 1)
    867 
    868     def test_check_file_does_not_exist(self):
    869         file_path = "file_does_not_exist.txt"
    870 
    871         # Confirm that the file does not exist.
    872         self.assertFalse(self.mock_os_path_exists(file_path))
    873 
    874         # Check the outcome.
    875         self.assertRaises(SystemExit, self.call_check_file, file_path)
    876         self.assertLog(["ERROR: File does not exist: "
    877                         "file_does_not_exist.txt\n"])
    878 
    879     def test_check_file_stdin(self):
    880         file_path = "-"
    881 
    882         # Confirm that the file does not exist.
    883         self.assertFalse(self.mock_os_path_exists(file_path))
    884 
    885         # Check the outcome.
    886         self.call_check_file(file_path)
    887         expected_processor = CppProcessor(file_path,
    888                                           "",
    889                                           self.mock_handle_style_error, 3)
    890         self.assert_attributes(file_path,
    891                                self.mock_handle_style_error,
    892                                expected_processor,
    893                                "")
    894 
    895     def test_check_file_on_skip_without_warning(self):
    896         """Test check_file() for a skipped-without-warning file."""
    897 
    898         file_path = "LayoutTests/does_exist/foo.txt"
    899 
    900         dispatcher = ProcessorDispatcher()
    901         # Confirm that the input file is truly a skipped-without-warning file.
    902         self.assertTrue(dispatcher.should_skip_without_warning(file_path))
    903 
    904         # Check the outcome.
    905         self.call_check_file(file_path)
    906         self.assert_attributes(None, None, None, "")
    907 
    908     def test_check_file_on_skip_with_warning(self):
    909         """Test check_file() for a skipped-with-warning file."""
    910 
    911         file_path = "does_exist/gtk2drawing.c"
    912 
    913         dispatcher = ProcessorDispatcher()
    914         # Check that the input file is truly a skipped-with-warning file.
    915         self.assertTrue(dispatcher.should_skip_with_warning(file_path))
    916 
    917         # Check the outcome.
    918         self.call_check_file(file_path)
    919         self.assert_attributes(None, None, None, "")
    920         self.assertLog(["WARNING: File exempt from style guide. "
    921                         'Skipping: "does_exist/gtk2drawing.c"\n'])
    922 
    923     def test_check_file_on_non_skipped(self):
    924 
    925         # We use a C++ file since by using a CppProcessor, we can check
    926         # that all of the possible information is getting passed to
    927         # process_file (in particular, the min_confidence parameter).
    928         file_base = "foo_does_exist"
    929         file_extension = "cpp"
    930         file_path = file_base + "." + file_extension
    931 
    932         dispatcher = ProcessorDispatcher()
    933         # Check that the input file is truly a C++ file.
    934         self.assertEquals(dispatcher._file_type(file_path), style.FileType.CPP)
    935 
    936         # Check the outcome.
    937         self.call_check_file(file_path)
    938 
    939         expected_processor = CppProcessor(file_path, file_extension, self.mock_handle_style_error, 3)
    940 
    941         self.assert_attributes(file_path,
    942                                self.mock_handle_style_error,
    943                                expected_processor,
    944                                "")
    945 
    946 
    947 # FIXME: Delete this class since it is no longer being used.
    948 class StyleCheckerCheckPathsTest(unittest.TestCase):
    949 
    950     """Test the check_paths() method of the StyleChecker class."""
    951 
    952     class MockOs(object):
    953 
    954         class MockPath(object):
    955 
    956             """A mock os.path."""
    957 
    958             def isdir(self, path):
    959                 return path == "directory"
    960 
    961         def __init__(self):
    962             self.path = self.MockPath()
    963 
    964         def walk(self, directory):
    965             """A mock of os.walk."""
    966             if directory == "directory":
    967                 dirs = [("dir_path1", [], ["file1", "file2"]),
    968                         ("dir_path2", [], ["file3"])]
    969                 return dirs
    970             return None
    971 
    972     def setUp(self):
    973         self._checked_files = []
    974 
    975     def _mock_check_file(self, file):
    976         self._checked_files.append(file)
    977 
    978     def test_check_paths(self):
    979         """Test StyleChecker.check_paths()."""
    980         checker = DeprecatedStyleChecker(configuration=None)
    981         mock_check_file = self._mock_check_file
    982         mock_os = self.MockOs()
    983 
    984         # Confirm that checked files is empty at the outset.
    985         self.assertEquals(self._checked_files, [])
    986         checker.check_paths(["path1", "directory"],
    987                             mock_check_file=mock_check_file,
    988                             mock_os=mock_os)
    989         self.assertEquals(self._checked_files,
    990                           ["path1",
    991                            os.path.join("dir_path1", "file1"),
    992                            os.path.join("dir_path1", "file2"),
    993                            os.path.join("dir_path2", "file3")])
    994 
    995 
    996743class PatchCheckerTest(unittest.TestCase):
    997744
Note: See TracChangeset for help on using the changeset viewer.