diff options
author | 2022-11-24 11:35:55 +0800 | |
---|---|---|
committer | 2022-11-24 11:35:55 +0800 | |
commit | 727993bb362aca654057b3e01c4f104dde978f83 (patch) | |
tree | f962c52200373e7fcfd622d9bc6232ea1a673f69 | |
parent | Update docstrings (diff) |
Add unit test for MemFS access before __enter__
-rw-r--r-- | tests/test_memfs.py | 17 |
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) |