summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Smith <subsetpark@gmail.com>2018-05-02 09:37:38 -0400
committerGitHub <noreply@github.com>2018-05-02 09:37:38 -0400
commit9404e8d7cd794e0c2d037a885e49a9c9f6544b37 (patch)
tree7d7840b0eca1d72373ebdc2e5229a599b5526fee
parentfce7f146a3c70e637af86e9fa9856515d3165b8f (diff)
parentc7b01d3aeef3dd0786190d4c5330fcd800b7066e (diff)
downloadpycco-9404e8d7cd794e0c2d037a885e49a9c9f6544b37.tar.gz
Merge pull request #101 from vrde/master
Option --skip-bad-files now skips all kind of bad files
-rw-r--r--pycco/main.py8
-rw-r--r--requirements.test.txt3
-rw-r--r--tests/test_pycco.py16
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]