aboutsummaryrefslogtreecommitdiff
path: root/tests/test_sandbox.py
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-03-06 10:13:17 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-03-06 10:13:17 +0100
commit2a854b36624fb1c108a56d317aa54ca630864288 (patch)
treee50a5f2c2f77966c60580bdc1e73ce66be7b66b5 /tests/test_sandbox.py
parent422c56fbc5cd7493aaa96a341ebfff077f7a7de3 (diff)
downloadminishell_test-2a854b36624fb1c108a56d317aa54ca630864288.tar.gz
minishell_test-2a854b36624fb1c108a56d317aa54ca630864288.tar.bz2
minishell_test-2a854b36624fb1c108a56d317aa54ca630864288.zip
Updated tests to use monkeypatch.setattr(Config, attr, value) instead of custom config_context
Diffstat (limited to 'tests/test_sandbox.py')
-rw-r--r--tests/test_sandbox.py71
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()