diff options
Diffstat (limited to 'tests/test_sandbox.py')
| -rw-r--r-- | tests/test_sandbox.py | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/tests/test_sandbox.py b/tests/test_sandbox.py index 2536be7..bb2ea98 100644 --- a/tests/test_sandbox.py +++ b/tests/test_sandbox.py @@ -6,7 +6,7 @@ # By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/03/03 08:09:00 by cacharle #+# #+# # -# Updated: 2021/03/03 09:15:42 by cacharle ### ########.fr # +# Updated: 2021/03/06 09:58:17 by cacharle ### ########.fr # # # # ############################################################################ # @@ -14,7 +14,6 @@ import pytest import shutil from pathlib import Path -from tests.helpers import config_context from minishell_test import sandbox from minishell_test.config import Config @@ -31,55 +30,55 @@ def sandbox_dirs(): ]] -def test_create(tmpdir, sandbox_dirs): +def test_create(tmpdir, monkeypatch, sandbox_dirs): for sandbox_dir in sandbox_dirs: sandbox_dir = Path(tmpdir / sandbox_dir) - with config_context(sandbox_dir=sandbox_dir): - assert not sandbox_dir.exists() - sandbox.create() - assert sandbox_dir.exists() + monkeypatch.setattr(Config, 'sandbox_dir', sandbox_dir) + assert not sandbox_dir.exists() + sandbox.create() + assert sandbox_dir.exists() -def test_remove(tmpdir, sandbox_dirs): +def test_remove(tmpdir, monkeypatch, sandbox_dirs): for sandbox_dir in sandbox_dirs: sandbox_dir = Path(tmpdir / sandbox_dir) - with config_context(sandbox_dir=sandbox_dir): - sandbox.create() - assert sandbox_dir.exists() - sandbox.remove() - assert not sandbox_dir.exists() + monkeypatch.setattr(Config, 'sandbox_dir', sandbox_dir) + sandbox.create() + assert sandbox_dir.exists() + sandbox.remove() + assert not sandbox_dir.exists() for sandbox_dir in sandbox_dirs: sandbox_dir = Path(tmpdir / sandbox_dir) - with config_context(sandbox_dir=sandbox_dir): - sandbox.create() - assert sandbox_dir.exists() - sandbox_dir.chmod(000) - sandbox.remove() - assert not sandbox_dir.exists() + monkeypatch.setattr(Config, 'sandbox_dir', sandbox_dir) + sandbox.create() + assert sandbox_dir.exists() + sandbox_dir.chmod(000) + sandbox.remove() + assert not sandbox_dir.exists() for sandbox_dir in sandbox_dirs: sandbox_dir = Path(tmpdir / sandbox_dir) - with config_context(sandbox_dir=sandbox_dir): - sandbox.create() - assert sandbox_dir.exists() - shutil.rmtree(sandbox_dir) - sandbox.remove() - assert not sandbox_dir.exists() + monkeypatch.setattr(Config, 'sandbox_dir', sandbox_dir) + sandbox.create() + assert sandbox_dir.exists() + shutil.rmtree(sandbox_dir) + sandbox.remove() + assert not sandbox_dir.exists() -def test_context(tmpdir, sandbox_dirs): +def test_context(tmpdir, monkeypatch, sandbox_dirs): + for sandbox_dir in sandbox_dirs: + sandbox_dir = Path(tmpdir / sandbox_dir) + monkeypatch.setattr(Config, 'sandbox_dir', sandbox_dir) + assert not sandbox_dir.exists() + with sandbox.context(): + assert sandbox_dir.exists() + assert not sandbox_dir.exists() for sandbox_dir in sandbox_dirs: sandbox_dir = Path(tmpdir / sandbox_dir) - with config_context(sandbox_dir=sandbox_dir): + monkeypatch.setattr(Config, 'sandbox_dir', sandbox_dir) + with pytest.raises(RuntimeError): assert not sandbox_dir.exists() with sandbox.context(): assert sandbox_dir.exists() + raise RuntimeError assert not sandbox_dir.exists() - for sandbox_dir in sandbox_dirs: - sandbox_dir = Path(tmpdir / sandbox_dir) - with config_context(sandbox_dir=sandbox_dir): - with pytest.raises(RuntimeError): - assert not sandbox_dir.exists() - with sandbox.context(): - assert sandbox_dir.exists() - raise RuntimeError - assert not sandbox_dir.exists() |
