tests for TokenParser

This commit is contained in:
Alan Hamlett 2015-09-26 12:10:05 -07:00
parent 41d3419a99
commit fc203d3991
3 changed files with 28 additions and 1 deletions

View file

@ -6,6 +6,8 @@ from wakatime.packages import requests
import time import time
from wakatime.compat import u from wakatime.compat import u
from wakatime.exceptions import NotYetImplemented
from wakatime.languages import TokenParser
from wakatime.packages.requests.models import Response from wakatime.packages.requests.models import Response
from . import utils from . import utils
@ -20,6 +22,16 @@ class LanguagesTestCase(utils.TestCase):
['wakatime.session_cache.SessionCache.get', requests.session], ['wakatime.session_cache.SessionCache.get', requests.session],
] ]
def test_token_parser(self):
with utils.mock.patch('wakatime.languages.TokenParser._extract_tokens') as mock_extract_tokens:
with self.assertRaises(NotYetImplemented):
source_file = 'tests/samples/codefiles/see.h'
parser = TokenParser(source_file)
parser.parse()
mock_extract_tokens.assert_called_once_with()
def test_language_detected_for_header_file(self): def test_language_detected_for_header_file(self):
response = Response() response = Response()
response.status_code = 500 response.status_code = 500

14
wakatime/exceptions.py Normal file
View file

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
"""
wakatime.exceptions
~~~~~~~~~~~~~~~~~~~
Custom exceptions.
:copyright: (c) 2015 Alan Hamlett.
:license: BSD, see LICENSE for more details.
"""
class NotYetImplemented(Exception):
"""This method needs to be implemented."""

View file

@ -15,6 +15,7 @@ import sys
import traceback import traceback
from ..compat import u, open, import_module from ..compat import u, open, import_module
from ..exceptions import NotYetImplemented
log = logging.getLogger('WakaTime') log = logging.getLogger('WakaTime')
@ -39,7 +40,7 @@ class TokenParser(object):
""" """
if not tokens and not self.tokens: if not tokens and not self.tokens:
self.tokens = self._extract_tokens() self.tokens = self._extract_tokens()
raise Exception('Not yet implemented.') raise NotYetImplemented()
def append(self, dep, truncate=False, separator=None, truncate_to=None, def append(self, dep, truncate=False, separator=None, truncate_to=None,
strip_whitespace=True): strip_whitespace=True):