Skip to content

Commit

Permalink
S3Storage is optional (#20)
Browse files Browse the repository at this point in the history
* Reporting missing s3fs

* test: S3Storage test conditional if s3fs is available
  • Loading branch information
castelao authored Mar 19, 2022
1 parent 8786f97 commit 61d039d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions OceanColor/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

try:
import s3fs
S3FS_AVAILABLE = True
except:
S3FS_AVAILABLE = False
module_logger.debug("s3fs library is not available")


Expand Down Expand Up @@ -277,6 +279,10 @@ def __init__(self, root: str):
>>> backend = S3Storage('s3://mybucket/NASA/')
>>> 'T2004006.L3m_DAY_CHL_chlor_a_4km.nc' in backend
"""
if not S3FS_AVAILABLE:
module_logger.error("Missing s3fs library required by S3Storage")
raise ImportError

self.root = root
self.fs = s3fs.S3FileSystem(anon=False)

Expand Down
8 changes: 8 additions & 0 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

import os
import pickle

import pytest
try:
import s3fs
S3FS_AVAILABLE = True
except:
S3FS_AVAILABLE = False

from OceanColor.storage import parse_filename, OceanColorDB, FileSystem, S3Storage

Expand Down Expand Up @@ -104,6 +110,8 @@ def test_no_download():
# It was not supposed to reach here
raise


@pytest.mark.skipif(not S3FS_AVAILABLE, reason="S3Storage is not available without s3fs")
def test_S3Storage_path():
backend = S3Storage("s3://mybucket/datadir")
assert backend.path("A2019109.L3m_DAY_CHL_chlor_a_4km.nc") == 's3://mybucket/datadir/MODIS-Aqua/L3m/2019/109/A2019109.L3m_DAY_CHL_chlor_a_4km.zarr'

0 comments on commit 61d039d

Please sign in to comment.