diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-03-12 22:07:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-12 22:07:58 +0100 |
commit | 3e25d1ced2ef87c3aa917bc97f7c0be61a95ebb8 (patch) | |
tree | 4037e343e78eb3922e35c73cfd8408384497808e | |
parent | 3c7f9245e5a2b8f0bd80c39272efa469109429db (diff) | |
parent | 4ea73a83e98bf21a0adb54874b54eb6ee1c734e4 (diff) | |
download | qutebrowser-3e25d1ced2ef87c3aa917bc97f7c0be61a95ebb8.tar.gz qutebrowser-3e25d1ced2ef87c3aa917bc97f7c0be61a95ebb8.zip |
Merge pull request #6251 from Lembrun/pathlib-/unit/config
Pathlib /unit/config
-rw-r--r-- | tests/unit/config/test_configcommands.py | 34 | ||||
-rw-r--r-- | tests/unit/config/test_configfiles.py | 62 |
2 files changed, 48 insertions, 48 deletions
diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py index a15a6a334..72af2ad3e 100644 --- a/tests/unit/config/test_configcommands.py +++ b/tests/unit/config/test_configcommands.py @@ -480,7 +480,7 @@ class TestSource: @pytest.mark.parametrize('location', ['default', 'absolute', 'relative']) @pytest.mark.parametrize('clear', [True, False]) - def test_config_source(self, tmpdir, commands, config_stub, config_tmpdir, + def test_config_source(self, tmp_path, commands, config_stub, config_tmpdir, location, clear): assert config_stub.val.content.javascript.enabled config_stub.val.search.ignore_case = 'always' @@ -489,7 +489,7 @@ class TestSource: pyfile = config_tmpdir / 'config.py' arg = None elif location == 'absolute': - pyfile = tmpdir / 'sourced.py' + pyfile = tmp_path / 'sourced.py' arg = str(pyfile) elif location == 'relative': pyfile = config_tmpdir / 'sourced.py' @@ -607,8 +607,8 @@ class TestWritePy: """Tests for :config-write-py.""" - def test_custom(self, commands, config_stub, key_config_stub, tmpdir): - confpy = tmpdir / 'config.py' + def test_custom(self, commands, config_stub, key_config_stub, tmp_path): + confpy = tmp_path / 'config.py' config_stub.val.content.javascript.enabled = True key_config_stub.bind(keyseq(',x'), 'message-info foo', mode='normal') @@ -618,8 +618,8 @@ class TestWritePy: assert "c.content.javascript.enabled = True" in lines assert "config.bind(',x', 'message-info foo')" in lines - def test_defaults(self, commands, tmpdir): - confpy = tmpdir / 'config.py' + def test_defaults(self, commands, tmp_path): + confpy = tmp_path / 'config.py' commands.config_write_py(str(confpy), defaults=True) lines = confpy.read_text('utf-8').splitlines() @@ -639,10 +639,10 @@ class TestWritePy: assert '# Autogenerated config.py' in lines @pytest.mark.posix - def test_expanduser(self, commands, monkeypatch, tmpdir): + def test_expanduser(self, commands, monkeypatch, tmp_path): """Make sure that using a path with ~/... works correctly.""" - home = tmpdir / 'home' - home.ensure(dir=True) + home = tmp_path / 'home' + home.mkdir() monkeypatch.setenv('HOME', str(home)) commands.config_write_py('~/config.py') @@ -651,9 +651,9 @@ class TestWritePy: lines = confpy.read_text('utf-8').splitlines() assert '# Autogenerated config.py' in lines - def test_existing_file(self, commands, tmpdir): - confpy = tmpdir / 'config.py' - confpy.ensure() + def test_existing_file(self, commands, tmp_path): + confpy = tmp_path / 'config.py' + confpy.touch() with pytest.raises(cmdutils.CommandError) as excinfo: commands.config_write_py(str(confpy)) @@ -661,19 +661,19 @@ class TestWritePy: expected = " already exists - use --force to overwrite!" assert str(excinfo.value).endswith(expected) - def test_existing_file_force(self, commands, tmpdir): - confpy = tmpdir / 'config.py' - confpy.ensure() + def test_existing_file_force(self, commands, tmp_path): + confpy = tmp_path / 'config.py' + confpy.touch() commands.config_write_py(str(confpy), force=True) lines = confpy.read_text('utf-8').splitlines() assert '# Autogenerated config.py' in lines - def test_oserror(self, commands, tmpdir): + def test_oserror(self, commands, tmp_path): """Test writing to a directory which does not exist.""" with pytest.raises(cmdutils.CommandError): - commands.config_write_py(str(tmpdir / 'foo' / 'config.py')) + commands.config_write_py(str(tmp_path / 'foo' / 'config.py')) def test_config_py_arg(self, commands, config_py_arg): config_py_arg.ensure() diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py index 255ea8acc..4d70b7d25 100644 --- a/tests/unit/config/test_configfiles.py +++ b/tests/unit/config/test_configfiles.py @@ -744,13 +744,13 @@ class ConfPy: """Helper class to get a confpy fixture.""" - def __init__(self, tmpdir, filename: str = "config.py"): - self._file = tmpdir / filename + def __init__(self, tmp_path, filename: str = "config.py"): + self._file = tmp_path / filename self.filename = str(self._file) def write(self, *lines): text = '\n'.join(lines) - self._file.write_text(text, 'utf-8', ensure=True) + self._file.write_text(text, 'utf-8') def read(self, error=False, warn_autoconfig=False): """Read the config.py via configfiles and check for errors.""" @@ -777,8 +777,8 @@ class ConfPy: @pytest.fixture -def confpy(tmpdir, config_tmpdir, data_tmpdir, config_stub, key_config_stub): - return ConfPy(tmpdir) +def confpy(tmp_path, config_tmpdir, data_tmpdir, config_stub, key_config_stub): + return ConfPy(tmp_path) class TestConfigPyModules: @@ -786,8 +786,8 @@ class TestConfigPyModules: pytestmark = pytest.mark.usefixtures('config_stub', 'key_config_stub') @pytest.fixture - def qbmodulepy(self, tmpdir): - return ConfPy(tmpdir, filename="qbmodule.py") + def qbmodulepy(self, tmp_path): + return ConfPy(tmp_path, filename="qbmodule.py") @pytest.fixture(autouse=True) def restore_sys_path(self): @@ -795,7 +795,7 @@ class TestConfigPyModules: yield sys.path = old_path - def test_bind_in_module(self, confpy, qbmodulepy, tmpdir): + def test_bind_in_module(self, confpy, qbmodulepy, tmp_path): qbmodulepy.write( 'def run(config):', ' config.bind(",a", "message-info foo", mode="normal")') @@ -804,9 +804,9 @@ class TestConfigPyModules: expected = {'normal': {',a': 'message-info foo'}} assert config.instance.get_obj('bindings.commands') == expected assert "qbmodule" not in sys.modules.keys() - assert tmpdir not in sys.path + assert tmp_path not in sys.path - def test_restore_sys_on_err(self, confpy, qbmodulepy, tmpdir): + def test_restore_sys_on_err(self, confpy, qbmodulepy, tmp_path): confpy.write_qbmodule() qbmodulepy.write('def run(config):', ' 1/0') @@ -815,9 +815,9 @@ class TestConfigPyModules: assert error.text == "Unhandled exception" assert isinstance(error.exception, ZeroDivisionError) assert "qbmodule" not in sys.modules.keys() - assert tmpdir not in sys.path + assert tmp_path not in sys.path - def test_fail_on_nonexistent_module(self, confpy, qbmodulepy, tmpdir): + def test_fail_on_nonexistent_module(self, confpy, qbmodulepy, tmp_path): qbmodulepy.write('def run(config):', ' pass') confpy.write('import foobar', @@ -832,13 +832,13 @@ class TestConfigPyModules: assert tblines[0] == "Traceback (most recent call last):" assert tblines[-1].endswith("Error: No module named 'foobar'") - def test_no_double_if_path_exists(self, confpy, qbmodulepy, tmpdir): - sys.path.insert(0, tmpdir) + def test_no_double_if_path_exists(self, confpy, qbmodulepy, tmp_path): + sys.path.insert(0, tmp_path) confpy.write('import sys', 'if sys.path[0] in sys.path[1:]:', ' raise Exception("Path not expected")') confpy.read() - assert sys.path.count(tmpdir) == 1 + assert sys.path.count(tmp_path) == 1 class TestConfigPy: @@ -1004,9 +1004,9 @@ class TestConfigPy: confpy.read() assert config.instance.get_obj(option)[-1] == value - def test_oserror(self, tmpdir, data_tmpdir, config_tmpdir): + def test_oserror(self, tmp_path, data_tmpdir, config_tmpdir): with pytest.raises(configexc.ConfigFileErrors) as excinfo: - configfiles.read_config_py(str(tmpdir / 'foo')) + configfiles.read_config_py(str(tmp_path / 'foo')) assert len(excinfo.value.errors) == 1 error = excinfo.value.errors[0] @@ -1154,12 +1154,12 @@ class TestConfigPy: assert error.traceback is not None @pytest.mark.parametrize('location', ['abs', 'rel']) - def test_source(self, tmpdir, confpy, location): + def test_source(self, tmp_path, confpy, location): if location == 'abs': - subfile = tmpdir / 'subfile.py' + subfile = tmp_path / 'subfile.py' arg = str(subfile) else: - subfile = tmpdir / 'config' / 'subfile.py' + subfile = tmp_path / 'config' / 'subfile.py' arg = 'subfile.py' subfile.write_text("c.content.javascript.enabled = False", @@ -1169,11 +1169,11 @@ class TestConfigPy: assert not config.instance.get_obj('content.javascript.enabled') - def test_source_configpy_arg(self, tmpdir, data_tmpdir, monkeypatch): + def test_source_configpy_arg(self, tmp_path, data_tmpdir, monkeypatch): alt_filename = 'alt-config.py' - alt_confpy_dir = tmpdir / 'alt-confpy-dir' - alt_confpy_dir.ensure(dir=True) + alt_confpy_dir = tmp_path / 'alt-confpy-dir' + alt_confpy_dir.mkdir() monkeypatch.setattr(standarddir, 'config_py', lambda: str(alt_confpy_dir / alt_filename)) @@ -1187,8 +1187,8 @@ class TestConfigPy: assert not config.instance.get_obj('content.javascript.enabled') - def test_source_errors(self, tmpdir, confpy): - subfile = tmpdir / 'config' / 'subfile.py' + def test_source_errors(self, tmp_path, confpy): + subfile = tmp_path / 'config' / 'subfile.py' subfile.write_text("c.foo = 42", encoding='utf-8') confpy.write("config.source('subfile.py')") error = confpy.read(error=True) @@ -1196,8 +1196,8 @@ class TestConfigPy: assert error.text == "While setting 'foo'" assert isinstance(error.exception, configexc.NoOptionError) - def test_source_multiple_errors(self, tmpdir, confpy): - subfile = tmpdir / 'config' / 'subfile.py' + def test_source_multiple_errors(self, tmp_path, confpy): + subfile = tmp_path / 'config' / 'subfile.py' subfile.write_text("c.foo = 42", encoding='utf-8') confpy.write("config.source('subfile.py')", "c.bar = 23") @@ -1218,8 +1218,8 @@ class TestConfigPy: assert isinstance(error.exception, FileNotFoundError) @pytest.mark.parametrize('reverse', [True, False]) - def test_source_warn_autoconfig(self, tmpdir, confpy, reverse): - subfile = tmpdir / 'config' / 'subfile.py' + def test_source_warn_autoconfig(self, tmp_path, confpy, reverse): + subfile = tmp_path / 'config' / 'subfile.py' subfile.write_text("c.content.javascript.enabled = False", encoding='utf-8') lines = [ @@ -1383,8 +1383,8 @@ class TestConfigPyWriter: expected = "config.set('opt', 'ask', 'https://www.example.com/')" assert expected in text - def test_write(self, tmpdir): - pyfile = tmpdir / 'config.py' + def test_write(self, tmp_path): + pyfile = tmp_path / 'config.py' writer = configfiles.ConfigPyWriter(options=[], bindings={}, commented=False) writer.write(str(pyfile)) |