Skip to content

Commit 1f01682

Browse files
committed
Add python 3 support to cpplint_unittest
1 parent 849a106 commit 1f01682

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

cpplint/cpplint_unittest.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import os
3838
import random
3939
import re
40+
import six
4041
import subprocess
4142
import sys
4243
import unittest
@@ -3151,7 +3152,8 @@ def DoTest(self, raw_bytes, has_invalid_utf8):
31513152
error_collector = ErrorCollector(self.assert_)
31523153
cpplint.ProcessFileData(
31533154
'foo.cc', 'cc',
3154-
unicode(raw_bytes, 'utf8', 'replace').split('\n'),
3155+
six.ensure_text(raw_bytes, encoding='utf8',
3156+
errors='replace').split('\n'),
31553157
error_collector)
31563158
# The warning appears only once.
31573159
self.assertEquals(
@@ -3162,11 +3164,11 @@ def DoTest(self, raw_bytes, has_invalid_utf8):
31623164
' [readability/utf8] [5]'))
31633165

31643166
DoTest(self, 'Hello world\n', False)
3165-
DoTest(self, '\xe9\x8e\xbd\n', False)
3166-
DoTest(self, '\xe9x\x8e\xbd\n', True)
3167+
DoTest(self, b'\xe9\x8e\xbd\n', False)
3168+
DoTest(self, b'\xe9x\x8e\xbd\n', True)
31673169
# This is the encoding of the replacement character itself (which
31683170
# you can see by evaluating codecs.getencoder('utf8')(u'\ufffd')).
3169-
DoTest(self, '\xef\xbf\xbd\n', True)
3171+
DoTest(self, b'\xef\xbf\xbd\n', True)
31703172

31713173
def testBadCharacters(self):
31723174
# Test for NUL bytes only
@@ -3184,7 +3186,7 @@ def testBadCharacters(self):
31843186
cpplint.ProcessFileData(
31853187
'nul_utf8.cc', 'cc',
31863188
['// Copyright 2014 Your Company.',
3187-
unicode('\xe9x\0', 'utf8', 'replace'), ''],
3189+
six.ensure_text(b'\xe9x\0', encoding='utf8', errors='replace'), ''],
31883190
error_collector)
31893191
self.assertEquals(
31903192
error_collector.Results(),
@@ -5810,8 +5812,9 @@ def _runCppLint(self, *args):
58105812

58115813
def testNonQuietWithErrors(self):
58125814
# This will fail: the test header is missing a copyright and header guard.
5813-
(return_code, output) = self._runCppLint()
5815+
(return_code, output_bytes) = self._runCppLint()
58145816
self.assertEquals(1, return_code)
5817+
output = output_bytes.decode('utf-8')
58155818
# Always-on behavior: Print error messages as they come up.
58165819
self.assertIn("[legal/copyright]", output)
58175820
self.assertIn("[build/header_guard]", output)
@@ -5821,7 +5824,8 @@ def testNonQuietWithErrors(self):
58215824

58225825
def testQuietWithErrors(self):
58235826
# When there are errors, behavior is identical to not passing --quiet.
5824-
(return_code, output) = self._runCppLint('--quiet')
5827+
(return_code, output_bytes) = self._runCppLint('--quiet')
5828+
output = output_bytes.decode('utf-8')
58255829
self.assertEquals(1, return_code)
58265830
self.assertIn("[legal/copyright]", output)
58275831
self.assertIn("[build/header_guard]", output)
@@ -5831,9 +5835,10 @@ def testQuietWithErrors(self):
58315835

58325836
def testNonQuietWithoutErrors(self):
58335837
# This will succeed. We filtered out all the known errors for that file.
5834-
(return_code, output) = self._runCppLint('--filter=' +
5838+
(return_code, output_bytes) = self._runCppLint('--filter=' +
58355839
'-legal/copyright,' +
58365840
'-build/header_guard')
5841+
output = output_bytes.decode('utf-8')
58375842
self.assertEquals(0, return_code, output)
58385843
# No cpplint errors are printed since there were no errors.
58395844
self.assertNotIn("[legal/copyright]", output)
@@ -5845,10 +5850,11 @@ def testNonQuietWithoutErrors(self):
58455850

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

0 commit comments

Comments
 (0)