37
37
import os
38
38
import random
39
39
import re
40
+ import six
40
41
import subprocess
41
42
import sys
42
43
import unittest
@@ -3151,7 +3152,8 @@ def DoTest(self, raw_bytes, has_invalid_utf8):
3151
3152
error_collector = ErrorCollector (self .assert_ )
3152
3153
cpplint .ProcessFileData (
3153
3154
'foo.cc' , 'cc' ,
3154
- unicode (raw_bytes , 'utf8' , 'replace' ).split ('\n ' ),
3155
+ six .ensure_text (raw_bytes , encoding = 'utf8' ,
3156
+ errors = 'replace' ).split ('\n ' ),
3155
3157
error_collector )
3156
3158
# The warning appears only once.
3157
3159
self .assertEquals (
@@ -3162,11 +3164,11 @@ def DoTest(self, raw_bytes, has_invalid_utf8):
3162
3164
' [readability/utf8] [5]' ))
3163
3165
3164
3166
DoTest (self , 'Hello world\n ' , False )
3165
- DoTest (self , '\xe9 \x8e \xbd \n ' , False )
3166
- DoTest (self , '\xe9 x\x8e \xbd \n ' , True )
3167
+ DoTest (self , b '\xe9 \x8e \xbd \n ' , False )
3168
+ DoTest (self , b '\xe9 x\x8e \xbd \n ' , True )
3167
3169
# This is the encoding of the replacement character itself (which
3168
3170
# 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 )
3170
3172
3171
3173
def testBadCharacters (self ):
3172
3174
# Test for NUL bytes only
@@ -3184,7 +3186,7 @@ def testBadCharacters(self):
3184
3186
cpplint .ProcessFileData (
3185
3187
'nul_utf8.cc' , 'cc' ,
3186
3188
['// Copyright 2014 Your Company.' ,
3187
- unicode ( '\xe9 x\0 ' , 'utf8' , 'replace' ), '' ],
3189
+ six . ensure_text ( b '\xe9 x\0 ' , encoding = 'utf8' , errors = 'replace' ), '' ],
3188
3190
error_collector )
3189
3191
self .assertEquals (
3190
3192
error_collector .Results (),
@@ -5810,8 +5812,9 @@ def _runCppLint(self, *args):
5810
5812
5811
5813
def testNonQuietWithErrors (self ):
5812
5814
# 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 ()
5814
5816
self .assertEquals (1 , return_code )
5817
+ output = output_bytes .decode ('utf-8' )
5815
5818
# Always-on behavior: Print error messages as they come up.
5816
5819
self .assertIn ("[legal/copyright]" , output )
5817
5820
self .assertIn ("[build/header_guard]" , output )
@@ -5821,7 +5824,8 @@ def testNonQuietWithErrors(self):
5821
5824
5822
5825
def testQuietWithErrors (self ):
5823
5826
# 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' )
5825
5829
self .assertEquals (1 , return_code )
5826
5830
self .assertIn ("[legal/copyright]" , output )
5827
5831
self .assertIn ("[build/header_guard]" , output )
@@ -5831,9 +5835,10 @@ def testQuietWithErrors(self):
5831
5835
5832
5836
def testNonQuietWithoutErrors (self ):
5833
5837
# 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=' +
5835
5839
'-legal/copyright,' +
5836
5840
'-build/header_guard' )
5841
+ output = output_bytes .decode ('utf-8' )
5837
5842
self .assertEquals (0 , return_code , output )
5838
5843
# No cpplint errors are printed since there were no errors.
5839
5844
self .assertNotIn ("[legal/copyright]" , output )
@@ -5845,10 +5850,11 @@ def testNonQuietWithoutErrors(self):
5845
5850
5846
5851
def testQuietWithoutErrors (self ):
5847
5852
# 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' ,
5849
5854
'--filter=' +
5850
5855
'-legal/copyright,' +
5851
5856
'-build/header_guard' )
5857
+ output = output_bytes .decode ('utf-8' )
5852
5858
self .assertEquals (0 , return_code , output )
5853
5859
# No cpplint errors are printed since there were no errors.
5854
5860
self .assertNotIn ("[legal/copyright]" , output )
0 commit comments