only read one line of extra heartbeats from stdin
This commit is contained in:
parent
208477cc0c
commit
937350220e
7 changed files with 166 additions and 143 deletions
|
@ -157,3 +157,44 @@ class LanguagesTestCase(utils.TestCase):
|
|||
|
||||
language = u('Java')
|
||||
self.assertEqual(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0].get('language'), language)
|
||||
|
||||
def test_alternate_language_not_used_when_invalid(self):
|
||||
response = Response()
|
||||
response.status_code = 500
|
||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||
|
||||
with utils.mock.patch('wakatime.stats.smart_guess_lexer') as mock_guess_lexer:
|
||||
mock_guess_lexer.return_value = None
|
||||
|
||||
now = u(int(time.time()))
|
||||
config = 'tests/samples/configs/good_config.cfg'
|
||||
entity = 'tests/samples/codefiles/python.py'
|
||||
args = ['--file', entity, '--config', config, '--time', now, '--alternate-language', 'foo', '--plugin', 'NeoVim/703 vim-wakatime/4.0.9']
|
||||
|
||||
retval = execute(args)
|
||||
self.assertEquals(retval, 102)
|
||||
|
||||
language = None
|
||||
self.assertEqual(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0].get('language'), language)
|
||||
|
||||
def test_error_reading_alternate_language_json_map_file(self):
|
||||
response = Response()
|
||||
response.status_code = 500
|
||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||
|
||||
with utils.mock.patch('wakatime.stats.smart_guess_lexer') as mock_guess_lexer:
|
||||
mock_guess_lexer.return_value = None
|
||||
|
||||
with utils.mock.patch('wakatime.stats.open') as mock_open:
|
||||
mock_open.side_effect = IOError('')
|
||||
|
||||
now = u(int(time.time()))
|
||||
config = 'tests/samples/configs/good_config.cfg'
|
||||
entity = 'tests/samples/codefiles/python.py'
|
||||
args = ['--file', entity, '--config', config, '--time', now, '--alternate-language', 'foo', '--plugin', 'NeoVim/703 vim-wakatime/4.0.9']
|
||||
|
||||
retval = execute(args)
|
||||
self.assertEquals(retval, 102)
|
||||
|
||||
language = None
|
||||
self.assertEqual(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0].get('language'), language)
|
||||
|
|
|
@ -368,88 +368,6 @@ class BaseTestCase(utils.TestCase):
|
|||
self.assertEquals(stats, json.loads(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][1]))
|
||||
self.patched['wakatime.offlinequeue.Queue.pop'].assert_not_called()
|
||||
|
||||
def test_alternate_project(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/codefiles/twolinefile.txt'
|
||||
config = 'tests/samples/configs/good_config.cfg'
|
||||
|
||||
args = ['--file', entity, '--alternate-project', 'xyz', '--config', config, '--time', now]
|
||||
|
||||
retval = execute(args)
|
||||
self.assertEquals(retval, API_ERROR)
|
||||
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 = {
|
||||
'language': 'Text only',
|
||||
'lines': 2,
|
||||
'entity': os.path.abspath(entity),
|
||||
'project': os.path.basename(os.path.abspath('.')),
|
||||
'branch': os.environ.get('TRAVIS_COMMIT', ANY),
|
||||
'time': float(now),
|
||||
'type': 'file',
|
||||
}
|
||||
stats = {
|
||||
u('cursorpos'): None,
|
||||
u('dependencies'): [],
|
||||
u('language'): u('Text only'),
|
||||
u('lineno'): None,
|
||||
u('lines'): 2,
|
||||
}
|
||||
|
||||
self.patched['wakatime.offlinequeue.Queue.push'].assert_called_once_with(heartbeat, ANY, None)
|
||||
self.assertEquals(stats, json.loads(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][1]))
|
||||
self.patched['wakatime.offlinequeue.Queue.pop'].assert_not_called()
|
||||
|
||||
def test_set_project_from_command_line(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/codefiles/twolinefile.txt'
|
||||
config = 'tests/samples/configs/good_config.cfg'
|
||||
|
||||
args = ['--file', entity, '--project', 'xyz', '--config', config, '--time', now]
|
||||
|
||||
retval = execute(args)
|
||||
self.assertEquals(retval, API_ERROR)
|
||||
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 = {
|
||||
'language': 'Text only',
|
||||
'lines': 2,
|
||||
'entity': os.path.abspath(entity),
|
||||
'project': 'xyz',
|
||||
'branch': os.environ.get('TRAVIS_COMMIT', ANY),
|
||||
'time': float(now),
|
||||
'type': 'file',
|
||||
}
|
||||
stats = {
|
||||
u('cursorpos'): None,
|
||||
u('dependencies'): [],
|
||||
u('language'): u('Text only'),
|
||||
u('lineno'): None,
|
||||
u('lines'): 2,
|
||||
}
|
||||
|
||||
self.patched['wakatime.offlinequeue.Queue.push'].assert_called_once_with(heartbeat, ANY, None)
|
||||
self.assertEquals(stats, json.loads(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][1]))
|
||||
self.patched['wakatime.offlinequeue.Queue.pop'].assert_not_called()
|
||||
|
||||
def test_missing_entity_file(self):
|
||||
response = Response()
|
||||
response.status_code = 201
|
||||
|
@ -468,7 +386,7 @@ class BaseTestCase(utils.TestCase):
|
|||
self.patched['wakatime.session_cache.SessionCache.save'].assert_not_called()
|
||||
|
||||
self.patched['wakatime.offlinequeue.Queue.push'].assert_not_called()
|
||||
self.patched['wakatime.offlinequeue.Queue.pop'].assert_not_called()
|
||||
self.patched['wakatime.offlinequeue.Queue.pop'].assert_called_once_with()
|
||||
|
||||
def test_proxy_argument(self):
|
||||
response = Response()
|
||||
|
@ -653,19 +571,23 @@ class BaseTestCase(utils.TestCase):
|
|||
response.status_code = 201
|
||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||
|
||||
entity = 'tests/samples/codefiles/emptyfile.txt'
|
||||
project1 = os.path.basename(os.path.abspath('.'))
|
||||
project2 = 'xyz'
|
||||
entity1 = os.path.abspath('tests/samples/codefiles/emptyfile.txt')
|
||||
entity2 = os.path.abspath('tests/samples/codefiles/twolinefile.txt')
|
||||
config = 'tests/samples/configs/good_config.cfg'
|
||||
args = ['--file', entity, '--config', config, '--extra-heartbeats']
|
||||
args = ['--file', entity1, '--config', config, '--extra-heartbeats']
|
||||
|
||||
with utils.mock.patch('wakatime.main.sys.stdin') as mock_stdin:
|
||||
now = int(time.time())
|
||||
heartbeats = json.dumps([{
|
||||
'timestamp': now,
|
||||
'entity': entity,
|
||||
'entity': entity2,
|
||||
'entity_type': 'file',
|
||||
'project': project2,
|
||||
'is_write': True,
|
||||
}])
|
||||
mock_stdin.read.return_value = heartbeats
|
||||
mock_stdin.readline.return_value = heartbeats
|
||||
|
||||
retval = execute(args)
|
||||
|
||||
|
@ -678,4 +600,16 @@ class BaseTestCase(utils.TestCase):
|
|||
self.patched['wakatime.session_cache.SessionCache.save'].assert_has_calls([call(ANY), call(ANY)])
|
||||
|
||||
self.patched['wakatime.offlinequeue.Queue.push'].assert_not_called()
|
||||
self.patched['wakatime.offlinequeue.Queue.pop'].assert_has_calls([call(), call()])
|
||||
self.patched['wakatime.offlinequeue.Queue.pop'].assert_called_once_with()
|
||||
|
||||
calls = self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].call_args_list
|
||||
|
||||
body = calls[0][0][0].body
|
||||
data = json.loads(body)
|
||||
self.assertEquals(data.get('entity'), entity1)
|
||||
self.assertEquals(data.get('project'), project1)
|
||||
|
||||
body = calls[1][0][0].body
|
||||
data = json.loads(body)
|
||||
self.assertEquals(data.get('entity'), entity2)
|
||||
self.assertEquals(data.get('project'), project2)
|
||||
|
|
|
@ -55,6 +55,60 @@ class LanguagesTestCase(utils.TestCase):
|
|||
|
||||
self.assertEquals('forced-project', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
|
||||
|
||||
def test_alternate_project_argument_does_not_override_detected_project(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/projects/git/emptyfile.txt'
|
||||
config = 'tests/samples/configs/good_config.cfg'
|
||||
project = os.path.basename(os.path.abspath('.'))
|
||||
|
||||
args = ['--alternate-project', 'alt-project', '--file', entity, '--config', config, '--time', now]
|
||||
|
||||
execute(args)
|
||||
|
||||
self.assertEquals(project, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
|
||||
|
||||
def test_alternate_project_argument_does_not_override_project_argument(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/projects/git/emptyfile.txt'
|
||||
config = 'tests/samples/configs/good_config.cfg'
|
||||
|
||||
args = ['--project', 'forced-project', '--alternate-project', 'alt-project', '--file', entity, '--config', config, '--time', now]
|
||||
|
||||
execute(args)
|
||||
|
||||
self.assertEquals('forced-project', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
|
||||
|
||||
def test_alternate_project_argument_used_when_project_not_detected(self):
|
||||
response = Response()
|
||||
response.status_code = 0
|
||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||
|
||||
tempdir = tempfile.mkdtemp()
|
||||
entity = 'tests/samples/projects/git/emptyfile.txt'
|
||||
shutil.copy(entity, os.path.join(tempdir, 'emptyfile.txt'))
|
||||
|
||||
now = u(int(time.time()))
|
||||
entity = os.path.join(tempdir, 'emptyfile.txt')
|
||||
config = 'tests/samples/configs/good_config.cfg'
|
||||
|
||||
args = ['--file', entity, '--config', config, '--time', now]
|
||||
execute(args)
|
||||
|
||||
args = ['--file', entity, '--config', config, '--time', now, '--alternate-project', 'alt-project']
|
||||
execute(args)
|
||||
|
||||
calls = self.patched['wakatime.offlinequeue.Queue.push'].call_args_list
|
||||
self.assertEquals(None, calls[0][0][0].get('project'))
|
||||
self.assertEquals('alt-project', calls[1][0][0]['project'])
|
||||
|
||||
def test_wakatime_project_file(self):
|
||||
response = Response()
|
||||
response.status_code = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue