1
0
Fork 0

Merging upstream version 3.2.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 20:40:38 +01:00
parent b0222c2f7f
commit 1f96436375
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
7 changed files with 27 additions and 45 deletions

View file

@ -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

View file

@ -10,29 +10,29 @@ repos:
- id: name-tests-test - id: name-tests-test
- id: requirements-txt-fixer - id: requirements-txt-fixer
- repo: https://gitlab.com/pycqa/flake8 - repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9 rev: 3.8.0
hooks: hooks:
- id: flake8 - id: flake8
- repo: https://github.com/pre-commit/mirrors-autopep8 - repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5 rev: v1.5.2
hooks: hooks:
- id: autopep8 - id: autopep8
- repo: https://github.com/asottile/reorder_python_imports - repo: https://github.com/asottile/reorder_python_imports
rev: v1.9.0 rev: v2.3.0
hooks: hooks:
- id: reorder-python-imports - id: reorder-python-imports
args: [--py3-plus] args: [--py3-plus]
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/asottile/pyupgrade
rev: v1.26.2 rev: v2.4.1
hooks: hooks:
- id: pyupgrade - id: pyupgrade
args: [--py36-plus] args: [--py36-plus]
- repo: https://github.com/asottile/add-trailing-comma - repo: https://github.com/asottile/add-trailing-comma
rev: v1.5.0 rev: v2.0.1
hooks: hooks:
- id: add-trailing-comma - id: add-trailing-comma
args: [--py36-plus] args: [--py36-plus]
- repo: https://github.com/asottile/setup-cfg-fmt - repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.6.0 rev: v1.9.0
hooks: hooks:
- id: setup-cfg-fmt - id: setup-cfg-fmt

View file

@ -395,10 +395,13 @@ def load_from_filename(
if not os.path.exists(filename): if not os.path.exists(filename):
raise ValidationError(f'{filename} does not exist') raise ValidationError(f'{filename} does not exist')
with open(filename, encoding='utf-8') as f:
contents = f.read()
with validate_context(f'File {filename}'): 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: try:
data = load_strategy(contents) data = load_strategy(contents)
except Exception as e: except Exception as e:

View file

@ -1,3 +1,3 @@
covdefaults
coverage coverage
pre-commit
pytest pytest

View file

@ -1,6 +1,6 @@
[metadata] [metadata]
name = cfgv name = cfgv
version = 3.1.0 version = 3.2.0
description = Validate configuration and produce human readable error messages. description = Validate configuration and produce human readable error messages.
long_description = file: README.md long_description = file: README.md
long_description_content_type = text/markdown long_description_content_type = text/markdown
@ -25,3 +25,6 @@ python_requires = >=3.6.1
[bdist_wheel] [bdist_wheel]
universal = True universal = True
[coverage:run]
plugins = covdefaults

View file

@ -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' 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): def test_load_from_filename_fails_load_strategy(tmpdir):
f = tmpdir.join('foo.notjson') f = tmpdir.join('foo.notjson')
f.write('totes not json') f.write('totes not json')

View file

@ -7,7 +7,6 @@ commands =
coverage erase coverage erase
coverage run -m pytest {posargs:tests} coverage run -m pytest {posargs:tests}
coverage report --fail-under 100 coverage report --fail-under 100
pre-commit install
[testenv:pre-commit] [testenv:pre-commit]
skip_install = true skip_install = true