aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ionite34 <[email protected]>2022-11-24 11:35:55 +0800
committerGravatar ionite34 <[email protected]>2022-11-24 11:35:55 +0800
commit727993bb362aca654057b3e01c4f104dde978f83 (patch)
treef962c52200373e7fcfd622d9bc6232ea1a673f69
parentUpdate docstrings (diff)
Add unit test for MemFS access before __enter__
-rw-r--r--tests/test_memfs.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/test_memfs.py b/tests/test_memfs.py
index 128530a..6b51405 100644
--- a/tests/test_memfs.py
+++ b/tests/test_memfs.py
@@ -1,5 +1,6 @@
import logging
from concurrent.futures import ThreadPoolExecutor
+from operator import attrgetter
from unittest import TestCase, mock
from uuid import uuid4
@@ -37,3 +38,19 @@ class NsJailTests(TestCase):
# Original memfs should still exist afterwards
self.assertIsInstance(memfs, MemFS)
self.assertTrue(memfs.path.exists())
+
+ def test_no_context_error(self):
+ """Accessing MemFS attributes before __enter__ raises RuntimeError."""
+ cases = [
+ attrgetter("path"),
+ attrgetter("name"),
+ attrgetter("home"),
+ attrgetter("output"),
+ lambda fs: fs.mkdir(""),
+ lambda fs: list(fs.attachments(1)),
+ ]
+
+ memfs = MemFS(10)
+ for case in cases:
+ with self.subTest(case=case), self.assertRaises(RuntimeError):
+ case(memfs)