tests for mercurial project detection

This commit is contained in:
Alan Hamlett 2015-09-07 21:40:01 -07:00
parent 1194bc004e
commit fdaabdd27e
3 changed files with 23 additions and 3 deletions

View file

@ -0,0 +1 @@
test-hg-branch

View file

@ -119,6 +119,25 @@ class LanguagesTestCase(utils.TestCase):
self.assertNotIn('project', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]) self.assertNotIn('project', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0])
def test_mercurial_project_detected(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
now = u(int(time.time()))
entity = 'tests/samples/projects/hg/emptyfile.txt'
config = 'tests/samples/sample.cfg'
args = ['--file', entity, '--config', config, '--time', now]
execute(args)
self.assertEquals('hg', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
self.assertEquals('test-hg-branch', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['branch'])
def test_project_map(self): def test_project_map(self):
response = Response() response = Response()
response.status_code = 0 response.status_code = 0

View file

@ -29,7 +29,7 @@ class Mercurial(BaseProject):
def name(self): def name(self):
if self.configDir: if self.configDir:
return u(os.path.basename(os.path.dirname(self.configDir))) return u(os.path.basename(os.path.dirname(self.configDir)))
return None return None # pragma: nocover
def branch(self): def branch(self):
if self.configDir: if self.configDir:
@ -37,13 +37,13 @@ class Mercurial(BaseProject):
try: try:
with open(branch_file, 'r', encoding='utf-8') as fh: with open(branch_file, 'r', encoding='utf-8') as fh:
return u(fh.readline().strip().rsplit('/', 1)[-1]) return u(fh.readline().strip().rsplit('/', 1)[-1])
except UnicodeDecodeError: except UnicodeDecodeError: # pragma: nocover
try: try:
with open(branch_file, 'r', encoding=sys.getfilesystemencoding()) as fh: with open(branch_file, 'r', encoding=sys.getfilesystemencoding()) as fh:
return u(fh.readline().strip().rsplit('/', 1)[-1]) return u(fh.readline().strip().rsplit('/', 1)[-1])
except: except:
log.exception("Exception:") log.exception("Exception:")
except IOError: except IOError: # pragma: nocover
log.exception("Exception:") log.exception("Exception:")
return u('default') return u('default')