From 8c280c2b892bb881b96e60733c197f2c6cda337b Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sat, 10 Nov 2018 10:59:18 +0000 Subject: [PATCH] =?UTF-8?q?fix=20Schr=C3=B6dinger=20memory=20resource=20(#?= =?UTF-8?q?229)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fs/_version.py | 2 +- fs/memoryfs.py | 3 +++ fs/test.py | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/_version.py b/fs/_version.py index 232aacee..8519feea 100644 --- a/fs/_version.py +++ b/fs/_version.py @@ -1,3 +1,3 @@ """Version, used in module and setup.py. """ -__version__ = "2.1.1" +__version__ = "2.1.2a0" diff --git a/fs/memoryfs.py b/fs/memoryfs.py index d038ed0f..2446b0d1 100644 --- a/fs/memoryfs.py +++ b/fs/memoryfs.py @@ -414,6 +414,9 @@ def openbin(self, path, mode="r", buffering=-1, **options): _path = self.validatepath(path) dir_path, file_name = split(_path) + if not file_name: + raise errors.FileExpected(path) + with self._lock: parent_dir_entry = self._get_dir_entry(dir_path) if parent_dir_entry is None or not parent_dir_entry.is_dir: diff --git a/fs/test.py b/fs/test.py index a65188a4..74ad10c5 100644 --- a/fs/test.py +++ b/fs/test.py @@ -329,6 +329,12 @@ def assert_text(self, path, contents): self.assertEqual(data, contents) self.assertIsInstance(data, text_type) + def test_root_dir(self): + with self.assertRaises(errors.FileExpected): + self.fs.open("/") + with self.assertRaises(errors.FileExpected): + self.fs.openbin("/") + def test_appendbytes(self): with self.assertRaises(TypeError): self.fs.appendbytes("foo", "bar")