Skip to content

Commit f3e7853

Browse files
committed
fix for superfluous directory
1 parent d8fdb13 commit f3e7853

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ release: readme
88

99
.PHONY: test
1010
test:
11-
nosetests --with-coverage --cover-erase --cover-package=fs_s3fs fs_s3fs/tests
11+
nosetests --with-coverage --cover-erase --cover-package=fs_s3fs -a "!slow" fs_s3fs/tests
1212
rm .coverage
1313

1414
.PHONY: testall

docs/index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ URL from an S3 object. Here's an example:
9393
More Information
9494
================
9595

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

9998

10099
Indices and tables

fs_s3fs/_s3fs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def _path_to_key(self, path):
295295
_key = "{}/{}".format(
296296
self._prefix,
297297
_path
298-
).replace('/', self.delimiter)
298+
).lstrip('/').replace('/', self.delimiter)
299299
return _key
300300

301301
def _path_to_dir_key(self, path):
@@ -304,7 +304,7 @@ def _path_to_dir_key(self, path):
304304
_key = forcedir("{}/{}".format(
305305
self._prefix,
306306
_path
307-
)).replace('/', self.delimiter)
307+
)).lstrip('/').replace('/', self.delimiter)
308308
return _key
309309

310310
def _key_to_path(self, key):

fs_s3fs/tests/test_s3fs.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,37 @@
22

33
import unittest
44

5+
from nose.plugins.attrib import attr
6+
57
from fs.test import FSTestCases
68

79
from fs_s3fs import S3FS
810

911
import boto3
1012

1113

14+
class TestS3FS(FSTestCases, unittest.TestCase):
15+
"""Test S3FS implementation from dir_path."""
16+
bucket_name = 'fsexample'
17+
s3 = boto3.resource('s3')
18+
client = boto3.client('s3')
19+
20+
def make_fs(self):
21+
self._delete_bucket_contents()
22+
return S3FS(self.bucket_name)
23+
24+
def _delete_bucket_contents(self):
25+
response = self.client.list_objects(
26+
Bucket=self.bucket_name
27+
)
28+
contents = response.get("Contents", ())
29+
for obj in contents:
30+
self.client.delete_object(
31+
Bucket=self.bucket_name,
32+
Key=obj["Key"]
33+
)
34+
35+
@attr('slow')
1236
class TestS3FSSubDir(FSTestCases, unittest.TestCase):
1337
"""Test S3FS implementation from dir_path."""
1438
bucket_name = 'fsexample'
@@ -30,3 +54,17 @@ def _delete_bucket_contents(self):
3054
Bucket=self.bucket_name,
3155
Key=obj["Key"]
3256
)
57+
58+
59+
class TestS3FSHelpers(unittest.TestCase):
60+
61+
def test_path_to_key(self):
62+
s3 = S3FS('foo')
63+
self.assertEqual(s3._path_to_key('foo.bar'), 'foo.bar')
64+
self.assertEqual(s3._path_to_key('foo/bar'), 'foo/bar')
65+
66+
def test_path_to_key_subdir(self):
67+
s3 = S3FS('foo', '/dir')
68+
self.assertEqual(s3._path_to_key('foo.bar'), 'dir/foo.bar')
69+
self.assertEqual(s3._path_to_key('foo/bar'), 'dir/foo/bar')
70+

0 commit comments

Comments
 (0)