Skip to content

Commit

Permalink
fix for superfluous directory
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Aug 28, 2017
1 parent d8fdb13 commit f3e7853
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ release: readme

.PHONY: test
test:
nosetests --with-coverage --cover-erase --cover-package=fs_s3fs fs_s3fs/tests
nosetests --with-coverage --cover-erase --cover-package=fs_s3fs -a "!slow" fs_s3fs/tests
rm .coverage

.PHONY: testall
Expand Down
3 changes: 1 addition & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ URL from an S3 object. Here's an example:
More Information
================

See the `PyFilesystem Docs <https://docs.pyfilesystem.org>`_ for full
details.
See the `PyFilesystem Docs <https://docs.pyfilesystem.org>`_ for documentation on the rest of the PyFilesystem interface.


Indices and tables
Expand Down
4 changes: 2 additions & 2 deletions fs_s3fs/_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def _path_to_key(self, path):
_key = "{}/{}".format(
self._prefix,
_path
).replace('/', self.delimiter)
).lstrip('/').replace('/', self.delimiter)
return _key

def _path_to_dir_key(self, path):
Expand All @@ -304,7 +304,7 @@ def _path_to_dir_key(self, path):
_key = forcedir("{}/{}".format(
self._prefix,
_path
)).replace('/', self.delimiter)
)).lstrip('/').replace('/', self.delimiter)
return _key

def _key_to_path(self, key):
Expand Down
38 changes: 38 additions & 0 deletions fs_s3fs/tests/test_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,37 @@

import unittest

from nose.plugins.attrib import attr

from fs.test import FSTestCases

from fs_s3fs import S3FS

import boto3


class TestS3FS(FSTestCases, unittest.TestCase):
"""Test S3FS implementation from dir_path."""
bucket_name = 'fsexample'
s3 = boto3.resource('s3')
client = boto3.client('s3')

def make_fs(self):
self._delete_bucket_contents()
return S3FS(self.bucket_name)

def _delete_bucket_contents(self):
response = self.client.list_objects(
Bucket=self.bucket_name
)
contents = response.get("Contents", ())
for obj in contents:
self.client.delete_object(
Bucket=self.bucket_name,
Key=obj["Key"]
)

@attr('slow')
class TestS3FSSubDir(FSTestCases, unittest.TestCase):
"""Test S3FS implementation from dir_path."""
bucket_name = 'fsexample'
Expand All @@ -30,3 +54,17 @@ def _delete_bucket_contents(self):
Bucket=self.bucket_name,
Key=obj["Key"]
)


class TestS3FSHelpers(unittest.TestCase):

def test_path_to_key(self):
s3 = S3FS('foo')
self.assertEqual(s3._path_to_key('foo.bar'), 'foo.bar')
self.assertEqual(s3._path_to_key('foo/bar'), 'foo/bar')

def test_path_to_key_subdir(self):
s3 = S3FS('foo', '/dir')
self.assertEqual(s3._path_to_key('foo.bar'), 'dir/foo.bar')
self.assertEqual(s3._path_to_key('foo/bar'), 'dir/foo/bar')

0 comments on commit f3e7853

Please sign in to comment.