3737import os
3838import random
3939import re
40+ import six
4041import subprocess
4142import sys
4243import unittest
@@ -3071,7 +3072,8 @@ def DoTest(self, raw_bytes, has_invalid_utf8):
30713072 error_collector = ErrorCollector (self .assert_ )
30723073 cpplint .ProcessFileData (
30733074 'foo.cc' , 'cc' ,
3074- unicode (raw_bytes , 'utf8' , 'replace' ).split ('\n ' ),
3075+ six .ensure_text (raw_bytes , encoding = 'utf8' ,
3076+ errors = 'replace' ).split ('\n ' ),
30753077 error_collector )
30763078 # The warning appears only once.
30773079 self .assertEquals (
@@ -3082,11 +3084,11 @@ def DoTest(self, raw_bytes, has_invalid_utf8):
30823084 ' [readability/utf8] [5]' ))
30833085
30843086 DoTest (self , 'Hello world\n ' , False )
3085- DoTest (self , '\xe9 \x8e \xbd \n ' , False )
3086- DoTest (self , '\xe9 x\x8e \xbd \n ' , True )
3087+ DoTest (self , b '\xe9 \x8e \xbd \n ' , False )
3088+ DoTest (self , b '\xe9 x\x8e \xbd \n ' , True )
30873089 # This is the encoding of the replacement character itself (which
30883090 # you can see by evaluating codecs.getencoder('utf8')(u'\ufffd')).
3089- DoTest (self , '\xef \xbf \xbd \n ' , True )
3091+ DoTest (self , b '\xef \xbf \xbd \n ' , True )
30903092
30913093 def testBadCharacters (self ):
30923094 # Test for NUL bytes only
@@ -3104,7 +3106,7 @@ def testBadCharacters(self):
31043106 cpplint .ProcessFileData (
31053107 'nul_utf8.cc' , 'cc' ,
31063108 ['// Copyright 2014 Your Company.' ,
3107- unicode ( '\xe9 x\0 ' , 'utf8' , 'replace' ), '' ],
3109+ six . ensure_text ( b '\xe9 x\0 ' , encoding = 'utf8' , errors = 'replace' ), '' ],
31083110 error_collector )
31093111 self .assertEquals (
31103112 error_collector .Results (),
@@ -5723,8 +5725,9 @@ def _runCppLint(self, *args):
57235725
57245726 def testNonQuietWithErrors (self ):
57255727 # This will fail: the test header is missing a copyright and header guard.
5726- (return_code , output ) = self ._runCppLint ()
5728+ (return_code , output_bytes ) = self ._runCppLint ()
57275729 self .assertEquals (1 , return_code )
5730+ output = output_bytes .decode ('utf-8' )
57285731 # Always-on behavior: Print error messages as they come up.
57295732 self .assertIn ("[legal/copyright]" , output )
57305733 self .assertIn ("[build/header_guard]" , output )
@@ -5734,7 +5737,8 @@ def testNonQuietWithErrors(self):
57345737
57355738 def testQuietWithErrors (self ):
57365739 # When there are errors, behavior is identical to not passing --quiet.
5737- (return_code , output ) = self ._runCppLint ('--quiet' )
5740+ (return_code , output_bytes ) = self ._runCppLint ('--quiet' )
5741+ output = output_bytes .decode ('utf-8' )
57385742 self .assertEquals (1 , return_code )
57395743 self .assertIn ("[legal/copyright]" , output )
57405744 self .assertIn ("[build/header_guard]" , output )
@@ -5744,9 +5748,10 @@ def testQuietWithErrors(self):
57445748
57455749 def testNonQuietWithoutErrors (self ):
57465750 # This will succeed. We filtered out all the known errors for that file.
5747- (return_code , output ) = self ._runCppLint ('--filter=' +
5751+ (return_code , output_bytes ) = self ._runCppLint ('--filter=' +
57485752 '-legal/copyright,' +
57495753 '-build/header_guard' )
5754+ output = output_bytes .decode ('utf-8' )
57505755 self .assertEquals (0 , return_code , output )
57515756 # No cpplint errors are printed since there were no errors.
57525757 self .assertNotIn ("[legal/copyright]" , output )
@@ -5758,10 +5763,11 @@ def testNonQuietWithoutErrors(self):
57585763
57595764 def testQuietWithoutErrors (self ):
57605765 # This will succeed. We filtered out all the known errors for that file.
5761- (return_code , output ) = self ._runCppLint ('--quiet' ,
5766+ (return_code , output_bytes ) = self ._runCppLint ('--quiet' ,
57625767 '--filter=' +
57635768 '-legal/copyright,' +
57645769 '-build/header_guard' )
5770+ output = output_bytes .decode ('utf-8' )
57655771 self .assertEquals (0 , return_code , output )
57665772 # No cpplint errors are printed since there were no errors.
57675773 self .assertNotIn ("[legal/copyright]" , output )
0 commit comments