def test_ne(self): """Test __ne__ inequality function.""" # != calls __ne__. # By default, __ne__ always returns true on different objects. # Thus, just check the distinguishing case to verify that the # code defines __ne__. self.assertFalse(ProcessorOptions() != ProcessorOptions())
def test_call(self): patch_files = parse_patch(self._patch_string) diff = patch_files[self._file_path] options = ProcessorOptions(verbosity=3) handle_error = PatchStyleErrorHandler(diff, self._file_path, options, self._mock_increment_error_count, self._mock_stderr_write) category = "whitespace/tab" confidence = 5 message = "message" # Confirm error is reportable. self.assertTrue( options.is_reportable(category, confidence, self._file_path)) # Confirm error count initialized to zero. self.assertEquals(0, self._error_count) # Test error in unmodified line (error count does not increment). handle_error(1, category, confidence, message) self.assertEquals(0, self._error_count) # Test error in modified line (error count increments). handle_error(2, category, confidence, message) self.assertEquals(1, self._error_count)
def test_call(self): patch_files = parse_patch(self._patch_string) diff = patch_files[self._file_path] options = ProcessorOptions(verbosity=3) handle_error = PatchStyleErrorHandler(diff, self._file_path, options, self._mock_increment_error_count, self._mock_stderr_write) category = "whitespace/tab" confidence = 5 message = "message" # Confirm error is reportable. self.assertTrue(options.is_reportable(category, confidence, self._file_path)) # Confirm error count initialized to zero. self.assertEquals(0, self._error_count) # Test error in unmodified line (error count does not increment). handle_error(1, category, confidence, message) self.assertEquals(0, self._error_count) # Test error in modified line (error count increments). handle_error(2, category, confidence, message) self.assertEquals(1, self._error_count)
def test_is_reportable(self): """Test is_reportable().""" filter_configuration = FilterConfiguration(base_rules=["-xyz"]) options = ProcessorOptions(filter_configuration=filter_configuration, verbosity=3) # Test verbosity self.assertTrue(options.is_reportable("abc", 3, "foo.h")) self.assertFalse(options.is_reportable("abc", 2, "foo.h")) # Test filter self.assertTrue(options.is_reportable("xy", 3, "foo.h")) self.assertFalse(options.is_reportable("xyz", 3, "foo.h"))
def test_call_non_reportable(self): """Test __call__() method with a non-reportable error.""" confidence = 1 options = ProcessorOptions(verbosity=3) self._check_initialized() # Confirm the error is not reportable. self.assertFalse(options.is_reportable(self._category, confidence, self._file_path)) self._call_error_handler(options, confidence) self.assertEquals(0, self._error_count) self.assertEquals("", self._error_messages)
def test_call_non_reportable(self): """Test __call__() method with a non-reportable error.""" confidence = 1 options = ProcessorOptions(verbosity=3) self._check_initialized() # Confirm the error is not reportable. self.assertFalse( options.is_reportable(self._category, confidence, self._file_path)) self._call_error_handler(options, confidence) self.assertEquals(0, self._error_count) self.assertEquals("", self._error_messages)
def test_init(self): """Test __init__ constructor.""" options = ProcessorOptions() style_checker = self._style_checker(options) self.assertEquals(style_checker.error_count, 0) self.assertEquals(style_checker.options, options)
def test_call_max_reports_per_category(self): """Test error report suppression in __call__() method.""" confidence = 5 options = ProcessorOptions( verbosity=3, max_reports_per_category={self._category: 2}) error_handler = self._error_handler(options) self._check_initialized() # First call: usual reporting. self._call(error_handler, options, confidence) self.assertEquals(1, self._error_count) self.assertEquals(self._error_messages, "foo.h:100: message [whitespace/tab] [5]\n") # Second call: suppression message reported. self._error_messages = "" self._call(error_handler, options, confidence) self.assertEquals(2, self._error_count) self.assertEquals( self._error_messages, "foo.h:100: message [whitespace/tab] [5]\n" "Suppressing further [%s] reports for this file.\n" % self._category) # Third call: no report. self._error_messages = "" self._call(error_handler, options, confidence) self.assertEquals(3, self._error_count) self.assertEquals(self._error_messages, "")
def test_call_reportable_vs7(self): """Test __call__() method with a reportable error and vs7 format.""" confidence = 5 options = ProcessorOptions(verbosity=3, output_format="vs7") self._check_initialized() self._call_error_handler(options, confidence) self.assertEquals(1, self._error_count) self.assertEquals(self._error_messages, "foo.h(100): message [whitespace/tab] [5]\n")
def test_init(self): """Test __init__ constructor.""" # Check default parameters. options = ProcessorOptions() self.assertEquals(options.extra_flag_values, {}) self.assertEquals(options.filter_configuration, FilterConfiguration()) self.assertEquals(options.git_commit, None) self.assertEquals(options.max_reports_per_category, {}) self.assertEquals(options.output_format, "emacs") self.assertEquals(options.verbosity, 1) # Check argument validation. self.assertRaises(ValueError, ProcessorOptions, output_format="bad") ProcessorOptions(output_format="emacs") # No ValueError: works ProcessorOptions(output_format="vs7") # works self.assertRaises(ValueError, ProcessorOptions, verbosity=0) self.assertRaises(ValueError, ProcessorOptions, verbosity=6) ProcessorOptions(verbosity=1) # works ProcessorOptions(verbosity=5) # works # Check attributes. filter_configuration = FilterConfiguration(base_rules=["+"]) options = ProcessorOptions(extra_flag_values={"extra_value": 2}, filter_configuration=filter_configuration, git_commit="commit", max_reports_per_category={"category": 3}, output_format="vs7", verbosity=3) self.assertEquals(options.extra_flag_values, {"extra_value": 2}) self.assertEquals(options.filter_configuration, filter_configuration) self.assertEquals(options.git_commit, "commit") self.assertEquals(options.max_reports_per_category, {"category": 3}) self.assertEquals(options.output_format, "vs7") self.assertEquals(options.verbosity, 3)
def call_check_file(self, file_path): """Call the check_file() method of a test StyleChecker instance.""" # Confirm that the attributes are reset. self.assert_attributes(None, None, None, "") # Create a test StyleChecker instance. # # The verbosity attribute is the only ProcessorOptions # attribute that needs to be checked in this test. # This is because it is the only option is directly # passed to the constructor of a style processor. options = ProcessorOptions(verbosity=3) style_checker = StyleChecker(options, self.mock_stderr_write) style_checker.check_file(file_path, self.mock_handle_style_error, self.mock_process_file)
def test_eq(self): """Test __eq__ equality function.""" # == calls __eq__. self.assertTrue(ProcessorOptions() == ProcessorOptions()) # Verify that a difference in any argument causes equality to fail. filter_configuration = FilterConfiguration(base_rules=["+"]) options = ProcessorOptions(extra_flag_values={"extra_value": 1}, filter_configuration=filter_configuration, git_commit="commit", max_reports_per_category={"category": 3}, output_format="vs7", verbosity=1) self.assertFalse(options == ProcessorOptions( extra_flag_values={"extra_value": 2})) new_config = FilterConfiguration(base_rules=["-"]) self.assertFalse(options == ProcessorOptions( filter_configuration=new_config)) self.assertFalse(options == ProcessorOptions(git_commit="commit2")) self.assertFalse(options == ProcessorOptions( max_reports_per_category={"category": 2})) self.assertFalse(options == ProcessorOptions(output_format="emacs")) self.assertFalse(options == ProcessorOptions(verbosity=2))