def test_trailing_white(self): passes = ["i=0\n"] fails = ["i=0 ", " "] self.assertEqual(pycodestyle.trailing_whitespace(passes[0]), None) self.assertEqual(pycodestyle.trailing_whitespace(fails[0]), (3, 'W291 trailing whitespace')) self.assertEqual(pycodestyle.trailing_whitespace(fails[1]), (0, 'W293 blank line contains whitespace'))
def _eb_check_trailing_whitespace(physical_line, lines, line_number, checker_state): # pylint:disable=unused-argument """ W299 Warn about trailing whitespace, except for the description and comments. This differs from the standard trailing whitespace check as that will warn for any trailing whitespace. The arguments are explained at https://pycodestyle.readthedocs.io/en/latest/developer.html#contribute """ # apparently this is not the same as physical_line line?! line = lines[line_number-1] if COMMENT_REGEX.match(line): return None result = trailing_whitespace(line) if result: result = (result[0], result[1].replace('W291', 'W299')) # keep track of name of last parameter that was defined param_def = PARAM_DEF_REGEX.search(line) if param_def: checker_state['eb_last_key'] = param_def.group('key') # if the warning is about the multiline string of description # we will not issue a warning if checker_state.get('eb_last_key') == 'description': result = None return result