Skip to content

Commit

Permalink
Merge pull request #2832 from pnuu/fsfile-public-fs-property
Browse files Browse the repository at this point in the history
Add a read-only FSFile.fs property
  • Loading branch information
mraspaud committed Jun 20, 2024
2 parents a7ff99f + 52953f6 commit 8dfc261
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions satpy/readers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,11 @@ def __repr__(self):
"""Representation of the object."""
return '<FSFile "' + str(self._file) + '">'

@property
def fs(self):
"""Return the underlying private filesystem attribute."""
return self._fs

def open(self, *args, **kwargs): # noqa: A003
"""Open the file.
Expand Down
12 changes: 12 additions & 0 deletions satpy/tests/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,18 @@ def test_hash(self, local_filename, local_filename2, local_zip_file):
for fn in {local_filename, local_filename2}
for fs in [None, lfs, zfs, cfs]}) == 2 * 4

def test_fs_property_read(self, local_filename):
"""Test reading the fs property of the class."""
fsf = FSFile(local_filename)
fs = fsf.fs
assert fs is None

def test_fs_property_is_read_only(self, local_filename):
"""Test that the fs property of the class is read-only."""
fsf = FSFile(local_filename)
with pytest.raises(AttributeError):
fsf.fs = "foo"


def test_open_file_or_filename_uses_mode(tmp_path):
"""Test that open_file_or_filename uses provided mode."""
Expand Down

0 comments on commit 8dfc261

Please sign in to comment.