summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.coveragerc33
-rw-r--r--.pre-commit-config.yaml12
-rw-r--r--cfgv.py9
-rw-r--r--requirements-dev.txt2
-rw-r--r--setup.cfg5
-rw-r--r--tests/cfgv_test.py10
-rw-r--r--tox.ini1
7 files changed, 27 insertions, 45 deletions
diff --git a/.coveragerc b/.coveragerc
deleted file mode 100644
index 0bada6e..0000000
--- a/.coveragerc
+++ /dev/null
@@ -1,33 +0,0 @@
-[run]
-branch = True
-source =
- .
-omit =
- .tox/*
- /usr/*
- setup.py
- # Don't complain if non-runnable code isn't run
- */__main__.py
-
-[report]
-show_missing = True
-skip_covered = True
-exclude_lines =
- # Have to re-enable the standard pragma
- \#\s*pragma: no cover
- # We optionally substitute this
- ${COVERAGE_IGNORE_WINDOWS}
-
- # Don't complain if tests don't hit defensive assertion code:
- ^\s*raise AssertionError\b
- ^\s*raise NotImplementedError\b
- ^\s*return NotImplemented\b
- ^\s*raise$
-
- # Don't complain if non-runnable code isn't run:
- ^if __name__ == ['"]__main__['"]:$
-
-[html]
-directory = coverage-html
-
-# vim:ft=dosini
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 948de77..cdc0d1c 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -10,29 +10,29 @@ repos:
- id: name-tests-test
- id: requirements-txt-fixer
- repo: https://gitlab.com/pycqa/flake8
- rev: 3.7.9
+ rev: 3.8.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-autopep8
- rev: v1.5
+ rev: v1.5.2
hooks:
- id: autopep8
- repo: https://github.com/asottile/reorder_python_imports
- rev: v1.9.0
+ rev: v2.3.0
hooks:
- id: reorder-python-imports
args: [--py3-plus]
- repo: https://github.com/asottile/pyupgrade
- rev: v1.26.2
+ rev: v2.4.1
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: https://github.com/asottile/add-trailing-comma
- rev: v1.5.0
+ rev: v2.0.1
hooks:
- id: add-trailing-comma
args: [--py36-plus]
- repo: https://github.com/asottile/setup-cfg-fmt
- rev: v1.6.0
+ rev: v1.9.0
hooks:
- id: setup-cfg-fmt
diff --git a/cfgv.py b/cfgv.py
index 64c2380..f0b9eff 100644
--- a/cfgv.py
+++ b/cfgv.py
@@ -395,11 +395,14 @@ def load_from_filename(
if not os.path.exists(filename):
raise ValidationError(f'{filename} does not exist')
- with open(filename, encoding='utf-8') as f:
- contents = f.read()
-
with validate_context(f'File {filename}'):
try:
+ with open(filename, encoding='utf-8') as f:
+ contents = f.read()
+ except UnicodeDecodeError as e:
+ raise ValidationError(str(e))
+
+ try:
data = load_strategy(contents)
except Exception as e:
raise ValidationError(str(e))
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 4dbfffa..0c5a37e 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -1,3 +1,3 @@
+covdefaults
coverage
-pre-commit
pytest
diff --git a/setup.cfg b/setup.cfg
index ce6e897..cef13f1 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = cfgv
-version = 3.1.0
+version = 3.2.0
description = Validate configuration and produce human readable error messages.
long_description = file: README.md
long_description_content_type = text/markdown
@@ -25,3 +25,6 @@ python_requires = >=3.6.1
[bdist_wheel]
universal = True
+
+[coverage:run]
+plugins = covdefaults
diff --git a/tests/cfgv_test.py b/tests/cfgv_test.py
index 1b143a6..7320e4c 100644
--- a/tests/cfgv_test.py
+++ b/tests/cfgv_test.py
@@ -532,6 +532,16 @@ def test_load_from_filename_file_does_not_exist():
assert excinfo.value.args[0].error_msg == 'does_not_exist does not exist'
+def test_load_from_filename_unicode_error(tmp_path):
+ f = tmp_path.joinpath('f')
+ f.write_bytes(b'\x98\xae\xfe')
+
+ with pytest.raises(Error) as excinfo:
+ load_from_filename(f, map_required, json.loads, Error)
+ expected = (f'File {f}', mock.ANY)
+ _assert_exception_trace(excinfo.value.args[0], expected)
+
+
def test_load_from_filename_fails_load_strategy(tmpdir):
f = tmpdir.join('foo.notjson')
f.write('totes not json')
diff --git a/tox.ini b/tox.ini
index 3b6f4d7..3420602 100644
--- a/tox.ini
+++ b/tox.ini
@@ -7,7 +7,6 @@ commands =
coverage erase
coverage run -m pytest {posargs:tests}
coverage report --fail-under 100
- pre-commit install
[testenv:pre-commit]
skip_install = true