diff options
author | Zach Smith <zd@zdsmith.com> | 2018-05-02 09:44:51 -0400 |
---|---|---|
committer | Zach Smith <zd@zdsmith.com> | 2018-05-02 09:44:51 -0400 |
commit | 8377314cd8024f2e0c1584eba79a57db1f488eb1 (patch) | |
tree | 60e87068c8bf24965459c89eadc73604a7ab558e | |
parent | 57d0aaa4cff222ccd20b7d6f78f96ac6bb2225c0 (diff) | |
parent | 9404e8d7cd794e0c2d037a885e49a9c9f6544b37 (diff) | |
download | pycco-8377314cd8024f2e0c1584eba79a57db1f488eb1.tar.gz |
Merge branch 'master' into minor-fixesminor-fixes
-rw-r--r-- | pycco/main.py | 7 | ||||
-rw-r--r-- | requirements.test.txt | 5 | ||||
-rw-r--r-- | tests/test_pycco.py | 28 |
3 files changed, 31 insertions, 9 deletions
diff --git a/pycco/main.py b/pycco/main.py index 3e3c174..5bbb7c4 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 @@ -612,7 +612,8 @@ def main(): parser.add_argument('-i', '--generate_index', action='store_true', help='Generate an index.html document with sitemap content') - parser.add_argument('-s', '--skip-bad-files', action='store_true', + parser.add_argument('-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 f8e9871..3ba721c 100644 --- a/requirements.test.txt +++ b/requirements.test.txt @@ -1,3 +1,4 @@ -hypothesis==3.56.5 -pytest-cov==2.5.1 coveralls==1.3.0 +hypothesis==3.56.5 +mock~=2.0 +pytest-cov~=2.0 diff --git a/tests/test_pycco.py b/tests/test_pycco.py index 53fa74f..845bfe8 100644 --- a/tests/test_pycco.py +++ b/tests/test_pycco.py @@ -1,16 +1,24 @@ from __future__ import absolute_import + import copy import os +import os.path import tempfile import time -import os.path + import pytest -from hypothesis import given, example -from hypothesis.strategies import lists, text, booleans, choices, none import pycco.generate_index as generate_index -from pycco.languages import supported_languages import pycco.main as p +from hypothesis import assume, example, given +from hypothesis.strategies import booleans, choices, lists, none, text +from pycco.languages import supported_languages + +try: + from unittest.mock import patch +except ImportError: + from mock import patch + PYTHON = supported_languages['.py'] @@ -164,6 +172,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) + + one_or_more_chars = text(min_size=1, max_size=255) paths = lists(one_or_more_chars, min_size=1, max_size=30) @given( |