Skip to content

Commit

Permalink
add pytest.deprecated_call to expected deprecation warnings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xflr6 committed Nov 28, 2021
1 parent 13ab1d5 commit 99b4e62
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
4 changes: 3 additions & 1 deletion tests/backend/test_piping.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def test_pipe_pipe_invalid_data_mocked(mocker, sentinel, mock_run, quiet):
reason='https://gitlab.com/graphviz/graphviz/-/issues/1269'))])
def test_pipe(capsys, engine, format_, renderer, formatter, pattern,
data=b'graph { spam }'):
out = graphviz.pipe(engine, format_, data, renderer, formatter).decode('ascii')
with pytest.deprecated_call():
out = graphviz.pipe(engine, format_, data,
renderer, formatter).decode('ascii')

if pattern is not None:
assert re.match(pattern, out)
Expand Down
8 changes: 5 additions & 3 deletions tests/backend/test_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_render_missing_file(quiet, engine='dot', format_='pdf'):
(['dot', 'ps', 'nonfilepath', 'ps', ''], ValueError, r'unknown formatter')],
ids=lambda x: getattr(x, '__name__', x))
def test_render_unknown_parameter_raises(args, expected_exception, match):
with pytest.raises(expected_exception, match=match):
with pytest.raises(expected_exception, match=match), pytest.deprecated_call():
graphviz.render(*args)


Expand All @@ -53,7 +53,9 @@ def test_render(capsys, tmp_path, engine, format_, renderer, formatter,
assert lpath.write_bytes(data) == len(data) == lpath.stat().st_size
rendered = lpath.with_suffix(f'{lpath.suffix}.{expected_suffix}')

result = graphviz.render(engine, format_, str(lpath), renderer, formatter)
with pytest.deprecated_call():
result = graphviz.render(engine, format_, str(lpath),
renderer, formatter)

assert result == str(rendered)

Expand Down Expand Up @@ -181,7 +183,7 @@ def test_get_filepath(outfile, expected_fspath):
('spam.pdf', None, 'pdf'),
('spam.pdf', 'pdf', 'pdf'),
('spam', 'pdf', 'pdf')])
def test_get_ormat(outfile_name, format, expected_result):
def test_get_format(outfile_name, format, expected_result):
outfile = pathlib.Path(outfile_name)

result = rendering.get_format(outfile, format=format)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_all_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def test_save_mocked(mocker, dot, filename='nonfilename', directory='nondirector
mock_makedirs = mocker.patch('os.makedirs', autospec=True)
mock_open = mocker.patch('builtins.open', mocker.mock_open())

assert dot.save(filename, directory) == dot.filepath
with pytest.deprecated_call():
assert dot.save(filename, directory) == dot.filepath

assert dot.filename == filename
assert dot.directory == directory
Expand Down
13 changes: 9 additions & 4 deletions tests/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,21 @@ def test_from_file(tmp_path, filename='hello.gv', directory='source_hello',
lpath.mkdir()
(lpath / filename).write_text(data, encoding=encoding)

source = graphviz.Source.from_file(filename, str(lpath))
with pytest.deprecated_call():
source = graphviz.Source.from_file(filename, str(lpath))
assert source.encoding == 'utf-8'

source = graphviz.Source.from_file(filename, str(lpath), encoding=None)
with pytest.deprecated_call():
source = graphviz.Source.from_file(filename, str(lpath), encoding=None)
assert source.encoding == locale.getpreferredencoding()

renderer = 'xdot'
formatter = 'core'
source = graphviz.Source.from_file(filename, str(lpath), encoding=encoding,
renderer=renderer, formatter=formatter)
with pytest.deprecated_call():
source = graphviz.Source.from_file(filename, str(lpath),
encoding=encoding,
renderer=renderer,
formatter=formatter)
assert source.source == data + '\n'
assert source.filename == filename
assert source.directory == str(lpath)
Expand Down

0 comments on commit 99b4e62

Please sign in to comment.