Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python 3 support to cpplint_unittest #28

Merged
merged 1 commit into from
Mar 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions cpplint/cpplint_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3151,7 +3151,7 @@ def DoTest(self, raw_bytes, has_invalid_utf8):
error_collector = ErrorCollector(self.assert_)
cpplint.ProcessFileData(
'foo.cc', 'cc',
unicode(raw_bytes, 'utf8', 'replace').split('\n'),
raw_bytes.decode('utf-8', errors='replace').split('\n'),
error_collector)
# The warning appears only once.
self.assertEquals(
Expand All @@ -3161,12 +3161,12 @@ def DoTest(self, raw_bytes, has_invalid_utf8):
' (or Unicode replacement character).'
' [readability/utf8] [5]'))

DoTest(self, 'Hello world\n', False)
DoTest(self, '\xe9\x8e\xbd\n', False)
DoTest(self, '\xe9x\x8e\xbd\n', True)
DoTest(self, b'Hello world\n', False)
DoTest(self, b'\xe9\x8e\xbd\n', False)
DoTest(self, b'\xe9x\x8e\xbd\n', True)
# This is the encoding of the replacement character itself (which
# you can see by evaluating codecs.getencoder('utf8')(u'\ufffd')).
DoTest(self, '\xef\xbf\xbd\n', True)
DoTest(self, b'\xef\xbf\xbd\n', True)

def testBadCharacters(self):
# Test for NUL bytes only
Expand All @@ -3184,7 +3184,7 @@ def testBadCharacters(self):
cpplint.ProcessFileData(
'nul_utf8.cc', 'cc',
['// Copyright 2014 Your Company.',
unicode('\xe9x\0', 'utf8', 'replace'), ''],
b'\xe9x\0'.decode('utf8', errors='replace'), ''],
error_collector)
self.assertEquals(
error_collector.Results(),
Expand Down Expand Up @@ -5810,8 +5810,9 @@ def _runCppLint(self, *args):

def testNonQuietWithErrors(self):
# This will fail: the test header is missing a copyright and header guard.
(return_code, output) = self._runCppLint()
(return_code, output_bytes) = self._runCppLint()
self.assertEquals(1, return_code)
output = output_bytes.decode('utf-8')
# Always-on behavior: Print error messages as they come up.
self.assertIn("[legal/copyright]", output)
self.assertIn("[build/header_guard]", output)
Expand All @@ -5821,7 +5822,8 @@ def testNonQuietWithErrors(self):

def testQuietWithErrors(self):
# When there are errors, behavior is identical to not passing --quiet.
(return_code, output) = self._runCppLint('--quiet')
(return_code, output_bytes) = self._runCppLint('--quiet')
output = output_bytes.decode('utf-8')
self.assertEquals(1, return_code)
self.assertIn("[legal/copyright]", output)
self.assertIn("[build/header_guard]", output)
Expand All @@ -5831,9 +5833,10 @@ def testQuietWithErrors(self):

def testNonQuietWithoutErrors(self):
# This will succeed. We filtered out all the known errors for that file.
(return_code, output) = self._runCppLint('--filter=' +
'-legal/copyright,' +
'-build/header_guard')
(return_code, output_bytes) = self._runCppLint('--filter=' +
'-legal/copyright,' +
'-build/header_guard')
output = output_bytes.decode('utf-8')
self.assertEquals(0, return_code, output)
# No cpplint errors are printed since there were no errors.
self.assertNotIn("[legal/copyright]", output)
Expand All @@ -5845,10 +5848,11 @@ def testNonQuietWithoutErrors(self):

def testQuietWithoutErrors(self):
# This will succeed. We filtered out all the known errors for that file.
(return_code, output) = self._runCppLint('--quiet',
'--filter=' +
'-legal/copyright,' +
'-build/header_guard')
(return_code, output_bytes) = self._runCppLint('--quiet',
'--filter=' +
'-legal/copyright,' +
'-build/header_guard')
output = output_bytes.decode('utf-8')
self.assertEquals(0, return_code, output)
# No cpplint errors are printed since there were no errors.
self.assertNotIn("[legal/copyright]", output)
Expand Down