File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,6 @@ def __getattribute__(self, name):
3030 value = utils .git_config ('pw.{}' .format (name ))
3131 if value :
3232 LOG .debug ("Retrieved '{}' setting from git-config" .format (name ))
33- value = value .decode ('utf-8' )
3433
3534 setattr (self , name , value )
3635
Original file line number Diff line number Diff line change 77import subprocess
88import sys
99
10+ if sys .version_info < (3 , 0 ):
11+ _text = unicode # noqa
12+ else :
13+ _text = str # noqa
14+
1015
1116def trim (string , length = 70 ): # type: (str, int) -> str
1217 """Trim a string to the given length."""
@@ -22,9 +27,9 @@ def git_config(value):
2227 try :
2328 output = subprocess .check_output (['git' , 'config' , value ])
2429 except subprocess .CalledProcessError :
25- output = ''
30+ output = b ''
2631
27- return output .strip ()
32+ return output .decode ( 'utf-8' ). strip ()
2833
2934
3035def git_am (mbox , args ):
Original file line number Diff line number Diff line change 88from git_pw import utils
99
1010
11- @mock .patch .object (utils .subprocess , 'check_output' , return_value = ' bar ' )
11+ @mock .patch .object (utils .subprocess , 'check_output' , return_value = b ' bar ' )
1212def test_git_config (mock_subprocess ):
1313 value = utils .git_config ('foo' )
1414
1515 assert value == 'bar'
1616 mock_subprocess .assert_called_once_with (['git' , 'config' , 'foo' ])
1717
1818
19+ @mock .patch .object (utils .subprocess , 'check_output' ,
20+ return_value = b'\xf0 \x9f \xa4 \xb7 ' )
21+ def test_git_config_unicode (mock_subprocess ):
22+ value = utils .git_config ('foo' )
23+
24+ assert value == u'\U0001f937 '
25+ mock_subprocess .assert_called_once_with (['git' , 'config' , 'foo' ])
26+
27+
1928@mock .patch .object (utils .subprocess , 'check_output' ,
2029 side_effect = subprocess .CalledProcessError (1 , 'xyz' , '123' ))
2130def test_git_config_error (mock_subprocess ):
You can’t perform that action at this time.
0 commit comments