mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix PT011 (`pytest.raises(ValueError)
` is too broad)
This commit is contained in:
parent
78976662d9
commit
b91d763db8
@ -221,8 +221,6 @@ ignore = [
|
|||||||
"PLR5501", # consider using elif to remove an indentation level
|
"PLR5501", # consider using elif to remove an indentation level
|
||||||
"PLW0603", # using the global statement to update variables is discouraged
|
"PLW0603", # using the global statement to update variables is discouraged
|
||||||
"PLW2901", # outer loop variable overwritten by inner assignment
|
"PLW2901", # outer loop variable overwritten by inner assignment
|
||||||
# flake8-pytest-style
|
|
||||||
"PT011", # `pytest.raises(ValueError)` is too broad, set the `match` parameter
|
|
||||||
# flake8-use-pathlib
|
# flake8-use-pathlib
|
||||||
"PTH",
|
"PTH",
|
||||||
# flake8-quotes
|
# flake8-quotes
|
||||||
|
@ -214,8 +214,8 @@ def parselinenos(spec: str, total: int) -> list[int]:
|
|||||||
items.extend(range(start - 1, end))
|
items.extend(range(start - 1, end))
|
||||||
else:
|
else:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
except Exception as exc:
|
except ValueError as exc:
|
||||||
raise ValueError('invalid line number spec: %r' % spec) from exc
|
raise ValueError(f'invalid line number spec: {spec!r}') from exc
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ def test_html4_error(make_app, tmp_path):
|
|||||||
(tmp_path / 'conf.py').write_text('', encoding='utf-8')
|
(tmp_path / 'conf.py').write_text('', encoding='utf-8')
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
ConfigError,
|
ConfigError,
|
||||||
match=r'HTML 4 is no longer supported by Sphinx',
|
match='HTML 4 is no longer supported by Sphinx',
|
||||||
):
|
):
|
||||||
make_app(
|
make_app(
|
||||||
buildername='html',
|
buildername='html',
|
||||||
|
@ -117,16 +117,16 @@ def test_LiteralIncludeReader_lines_and_lineno_match1(literal_inc_path):
|
|||||||
def test_LiteralIncludeReader_lines_and_lineno_match2(literal_inc_path, app, status, warning):
|
def test_LiteralIncludeReader_lines_and_lineno_match2(literal_inc_path, app, status, warning):
|
||||||
options = {'lines': '0,3,5', 'lineno-match': True}
|
options = {'lines': '0,3,5', 'lineno-match': True}
|
||||||
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
|
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError, match='Cannot use "lineno-match" with a disjoint set of "lines"'):
|
||||||
content, lines = reader.read()
|
reader.read()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx() # init locale for errors
|
@pytest.mark.sphinx() # init locale for errors
|
||||||
def test_LiteralIncludeReader_lines_and_lineno_match3(literal_inc_path, app, status, warning):
|
def test_LiteralIncludeReader_lines_and_lineno_match3(literal_inc_path, app, status, warning):
|
||||||
options = {'lines': '100-', 'lineno-match': True}
|
options = {'lines': '100-', 'lineno-match': True}
|
||||||
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
|
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError, match="Line spec '100-': no lines pulled from include file"):
|
||||||
content, lines = reader.read()
|
reader.read()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
|
@pytest.mark.xfail(os.name != 'posix', reason="Not working on windows")
|
||||||
@ -179,23 +179,23 @@ def test_LiteralIncludeReader_start_at_and_lines(literal_inc_path):
|
|||||||
def test_LiteralIncludeReader_missing_start_and_end(literal_inc_path):
|
def test_LiteralIncludeReader_missing_start_and_end(literal_inc_path):
|
||||||
options = {'start-at': 'NOTHING'}
|
options = {'start-at': 'NOTHING'}
|
||||||
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
|
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError, match='start-at pattern not found: NOTHING'):
|
||||||
content, lines = reader.read()
|
reader.read()
|
||||||
|
|
||||||
options = {'end-at': 'NOTHING'}
|
options = {'end-at': 'NOTHING'}
|
||||||
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
|
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError, match='end-at pattern not found: NOTHING'):
|
||||||
content, lines = reader.read()
|
reader.read()
|
||||||
|
|
||||||
options = {'start-after': 'NOTHING'}
|
options = {'start-after': 'NOTHING'}
|
||||||
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
|
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError, match='start-after pattern not found: NOTHING'):
|
||||||
content, lines = reader.read()
|
reader.read()
|
||||||
|
|
||||||
options = {'end-before': 'NOTHING'}
|
options = {'end-before': 'NOTHING'}
|
||||||
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
|
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError, match='end-before pattern not found: NOTHING'):
|
||||||
content, lines = reader.read()
|
reader.read()
|
||||||
|
|
||||||
|
|
||||||
def test_LiteralIncludeReader_end_before(literal_inc_path):
|
def test_LiteralIncludeReader_end_before(literal_inc_path):
|
||||||
|
@ -63,11 +63,11 @@ def test_parselinenos():
|
|||||||
assert parselinenos('1,7-', 10) == [0, 6, 7, 8, 9]
|
assert parselinenos('1,7-', 10) == [0, 6, 7, 8, 9]
|
||||||
assert parselinenos('7-7', 10) == [6]
|
assert parselinenos('7-7', 10) == [6]
|
||||||
assert parselinenos('11-', 10) == [10]
|
assert parselinenos('11-', 10) == [10]
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError, match="invalid line number spec: '1-2-3'"):
|
||||||
parselinenos('1-2-3', 10)
|
parselinenos('1-2-3', 10)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError, match="invalid line number spec: 'abc-def'"):
|
||||||
parselinenos('abc-def', 10)
|
parselinenos('abc-def', 10)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError, match="invalid line number spec: '-'"):
|
||||||
parselinenos('-', 10)
|
parselinenos('-', 10)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError, match="invalid line number spec: '3-1'"):
|
||||||
parselinenos('3-1', 10)
|
parselinenos('3-1', 10)
|
||||||
|
@ -70,5 +70,5 @@ def test_parse_data_uri():
|
|||||||
# invalid data URI (no properties)
|
# invalid data URI (no properties)
|
||||||
uri = ("data:iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4"
|
uri = ("data:iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4"
|
||||||
"//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==")
|
"//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==")
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError, match=r'not enough values to unpack \(expected 2, got 1\)'):
|
||||||
parse_data_uri(uri)
|
parse_data_uri(uri)
|
||||||
|
@ -127,8 +127,10 @@ def test_signature():
|
|||||||
sig = inspect.stringify_signature(inspect.signature(list))
|
sig = inspect.stringify_signature(inspect.signature(list))
|
||||||
assert sig == '(iterable=(), /)'
|
assert sig == '(iterable=(), /)'
|
||||||
else:
|
else:
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError, match='no signature found for builtin type'):
|
||||||
inspect.signature(list)
|
inspect.signature(list)
|
||||||
|
with pytest.raises(ValueError, match='no signature found for builtin type'):
|
||||||
|
inspect.signature(range)
|
||||||
|
|
||||||
# normal function
|
# normal function
|
||||||
def func(a, b, c=1, d=2, *e, **f):
|
def func(a, b, c=1, d=2, *e, **f):
|
||||||
|
@ -23,6 +23,6 @@ def test_rstdim_to_latexdim():
|
|||||||
assert rstdim_to_latexdim('.5em') == '.5em'
|
assert rstdim_to_latexdim('.5em') == '.5em'
|
||||||
|
|
||||||
# unknown values (it might be generated by 3rd party extension)
|
# unknown values (it might be generated by 3rd party extension)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError, match='could not convert string to float: '):
|
||||||
rstdim_to_latexdim('unknown')
|
rstdim_to_latexdim('unknown')
|
||||||
assert rstdim_to_latexdim('160.0unknown') == '160.0unknown'
|
assert rstdim_to_latexdim('160.0unknown') == '160.0unknown'
|
||||||
|
Loading…
Reference in New Issue
Block a user