diff options
-rw-r--r-- | pycco/main.py | 8 | ||||
-rw-r--r-- | requirements.test.txt | 3 | ||||
-rw-r--r-- | tests/test_pycco.py | 16 |
3 files changed, 23 insertions, 4 deletions
diff --git a/pycco/main.py b/pycco/main.py index f0d4fcf..6db3a91 100644 --- a/pycco/main.py +++ b/pycco/main.py @@ -521,9 +521,9 @@ def process(sources, preserve_paths=True, outdir=None, language=None, print("pycco: {} -> {}".format(s, dest)) generated_files.append(dest) - except UnicodeDecodeError: + except (ValueError, UnicodeDecodeError) as e: if skip: - print("pycco [FAILURE]: {}".format(s)) + print("pycco [FAILURE]: {}, {}".format(s, e)) else: raise @@ -605,7 +605,9 @@ def main(): parser.add_option('-i', '--generate_index', action='store_true', help='Generate an index.html document with sitemap content') - parser.add_option('-s', '--skip-bad-files', action='store_true', + parser.add_option('-s', '--skip-bad-files', + '-e', '--ignore-errors', + action='store_true', dest='skip_bad_files', help='Continue processing after hitting a bad file') diff --git a/requirements.test.txt b/requirements.test.txt index 5db5948..6c8b8e3 100644 --- a/requirements.test.txt +++ b/requirements.test.txt @@ -1,3 +1,4 @@ hypothesis==1.18.1 -pytest-cov==2.2.0 +pytest-cov~=2.0 coveralls==1.1 +mock~=2.0 diff --git a/tests/test_pycco.py b/tests/test_pycco.py index 6db8265..cae1888 100644 --- a/tests/test_pycco.py +++ b/tests/test_pycco.py @@ -4,6 +4,10 @@ import tempfile import time import os.path import pytest +try: + from unittest.mock import patch +except ImportError: + from mock import patch from hypothesis import given, example, assume from hypothesis.strategies import lists, text, booleans, choices, none @@ -160,6 +164,18 @@ def test_process(preserve_paths, index, choice): language=lang_name) +@patch('pygments.lexers.guess_lexer') +def test_process_skips_unknown_languages(mock_guess_lexer): + class Name: + name = 'this language does not exist' + mock_guess_lexer.return_value = Name() + + with pytest.raises(ValueError): + p.process(['LICENSE'], outdir=tempfile.gettempdir(), skip=False) + + p.process(['LICENSE'], outdir=tempfile.gettempdir(), skip=True) + + @given(lists(lists(text(min_size=1), min_size=1, max_size=30), min_size=1), lists(text(min_size=1), min_size=1)) def test_generate_index(path_lists, outdir_list): file_paths = [os.path.join(*path_list) for path_list in path_lists] |