turn svn output into unicode before parsing
This commit is contained in:
parent
edb1dab9a8
commit
eff141187b
3 changed files with 43 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -24,6 +24,9 @@ if is_py2: # pragma: nocover
|
|||
return None
|
||||
try:
|
||||
return text.decode('utf-8')
|
||||
except:
|
||||
try:
|
||||
return text.decode(sys.getdefaultencoding())
|
||||
except:
|
||||
try:
|
||||
return unicode(text)
|
||||
|
@ -39,8 +42,17 @@ elif is_py3: # pragma: nocover
|
|||
if text is None:
|
||||
return None
|
||||
if isinstance(text, bytes):
|
||||
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)
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue