aboutsummaryrefslogtreecommitdiff
path: root/tests/test_sandbox.py
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-03-03 09:19:20 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-03-03 09:19:20 +0100
commit716265929bf861d340c1e71e2f24359875520d3a (patch)
treed6e536e42de09d7a908c559aa5b51d36936a4e5b /tests/test_sandbox.py
parenta90ac1b352bd5f7c2c677f051365401531229976 (diff)
downloadminishell_test-716265929bf861d340c1e71e2f24359875520d3a.tar.gz
minishell_test-716265929bf861d340c1e71e2f24359875520d3a.tar.bz2
minishell_test-716265929bf861d340c1e71e2f24359875520d3a.zip
Added sandbox and colors tests
Diffstat (limited to 'tests/test_sandbox.py')
-rw-r--r--tests/test_sandbox.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/test_sandbox.py b/tests/test_sandbox.py
new file mode 100644
index 0000000..2536be7
--- /dev/null
+++ b/tests/test_sandbox.py
@@ -0,0 +1,85 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# test_sandbox.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2021/03/03 08:09:00 by cacharle #+# #+# #
+# Updated: 2021/03/03 09:15:42 by cacharle ### ########.fr #
+# #
+# ############################################################################ #
+
+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
+
+Config.init([])
+
+
+@pytest.fixture
+def sandbox_dirs():
+ return [Path(s) for s in [
+ "foo",
+ "asdfasdfas;dlkfjas;dkfjas;lkdfj",
+ "z/y",
+ "a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z",
+ ]]
+
+
+def test_create(tmpdir, 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()
+
+
+def test_remove(tmpdir, 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()
+ 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()
+ 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()
+
+
+def test_context(tmpdir, 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()
+ 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):
+ with pytest.raises(RuntimeError):
+ assert not sandbox_dir.exists()
+ with sandbox.context():
+ assert sandbox_dir.exists()
+ raise RuntimeError
+ assert not sandbox_dir.exists()