test C and C++ detection when editing header files
This commit is contained in:
parent
f53044fd23
commit
4c8919f9ac
11 changed files with 49 additions and 17 deletions
0
tests/samples/codefiles/see.c
Normal file
0
tests/samples/codefiles/see.c
Normal file
0
tests/samples/codefiles/see.h
Normal file
0
tests/samples/codefiles/see.h
Normal file
0
tests/samples/codefiles/seeplusplus.cpp
Normal file
0
tests/samples/codefiles/seeplusplus.cpp
Normal file
0
tests/samples/codefiles/seeplusplus.h
Normal file
0
tests/samples/codefiles/seeplusplus.h
Normal file
|
@ -37,7 +37,7 @@ class LanguagesTestCase(utils.TestCase):
|
||||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
now = u(int(time.time()))
|
now = u(int(time.time()))
|
||||||
entity = 'tests/samples/codefile.py'
|
entity = 'tests/samples/codefiles/python.py'
|
||||||
config = 'tests/samples/sample.cfg'
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
args = ['--file', entity, '--config', config, '--time', now]
|
args = ['--file', entity, '--config', config, '--time', now]
|
||||||
|
@ -54,8 +54,8 @@ class LanguagesTestCase(utils.TestCase):
|
||||||
heartbeat = {
|
heartbeat = {
|
||||||
'language': u('Python'),
|
'language': u('Python'),
|
||||||
'lines': 26,
|
'lines': 26,
|
||||||
'entity': os.path.abspath(entity),
|
'entity': os.path.realpath(entity),
|
||||||
'project': u(os.path.basename(os.path.abspath('.'))),
|
'project': u(os.path.basename(os.path.realpath('.'))),
|
||||||
'dependencies': ANY,
|
'dependencies': ANY,
|
||||||
'branch': os.environ.get('TRAVIS_COMMIT', ANY),
|
'branch': os.environ.get('TRAVIS_COMMIT', ANY),
|
||||||
'time': float(now),
|
'time': float(now),
|
||||||
|
@ -76,3 +76,30 @@ class LanguagesTestCase(utils.TestCase):
|
||||||
self.assertIn(dep, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['dependencies'])
|
self.assertIn(dep, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['dependencies'])
|
||||||
self.assertEquals(stats, json.loads(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][1]))
|
self.assertEquals(stats, json.loads(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][1]))
|
||||||
self.patched['wakatime.offlinequeue.Queue.pop'].assert_not_called()
|
self.patched['wakatime.offlinequeue.Queue.pop'].assert_not_called()
|
||||||
|
|
||||||
|
def test_language_detected_for_header_file(self):
|
||||||
|
response = Response()
|
||||||
|
response.status_code = 500
|
||||||
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
|
now = u(int(time.time()))
|
||||||
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
|
entity = 'tests/samples/codefiles/see.h'
|
||||||
|
|
||||||
|
args = ['--file', entity, '--config', config, '--time', now]
|
||||||
|
|
||||||
|
retval = execute(args)
|
||||||
|
self.assertEquals(retval, 102)
|
||||||
|
|
||||||
|
language = u('C')
|
||||||
|
self.assertEqual(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['language'], language)
|
||||||
|
|
||||||
|
entity = 'tests/samples/codefiles/seeplusplus.h'
|
||||||
|
args[1] = entity
|
||||||
|
|
||||||
|
retval = execute(args)
|
||||||
|
self.assertEquals(retval, 102)
|
||||||
|
|
||||||
|
language = u('C++')
|
||||||
|
self.assertEqual(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['language'], language)
|
||||||
|
|
|
@ -47,7 +47,7 @@ class BaseTestCase(utils.TestCase):
|
||||||
response.status_code = 201
|
response.status_code = 201
|
||||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
args = ['--file', 'tests/samples/twolinefile.txt', '--key', '123', '--config', 'tests/samples/sample.cfg']
|
args = ['--file', 'tests/samples/codefiles/twolinefile.txt', '--key', '123', '--config', 'tests/samples/sample.cfg']
|
||||||
|
|
||||||
retval = execute(args)
|
retval = execute(args)
|
||||||
self.assertEquals(retval, 0)
|
self.assertEquals(retval, 0)
|
||||||
|
@ -62,7 +62,7 @@ class BaseTestCase(utils.TestCase):
|
||||||
self.patched['wakatime.offlinequeue.Queue.pop'].assert_called_once_with()
|
self.patched['wakatime.offlinequeue.Queue.pop'].assert_called_once_with()
|
||||||
|
|
||||||
def test_missing_config_file(self):
|
def test_missing_config_file(self):
|
||||||
args = ['--file', 'tests/samples/emptyfile.txt', '--config', 'foo']
|
args = ['--file', 'tests/samples/codefiles/emptyfile.txt', '--config', 'foo']
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(SystemExit):
|
||||||
execute(args)
|
execute(args)
|
||||||
expected_stdout = u("Error: Could not read from config file foo\n")
|
expected_stdout = u("Error: Could not read from config file foo\n")
|
||||||
|
@ -77,7 +77,7 @@ class BaseTestCase(utils.TestCase):
|
||||||
response.status_code = 201
|
response.status_code = 201
|
||||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
args = ['--file', 'tests/samples/emptyfile.txt', '--config', 'tests/samples/sample.cfg']
|
args = ['--file', 'tests/samples/codefiles/emptyfile.txt', '--config', 'tests/samples/sample.cfg']
|
||||||
retval = execute(args)
|
retval = execute(args)
|
||||||
self.assertEquals(retval, 0)
|
self.assertEquals(retval, 0)
|
||||||
self.assertEquals(sys.stdout.getvalue(), '')
|
self.assertEquals(sys.stdout.getvalue(), '')
|
||||||
|
@ -91,7 +91,7 @@ class BaseTestCase(utils.TestCase):
|
||||||
self.patched['wakatime.offlinequeue.Queue.pop'].assert_called_once_with()
|
self.patched['wakatime.offlinequeue.Queue.pop'].assert_called_once_with()
|
||||||
|
|
||||||
def test_bad_config_file(self):
|
def test_bad_config_file(self):
|
||||||
args = ['--file', 'tests/samples/emptyfile.txt', '--config', 'tests/samples/bad_config.cfg']
|
args = ['--file', 'tests/samples/codefiles/emptyfile.txt', '--config', 'tests/samples/bad_config.cfg']
|
||||||
retval = execute(args)
|
retval = execute(args)
|
||||||
self.assertEquals(retval, 103)
|
self.assertEquals(retval, 103)
|
||||||
self.assertIn('ParsingError', sys.stdout.getvalue())
|
self.assertIn('ParsingError', sys.stdout.getvalue())
|
||||||
|
@ -107,7 +107,7 @@ class BaseTestCase(utils.TestCase):
|
||||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
now = u(int(time.time()))
|
now = u(int(time.time()))
|
||||||
entity = 'tests/samples/twolinefile.txt'
|
entity = 'tests/samples/codefiles/twolinefile.txt'
|
||||||
config = 'tests/samples/sample.cfg'
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
args = ['--file', entity, '--key', '123', '--config', config, '--time', now]
|
args = ['--file', entity, '--key', '123', '--config', config, '--time', now]
|
||||||
|
@ -148,7 +148,7 @@ class BaseTestCase(utils.TestCase):
|
||||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
now = u(int(time.time()))
|
now = u(int(time.time()))
|
||||||
entity = 'tests/samples/twolinefile.txt'
|
entity = 'tests/samples/codefiles/twolinefile.txt'
|
||||||
config = 'tests/samples/paranoid.cfg'
|
config = 'tests/samples/paranoid.cfg'
|
||||||
|
|
||||||
args = ['--file', entity, '--key', '123', '--config', config, '--time', now]
|
args = ['--file', entity, '--key', '123', '--config', config, '--time', now]
|
||||||
|
@ -190,7 +190,7 @@ class BaseTestCase(utils.TestCase):
|
||||||
|
|
||||||
now = u(int(time.time()))
|
now = u(int(time.time()))
|
||||||
|
|
||||||
args = ['--file', 'tests/samples/twolinefile.txt', '--key', '123',
|
args = ['--file', 'tests/samples/codefiles/twolinefile.txt', '--key', '123',
|
||||||
'--config', 'tests/samples/paranoid.cfg', '--time', now]
|
'--config', 'tests/samples/paranoid.cfg', '--time', now]
|
||||||
|
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ class BaseTestCase(utils.TestCase):
|
||||||
|
|
||||||
now = u(int(time.time()))
|
now = u(int(time.time()))
|
||||||
|
|
||||||
args = ['--file', 'tests/samples/twolinefile.txt', '--key', '123',
|
args = ['--file', 'tests/samples/codefiles/twolinefile.txt', '--key', '123',
|
||||||
'--config', 'tests/samples/paranoid.cfg', '--time', now]
|
'--config', 'tests/samples/paranoid.cfg', '--time', now]
|
||||||
|
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ class BaseTestCase(utils.TestCase):
|
||||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
now = u(int(time.time()))
|
now = u(int(time.time()))
|
||||||
entity = 'tests/samples/twolinefile.txt'
|
entity = 'tests/samples/codefiles/twolinefile.txt'
|
||||||
config = 'tests/samples/sample.cfg'
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
args = ['--file', entity, '--alternate-project', 'xyz', '--config', config, '--time', now]
|
args = ['--file', entity, '--alternate-project', 'xyz', '--config', config, '--time', now]
|
||||||
|
@ -294,7 +294,7 @@ class BaseTestCase(utils.TestCase):
|
||||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
now = u(int(time.time()))
|
now = u(int(time.time()))
|
||||||
entity = 'tests/samples/twolinefile.txt'
|
entity = 'tests/samples/codefiles/twolinefile.txt'
|
||||||
config = 'tests/samples/sample.cfg'
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
args = ['--file', entity, '--project', 'xyz', '--config', config, '--time', now]
|
args = ['--file', entity, '--project', 'xyz', '--config', config, '--time', now]
|
||||||
|
|
|
@ -27,7 +27,7 @@ class OfflineQueueTestCase(utils.TestCase):
|
||||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
now = u(int(time.time()))
|
now = u(int(time.time()))
|
||||||
entity = 'tests/samples/twolinefile.txt'
|
entity = 'tests/samples/codefiles/twolinefile.txt'
|
||||||
config = 'tests/samples/sample.cfg'
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
args = ['--file', entity, '--config', config, '--time', now]
|
args = ['--file', entity, '--config', config, '--time', now]
|
||||||
|
@ -43,7 +43,7 @@ class OfflineQueueTestCase(utils.TestCase):
|
||||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
now = u(int(time.time()))
|
now = u(int(time.time()))
|
||||||
entity = 'tests/samples/twolinefile.txt'
|
entity = 'tests/samples/codefiles/twolinefile.txt'
|
||||||
config = 'tests/samples/sample.cfg'
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
args = ['--file', entity, '--config', config, '--time', now]
|
args = ['--file', entity, '--config', config, '--time', now]
|
||||||
|
@ -59,7 +59,7 @@ class OfflineQueueTestCase(utils.TestCase):
|
||||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
now = u(int(time.time()))
|
now = u(int(time.time()))
|
||||||
entity = 'tests/samples/twolinefile.txt'
|
entity = 'tests/samples/codefiles/twolinefile.txt'
|
||||||
config = 'tests/samples/sample.cfg'
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
args = ['--file', entity, '--config', config, '--time', now]
|
args = ['--file', entity, '--config', config, '--time', now]
|
||||||
|
|
|
@ -123,7 +123,12 @@ def get_language_from_extension(file_name):
|
||||||
"""Returns a matching language for the given file extension.
|
"""Returns a matching language for the given file extension.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
extension = os.path.splitext(file_name)[1].lower()
|
filepart, extension = os.path.splitext(file_name)
|
||||||
|
|
||||||
|
if os.path.exists(u('{0}{1}').format(u(filepart), u('.c'))) or os.path.exists(u('{0}{1}').format(u(filepart), u('.C'))):
|
||||||
|
return 'C'
|
||||||
|
|
||||||
|
extension = extension.lower()
|
||||||
if extension == '.h':
|
if extension == '.h':
|
||||||
directory = os.path.dirname(file_name)
|
directory = os.path.dirname(file_name)
|
||||||
available_files = os.listdir(directory)
|
available_files = os.listdir(directory)
|
||||||
|
|
Loading…
Reference in a new issue