imporove debug warning message from unsupported dependency parser
This commit is contained in:
parent
a69f81c0c8
commit
92d8960250
3 changed files with 59 additions and 10 deletions
|
@ -85,7 +85,60 @@ class DependenciesTestCase(utils.TestCase):
|
|||
expected = []
|
||||
self.assertEquals(dependencies, expected)
|
||||
|
||||
def test_io_error_when_parsing_dependencies(self):
|
||||
@log_capture()
|
||||
def test_missing_dependency_parser_in_debug_mode(self, logs):
|
||||
logging.disable(logging.NOTSET)
|
||||
|
||||
# turn on debug mode
|
||||
log = logging.getLogger('WakaTime')
|
||||
log.setLevel(logging.DEBUG)
|
||||
|
||||
lexer = PythonLexer
|
||||
lexer.__class__.__name__ = 'FooClass'
|
||||
parser = DependencyParser(None, lexer)
|
||||
|
||||
# parse dependencies
|
||||
dependencies = parser.parse()
|
||||
|
||||
log_output = u("\n").join([u(' ').join(x) for x in logs.actual()])
|
||||
expected = 'WakaTime DEBUG Parsing dependencies not supported for python.FooClass'
|
||||
self.assertEquals(log_output, expected)
|
||||
|
||||
self.assertEquals(sys.stdout.getvalue(), '')
|
||||
self.assertEquals(sys.stderr.getvalue(), '')
|
||||
|
||||
expected = []
|
||||
self.assertEquals(dependencies, expected)
|
||||
|
||||
@log_capture()
|
||||
def test_missing_dependency_parser_importerror_in_debug_mode(self, logs):
|
||||
logging.disable(logging.NOTSET)
|
||||
|
||||
# turn on debug mode
|
||||
log = logging.getLogger('WakaTime')
|
||||
log.setLevel(logging.DEBUG)
|
||||
|
||||
with utils.mock.patch('wakatime.dependencies.import_module') as mock_import:
|
||||
mock_import.side_effect = ImportError('foo')
|
||||
|
||||
lexer = PythonLexer
|
||||
lexer.__class__.__name__ = 'FooClass'
|
||||
parser = DependencyParser(None, lexer)
|
||||
|
||||
# parse dependencies
|
||||
dependencies = parser.parse()
|
||||
|
||||
log_output = u("\n").join([u(' ').join(x) for x in logs.actual()])
|
||||
expected = 'WakaTime DEBUG Parsing dependencies not supported for python.FooClass'
|
||||
self.assertEquals(log_output, expected)
|
||||
|
||||
self.assertEquals(sys.stdout.getvalue(), '')
|
||||
self.assertEquals(sys.stderr.getvalue(), '')
|
||||
|
||||
expected = []
|
||||
self.assertEquals(dependencies, expected)
|
||||
|
||||
def test_io_error_suppressed_when_parsing_dependencies(self):
|
||||
response = Response()
|
||||
response.status_code = 0
|
||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||
|
@ -137,11 +190,11 @@ class DependenciesTestCase(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_classnotfound_error_when_passing_none_to_pygments(self):
|
||||
def test_classnotfound_error_raised_when_passing_none_to_pygments(self):
|
||||
with self.assertRaises(ClassNotFound):
|
||||
get_lexer_by_name(None)
|
||||
|
||||
def test_classnotfound_error_when_parsing_dependencies(self):
|
||||
def test_classnotfound_error_suppressed_when_parsing_dependencies(self):
|
||||
response = Response()
|
||||
response.status_code = 0
|
||||
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||
|
|
|
@ -577,14 +577,10 @@ class MainTestCase(utils.TestCase):
|
|||
self.assertEquals(sys.stderr.getvalue(), '')
|
||||
|
||||
log_output = u("\n").join([u(' ').join(x) for x in logs.actual()])
|
||||
expected = 'ImportError: No module named special'
|
||||
if is_py3:
|
||||
expected = "ImportError: No module named 'wakatime.dependencies.special'"
|
||||
expected = 'Parsing dependencies not supported for special.TextParser'
|
||||
self.assertIn(expected, log_output)
|
||||
expected = 'WakaTime DEBUG Sending heartbeat to api at https://api.wakatime.com/api/v1/heartbeats'
|
||||
self.assertIn(expected, log_output)
|
||||
expected = 'WakaTime DEBUG Traceback'
|
||||
self.assertIn(expected, log_output)
|
||||
expected = "RequestException': u'requests exception'"
|
||||
if is_py3:
|
||||
expected = "RequestException': 'requests exception'"
|
||||
|
|
|
@ -117,9 +117,9 @@ class DependencyParser(object):
|
|||
try:
|
||||
self.parser = getattr(module, class_name)
|
||||
except AttributeError:
|
||||
log.debug('Module {0} is missing class {1}'.format(module.__name__, class_name))
|
||||
log.debug('Parsing dependencies not supported for {0}.{1}'.format(module_name, class_name))
|
||||
except ImportError:
|
||||
log.traceback(logging.DEBUG)
|
||||
log.debug('Parsing dependencies not supported for {0}.{1}'.format(module_name, class_name))
|
||||
|
||||
def parse(self):
|
||||
if self.parser:
|
||||
|
|
Loading…
Reference in a new issue