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
@@ -3071,7 +3072,8 @@ def DoTest(self, raw_bytes, has_invalid_utf8):
3071
3072
error_collector = ErrorCollector (self .assert_ )
3072
3073
cpplint .ProcessFileData (
3073
3074
'foo.cc' , 'cc' ,
3074
- unicode (raw_bytes , 'utf8' , 'replace' ).split ('\n ' ),
3075
+ six .ensure_text (raw_bytes , encoding = 'utf8' ,
3076
+ errors = 'replace' ).split ('\n ' ),
3075
3077
error_collector )
3076
3078
# The warning appears only once.
3077
3079
self .assertEquals (
@@ -3082,11 +3084,11 @@ def DoTest(self, raw_bytes, has_invalid_utf8):
3082
3084
' [readability/utf8] [5]' ))
3083
3085
3084
3086
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 )
3087
3089
# This is the encoding of the replacement character itself (which
3088
3090
# 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 )
3090
3092
3091
3093
def testBadCharacters (self ):
3092
3094
# Test for NUL bytes only
@@ -3104,7 +3106,7 @@ def testBadCharacters(self):
3104
3106
cpplint .ProcessFileData (
3105
3107
'nul_utf8.cc' , 'cc' ,
3106
3108
['// Copyright 2014 Your Company.' ,
3107
- unicode ( '\xe9 x\0 ' , 'utf8' , 'replace' ), '' ],
3109
+ six . ensure_text ( b '\xe9 x\0 ' , encoding = 'utf8' , errors = 'replace' ), '' ],
3108
3110
error_collector )
3109
3111
self .assertEquals (
3110
3112
error_collector .Results (),
@@ -5723,8 +5725,9 @@ def _runCppLint(self, *args):
5723
5725
5724
5726
def testNonQuietWithErrors (self ):
5725
5727
# 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 ()
5727
5729
self .assertEquals (1 , return_code )
5730
+ output = output_bytes .decode ('utf-8' )
5728
5731
# Always-on behavior: Print error messages as they come up.
5729
5732
self .assertIn ("[legal/copyright]" , output )
5730
5733
self .assertIn ("[build/header_guard]" , output )
@@ -5734,7 +5737,8 @@ def testNonQuietWithErrors(self):
5734
5737
5735
5738
def testQuietWithErrors (self ):
5736
5739
# 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' )
5738
5742
self .assertEquals (1 , return_code )
5739
5743
self .assertIn ("[legal/copyright]" , output )
5740
5744
self .assertIn ("[build/header_guard]" , output )
@@ -5744,9 +5748,10 @@ def testQuietWithErrors(self):
5744
5748
5745
5749
def testNonQuietWithoutErrors (self ):
5746
5750
# 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=' +
5748
5752
'-legal/copyright,' +
5749
5753
'-build/header_guard' )
5754
+ output = output_bytes .decode ('utf-8' )
5750
5755
self .assertEquals (0 , return_code , output )
5751
5756
# No cpplint errors are printed since there were no errors.
5752
5757
self .assertNotIn ("[legal/copyright]" , output )
@@ -5758,10 +5763,11 @@ def testNonQuietWithoutErrors(self):
5758
5763
5759
5764
def testQuietWithoutErrors (self ):
5760
5765
# 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' ,
5762
5767
'--filter=' +
5763
5768
'-legal/copyright,' +
5764
5769
'-build/header_guard' )
5770
+ output = output_bytes .decode ('utf-8' )
5765
5771
self .assertEquals (0 , return_code , output )
5766
5772
# No cpplint errors are printed since there were no errors.
5767
5773
self .assertNotIn ("[legal/copyright]" , output )
0 commit comments