Skip to content

Commit

Permalink
Merge pull request #36 from Othoz/cleanup-tests
Browse files Browse the repository at this point in the history
Remove runtime dependency on NumPy
  • Loading branch information
birnbaum committed Jul 10, 2020
2 parents a3f9c1c + 9506fd7 commit 068216d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -2,7 +2,8 @@ sudo: false
language: python

python:
- "3.5"
- 3.5
- 3.8

install:
- pip install pipenv
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -20,6 +20,15 @@ Possible types of changes are:
Unreleased
----------


1.4.1 - 06.07.2020
------------------

Fixed
'''''
- Fixed a bug in ``GCSFile.readinto`` that surfaced for Python >=3.8 when reading data via e.g. ``numpy.load``.


1.4.0 - 12.06.2020
------------------

Expand Down
1 change: 1 addition & 0 deletions Pipfile
Expand Up @@ -4,6 +4,7 @@ verify_ssl = true
name = "pypi"

[dev-packages]
numpy = "*" # one test verifies that GCSFS is compatible with numpy.load()/save() and thus requires numpy as a dep
flake8 = "*"
pytest = "*"
pytest-cov = "*"
Expand Down
40 changes: 11 additions & 29 deletions fs_gcsfs/tests/test_gcsfs.py
Expand Up @@ -37,35 +37,6 @@ def make_fs(self):
return GCSFS(bucket_name=TEST_BUCKET, root_path=self.root_path, client=self.client, create=True)


class TestReadinto(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.client = Client()
cls.bucket = cls.client.get_bucket(TEST_BUCKET)
super().setUpClass()

def setUp(self):
self.root_path = "gcsfs/" + str(uuid.uuid4())
super().setUp()

def tearDown(self):
for blob in self.bucket.list_blobs(prefix=self.root_path):
blob.delete()

def make_fs(self):
return GCSFS(bucket_name=TEST_BUCKET, root_path=self.root_path, client=self.client, create=True)

def test_readinto(self):
fs = self.make_fs()
a = np.random.choice([Decimal("1.0"), Decimal("2.22"), Decimal("3.1")], size=(100, 10))
with fs.open("foo.npy", "wb") as f:
np.save(f, a)

with fs.open("foo.npy", "rb") as f:
np.load(f, allow_pickle=True)


@pytest.fixture(scope="module")
def client_mock():
class ClientMock:
Expand Down Expand Up @@ -178,6 +149,17 @@ def test_instantiation_with_create_false_fails_for_non_existing_root_path():
GCSFS(bucket_name=TEST_BUCKET, root_path=str(uuid.uuid4()), create=False)


def test_gcsfile_readinto_works_correctly_with_numpy_load(gcsfs):
# Note: this is a regression test that previously failed with GCSFS <=1.4.0 due to a bug in
# GCSFile.readinto() that caused an exception to be raised. The test thus does not require explicit
# asserts, it purely verifies that the exception doesn't get raised anymore.
a = np.random.choice([Decimal("1.0"), Decimal("2.22"), Decimal("3.1")], size=(100, 10))
with gcsfs.open("foo.npy", "wb") as f:
np.save(f, a)
with gcsfs.open("foo.npy", "rb") as f:
np.load(f, allow_pickle=True)


@pytest.mark.parametrize("query_param, strict", [
("", True),
("nonExisting=True", True),
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Expand Up @@ -27,8 +27,7 @@
setup_requires=['setuptools_scm'],
install_requires=[
"fs~=2.0",
"google-cloud-storage~=1.0",
"numpy~=1.18"
"google-cloud-storage~=1.0"
],
entry_points={
"fs.opener": [
Expand Down

0 comments on commit 068216d

Please sign in to comment.