Skip to content

Commit

Permalink
add generic_open test with actual files
Browse files Browse the repository at this point in the history
  • Loading branch information
pdebuyl committed Mar 31, 2022
1 parent bc9c493 commit 9d0bd6a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions satpy/tests/reader_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,48 @@ def test_generic_open(self, bz2_mock):

assert mock_bz2_open.read.called

def test_generic_open_text(self):
"""Test the bz2 file unzipping context manager using dummy text data."""
dummy_text_data = 'Hello'
dummy_text_filename = 'dummy.txt'
with open(dummy_text_filename, 'w') as f:
f.write(dummy_text_data)

with hf.generic_open(dummy_text_filename, 'r') as f:
read_text_data = f.read()

assert read_text_data == dummy_text_data

dummy_text_filename = 'dummy.txt.bz2'
with hf.bz2.open(dummy_text_filename, 'wt') as f:
f.write(dummy_text_data)

with hf.generic_open(dummy_text_filename, 'rt') as f:
read_text_data = f.read()

assert read_text_data == dummy_text_data

def test_generic_open_binary(self):
"""Test the bz2 file unzipping context manager using dummy binary data."""
dummy_binary_data = b'Hello'
dummy_binary_filename = 'dummy.dat'
with open(dummy_binary_filename, 'wb') as f:
f.write(dummy_binary_data)

with hf.generic_open(dummy_binary_filename, 'rb') as f:
read_binary_data = f.read()

assert read_binary_data == dummy_binary_data

dummy_binary_filename = 'dummy.dat.bz2'
with hf.bz2.open(dummy_binary_filename, 'wb') as f:
f.write(dummy_binary_data)

with hf.generic_open(dummy_binary_filename, 'rb') as f:
read_binary_data = f.read()

assert read_binary_data == dummy_binary_data

@mock.patch("os.remove")
@mock.patch("satpy.readers.utils.unzip_file", return_value='dummy.txt')
def test_pro_reading_gets_unzipped_file(self, fake_unzip_file, fake_remove):
Expand Down

0 comments on commit 9d0bd6a

Please sign in to comment.