turn svn output into unicode before parsing

This commit is contained in:
Alan Hamlett 2015-09-07 21:25:21 -07:00
parent edb1dab9a8
commit eff141187b
3 changed files with 43 additions and 8 deletions

View file

@ -95,6 +95,30 @@ class LanguagesTestCase(utils.TestCase):
self.assertEquals('svn', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
def test_svn_exception_handled(self):
response = Response()
response.status_code = 0
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
with utils.mock.patch('wakatime.projects.git.Git.process') as mock_git:
mock_git.return_value = False
with utils.mock.patch('wakatime.projects.subversion.Popen') as mock_popen:
mock_popen.side_effect = OSError('')
with utils.mock.patch('wakatime.projects.subversion.Popen.communicate') as mock_communicate:
mock_communicate.side_effect = OSError('')
now = u(int(time.time()))
entity = 'tests/samples/projects/svn/emptyfile.txt'
config = 'tests/samples/sample.cfg'
args = ['--file', entity, '--config', config, '--time', now]
execute(args)
self.assertNotIn('project', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0])
def test_project_map(self):
response = Response()
response.status_code = 0

View file

@ -26,9 +26,12 @@ if is_py2: # pragma: nocover
return text.decode('utf-8')
except:
try:
return unicode(text)
return text.decode(sys.getdefaultencoding())
except:
return text
try:
return unicode(text)
except:
return text
open = codecs.open
basestring = basestring
@ -39,8 +42,17 @@ elif is_py3: # pragma: nocover
if text is None:
return None
if isinstance(text, bytes):
return text.decode('utf-8')
return str(text)
try:
return text.decode('utf-8')
except:
try:
return text.decode(sys.getdefaultencoding())
except:
pass
try:
return str(text)
except:
return text
open = open
basestring = (str, bytes)

View file

@ -19,7 +19,7 @@ from ..compat import u, open
try:
from collections import OrderedDict
except ImportError:
from ..packages.ordereddict import OrderedDict
from ..packages.ordereddict import OrderedDict # pragma: nocover
log = logging.getLogger('WakaTime')
@ -69,8 +69,7 @@ class Subversion(BaseProject):
else:
if stdout:
for line in stdout.splitlines():
if isinstance(line, bytes):
line = bytes.decode(line)
line = u(line)
line = line.split(': ', 1)
if len(line) == 2:
info[line[0]] = line[1]
@ -78,7 +77,7 @@ class Subversion(BaseProject):
def _find_project_base(self, path, found=False):
if platform.system() == 'Windows':
return False
return False # pragma: nocover
path = os.path.realpath(path)
if os.path.isfile(path):
path = os.path.split(path)[0]