diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-03-24 11:36:06 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2021-03-24 11:36:06 +0100 |
commit | 27ceb8196db3986c6c6df55152782f644be6f8c2 (patch) | |
tree | b5735c2bde710c62ef5143bd39a4bc9bab1bbefe | |
parent | 816ec60fe4155dbc35e8be333482839ba5a0ba8a (diff) | |
download | qutebrowser-27ceb8196db3986c6c6df55152782f644be6f8c2.tar.gz qutebrowser-27ceb8196db3986c6c6df55152782f644be6f8c2.zip |
Simplify paths in test_jinja, _qtutils and _version
-rw-r--r-- | tests/unit/utils/test_jinja.py | 23 | ||||
-rw-r--r-- | tests/unit/utils/test_qtutils.py | 5 | ||||
-rw-r--r-- | tests/unit/utils/test_version.py | 3 |
3 files changed, 14 insertions, 17 deletions
diff --git a/tests/unit/utils/test_jinja.py b/tests/unit/utils/test_jinja.py index d0c993046..85be8a6e3 100644 --- a/tests/unit/utils/test_jinja.py +++ b/tests/unit/utils/test_jinja.py @@ -33,27 +33,28 @@ from qutebrowser.config import configexc @pytest.fixture(autouse=True) def patch_read_file(monkeypatch): """pytest fixture to patch resources.read_file.""" - def _read_file(path): + def _read_file(filepath): """A read_file which returns a simple template if the path is right.""" - path = pathlib.Path(path) - if path == pathlib.Path('html') / 'test.html': + path = pathlib.Path(filepath) + html_path = pathlib.Path('html') + if path == html_path / 'test.html': return """Hello {{var}}""" - elif path == pathlib.Path('html') / 'test2.html': + elif path == html_path / 'test2.html': return """{{ resource_url('utils/testfile') }}""" - elif path == pathlib.Path('html') / 'test3.html': + elif path == html_path / 'test3.html': return """{{ data_url('testfile.txt') }}""" - elif path == pathlib.Path('html') / 'undef.html': + elif path == html_path / 'undef.html': return """{{ does_not_exist() }}""" - elif path == pathlib.Path('html') / 'attributeerror.html': + elif path == html_path / 'attributeerror.html': return """{{ obj.foobar }}""" else: - raise OSError("Invalid path {}!".format(path)) + raise OSError(f"Invalid path {filepath}!") - def _read_file_binary(path): - if path == 'testfile.txt': + def _read_file_binary(filepath): + if filepath == 'testfile.txt': return b'foo' else: - raise OSError("Invalid path {}!".format(path)) + raise OSError(f"Invalid path {filepath}!") monkeypatch.setattr(jinja.resources, 'read_file', _read_file) monkeypatch.setattr(jinja.resources, 'read_file_binary', _read_file_binary) diff --git a/tests/unit/utils/test_qtutils.py b/tests/unit/utils/test_qtutils.py index 2d98feece..c0832c9fb 100644 --- a/tests/unit/utils/test_qtutils.py +++ b/tests/unit/utils/test_qtutils.py @@ -520,10 +520,7 @@ if test_file is not None: def clean_up_python_testfile(): """Clean up the python testfile after tests if tests didn't.""" yield - try: - pathlib.Path(test_file.TESTFN).unlink() - except FileNotFoundError: - pass + pathlib.Path(test_file.TESTFN).unlink(missing_ok=True) class PyIODeviceTestMixin: diff --git a/tests/unit/utils/test_version.py b/tests/unit/utils/test_version.py index a2d18258f..7cd3504b0 100644 --- a/tests/unit/utils/test_version.py +++ b/tests/unit/utils/test_version.py @@ -304,8 +304,7 @@ except ImportError: def test_distribution(tmp_path, monkeypatch, os_release, expected): os_release_file = tmp_path / 'os-release' if os_release is not None: - (os_release_file.write_text( - textwrap.dedent(os_release), encoding="utf-8")) + os_release_file.write_text(textwrap.dedent(os_release), encoding="utf-8") monkeypatch.setenv('QUTE_FAKE_OS_RELEASE', str(os_release_file)) assert version.distribution() == expected |