Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path showing on PathDoesNotExist. #18

Merged
merged 1 commit into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions inmemorystorage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ def resolve(self, path, create=False, use_bytes=False):
if current in self.children.keys():
return self.children[current]
if not create:
raise PathDoesNotExist()
raise PathDoesNotExist(path)
content = six.binary_type() if use_bytes else six.text_type()
node = InMemoryFile(name=current, content=content)
self.add_child(current, node)
return node
if current in self.children.keys():
return self.children[current].resolve(rest, create=create, use_bytes=use_bytes)
if not create:
raise PathDoesNotExist()
raise PathDoesNotExist(path)
node = InMemoryDir()
self.add_child(current, node)
return self.children[current].resolve(rest, create=create, use_bytes=use_bytes)
Expand Down
15 changes: 12 additions & 3 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import time
import unittest
from inmemorystorage import InMemoryStorage
from inmemorystorage.storage import InMemoryDir, InMemoryFile
from django.core.files.base import ContentFile

from django.conf import settings
from django.core.files.base import ContentFile
from django.test.utils import override_settings

from inmemorystorage import InMemoryStorage
from inmemorystorage.storage import InMemoryDir, InMemoryFile, PathDoesNotExist


class MemoryStorageTests(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -65,6 +67,12 @@ def test_write(self):
with self.storage.open("file", "r") as f:
self.assertEqual(f.read(), "hello")

def test_missing(self):
missing_file_name = "missing-file"
with self.assertRaises(PathDoesNotExist) as context_manager:
self.storage.open(missing_file_name, "r")
self.assertEqual(context_manager.exception.args, (missing_file_name,))

def test_all(self):
self.assertEqual(self.storage.listdir('/'), [[], []])
self.assertEqual(self.storage.save('dir/subdir/file', ContentFile('testing')), 'dir/subdir/file')
Expand Down Expand Up @@ -157,5 +165,6 @@ def test_no_persistance_without_setting(self):
# Can't use self.assertIs because it isn't available in Python 2.6
self.assertTrue(storage_a.filesystem is not storage_b.filesystem)


if __name__ == '__main__':
unittest.main()