2015-08-12 22:03:39 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
2015-08-29 23:16:14 +00:00
|
|
|
from wakatime.main import execute
|
2015-08-12 22:03:39 +00:00
|
|
|
from wakatime.packages import requests
|
|
|
|
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import sys
|
|
|
|
from wakatime.compat import u
|
|
|
|
from wakatime.packages.requests.models import Response
|
|
|
|
from . import utils
|
|
|
|
|
2015-08-30 00:48:42 +00:00
|
|
|
try:
|
|
|
|
from .packages import simplejson as json
|
|
|
|
except (ImportError, SyntaxError):
|
|
|
|
import json
|
2015-08-12 22:03:39 +00:00
|
|
|
try:
|
|
|
|
from mock import ANY
|
|
|
|
except ImportError:
|
|
|
|
from unittest.mock import ANY
|
|
|
|
|
|
|
|
|
|
|
|
class LanguagesTestCase(utils.TestCase):
|
|
|
|
patch_these = [
|
|
|
|
'wakatime.packages.requests.adapters.HTTPAdapter.send',
|
|
|
|
'wakatime.offlinequeue.Queue.push',
|
|
|
|
['wakatime.offlinequeue.Queue.pop', None],
|
|
|
|
'wakatime.session_cache.SessionCache.save',
|
|
|
|
'wakatime.session_cache.SessionCache.delete',
|
|
|
|
['wakatime.session_cache.SessionCache.get', requests.session],
|
|
|
|
]
|
|
|
|
|
|
|
|
def test_python_dependencies_detected(self):
|
|
|
|
response = Response()
|
|
|
|
response.status_code = 0
|
|
|
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
|
|
|
|
|
|
|
now = u(int(time.time()))
|
|
|
|
entity = 'tests/samples/codefile.py'
|
|
|
|
config = 'tests/samples/sample.cfg'
|
|
|
|
|
|
|
|
args = ['--file', entity, '--config', config, '--time', now]
|
|
|
|
|
2015-08-29 23:16:14 +00:00
|
|
|
retval = execute(args)
|
2015-08-12 22:03:39 +00:00
|
|
|
self.assertEquals(retval, 102)
|
|
|
|
self.assertEquals(sys.stdout.getvalue(), '')
|
|
|
|
self.assertEquals(sys.stderr.getvalue(), '')
|
|
|
|
|
|
|
|
self.patched['wakatime.session_cache.SessionCache.get'].assert_called_once_with()
|
|
|
|
self.patched['wakatime.session_cache.SessionCache.delete'].assert_called_once_with()
|
|
|
|
self.patched['wakatime.session_cache.SessionCache.save'].assert_not_called()
|
|
|
|
|
|
|
|
heartbeat = {
|
2015-08-29 23:16:14 +00:00
|
|
|
'language': u('Python'),
|
2015-08-12 22:03:39 +00:00
|
|
|
'lines': 26,
|
|
|
|
'entity': os.path.abspath(entity),
|
2015-08-29 23:16:14 +00:00
|
|
|
'project': u(os.path.basename(os.path.abspath('.'))),
|
|
|
|
'dependencies': ANY,
|
2015-08-12 22:03:39 +00:00
|
|
|
'branch': os.environ.get('TRAVIS_COMMIT', ANY),
|
|
|
|
'time': float(now),
|
|
|
|
'type': 'file',
|
|
|
|
}
|
2015-08-30 00:48:42 +00:00
|
|
|
stats = {
|
|
|
|
u('cursorpos'): None,
|
|
|
|
u('dependencies'): ANY,
|
|
|
|
u('language'): u('Python'),
|
|
|
|
u('lineno'): None,
|
|
|
|
u('lines'): 26,
|
|
|
|
}
|
|
|
|
expected_dependencies = ['wakatime', 'mock', 'django', 'simplejson', 'os']
|
2015-08-29 23:16:14 +00:00
|
|
|
expected_dependencies = ['wakatime', 'mock', 'django', 'simplejson', 'os']
|
2015-08-12 22:03:39 +00:00
|
|
|
|
2015-08-30 00:48:42 +00:00
|
|
|
self.patched['wakatime.offlinequeue.Queue.push'].assert_called_once_with(heartbeat, ANY, None)
|
2015-08-29 23:16:14 +00:00
|
|
|
for dep in expected_dependencies:
|
|
|
|
self.assertIn(dep, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['dependencies'])
|
2015-08-30 00:48:42 +00:00
|
|
|
self.assertEquals(stats, json.loads(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][1]))
|
2015-08-12 22:03:39 +00:00
|
|
|
self.patched['wakatime.offlinequeue.Queue.pop'].assert_not_called()
|