Skip to content

Commit f26b7d1

Browse files
committed
Add test to cover missed branches in fs.memoryfs
1 parent eb62026 commit f26b7d1

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

fs/test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,15 @@ def test_removetree(self):
11151115
self.fs.removetree("foo")
11161116
self.assert_not_exists("foo")
11171117

1118+
# Errors on files
1119+
self.fs.create("bar")
1120+
with self.assertRaises(errors.DirectoryExpected):
1121+
self.fs.removetree("bar")
1122+
1123+
# Errors on non-existing path
1124+
with self.assertRaises(errors.ResourceNotFound):
1125+
self.fs.removetree("foofoo")
1126+
11181127
def test_setinfo(self):
11191128
self.fs.create("birthday.txt")
11201129
now = math.floor(time.time())

tests/test_memoryfs.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,20 @@ def test_close_mem_free(self):
6666
"Memory usage increased after closing the file system; diff is %0.2f KiB."
6767
% (diff_close.size_diff / 1024.0),
6868
)
69+
70+
71+
class TestMemoryFile(unittest.TestCase):
72+
73+
def setUp(self):
74+
self.fs = memoryfs.MemoryFS()
75+
76+
def tearDown(self):
77+
self.fs.close()
78+
79+
def test_readline_writing(self):
80+
with self.fs.openbin("test.txt", "w") as f:
81+
self.assertRaises(IOError, f.readline)
82+
83+
def test_readinto_writing(self):
84+
with self.fs.openbin("test.txt", "w") as f:
85+
self.assertRaises(IOError, f.readinto, bytearray(10))

0 commit comments

Comments
 (0)