Skip to content

Commit

Permalink
add test for completely missing data
Browse files Browse the repository at this point in the history
  • Loading branch information
sroet committed Mar 22, 2024
1 parent 0373d62 commit 9292e38
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/pytom_tm/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def wrap_mrcfile_readers(func, *args, **kwargs):
"However, loading with 'permissive=True' did generate data, make sure this is correct!")
else:
logging.debug(f"Could not reasonably recover")
raise err
raise ValueError(
f"{args[0]} header or data is too corrupt to recover, please fix the header or data"
) from err
yield mrc
# this should only be called after the context exists
mrc.close()
Expand Down
Binary file added tests/Data/header_only.mrc
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import pathlib

FAILING_MRC = pathlib.Path(__file__).parent.joinpath(pathlib.Path('Data/human_ribo_mask_32_8_5.mrc'))
# The below file was made with head -c 1024 human_ribo_mask_32_8_5.mrc > header_only.mrc
CORRUPT_MRC = pathlib.Path(__file__).parent.joinpath(pathlib.Path('header_only.mrc'))


class TestBrokenMRC(unittest.TestCase):
def test_read_mrc_minor_broken(self):
Expand All @@ -14,6 +17,13 @@ def test_read_mrc_minor_broken(self):
self.assertIn(FAILING_MRC, cm.output[0])
self.assertIn("make sure this is correct", cm.output[0])

def test_read_mrc_too_broken(self):
# Test if this mrc raises an error as expected
with self.assertRaises(ValueError) as err:
mrc = read_mrc(FAILING_MRC)
self.assertIn(FAILING_MRC, str(err.exception)
self.assertIn("too corrupt", cm.output[0])

def test_read_mrc_meta_data(self):
# Test if this mrc can be read and if the approriate logs are printed
with self.assertLogs(level='WARNING') as cm:
Expand Down

0 comments on commit 9292e38

Please sign in to comment.