From 41ac85cd6b68a0e6b1a53e79ae497e315008f12a Mon Sep 17 00:00:00 2001 From: vrde Date: Wed, 18 Apr 2018 14:48:23 +0200 Subject: Option --skip-bad-files now skips all kind of bad files --- pycco/main.py | 4 ++-- tests/test_pycco.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pycco/main.py b/pycco/main.py index f0d4fcf..492058b 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 diff --git a/tests/test_pycco.py b/tests/test_pycco.py index 6db8265..1be2683 100644 --- a/tests/test_pycco.py +++ b/tests/test_pycco.py @@ -4,6 +4,7 @@ import tempfile import time import os.path import pytest +from unittest.mock import patch from hypothesis import given, example, assume from hypothesis.strategies import lists, text, booleans, choices, none @@ -160,6 +161,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] -- cgit v1.2.1