Skip to content
Snippets Groups Projects
Commit 1fc03890 authored by Ulugbek Abdullaev's avatar Ulugbek Abdullaev
Browse files

add a check that filename passed to nd2reader has an extension .nd2 because...

add a check that filename passed to nd2reader has an extension .nd2 because the current implementation raises InvalidVersionError if the passed file is non-nd2 type, which is misleading

add an exception InvalidFileType

add a test for the new behavior of ND2Reader constructor
parent c038c5b2
No related branches found
No related tags found
No related merge requests found
class InvalidFileType(Exception):
"""Non .nd2 extension file.
File does not have an extension .nd2.
"""
pass
class InvalidVersionError(Exception):
"""Unknown version.
......
from pims import Frame
from pims.base_frames import FramesSequenceND
from nd2reader.exceptions import EmptyFileError
from nd2reader.exceptions import EmptyFileError, InvalidFileType
from nd2reader.parser import Parser
import numpy as np
......@@ -15,6 +15,10 @@ class ND2Reader(FramesSequenceND):
def __init__(self, filename):
super(ND2Reader, self).__init__()
if not filename.endswith(".nd2"):
raise InvalidFileType(f"The file {filename} you want to read with nd2reader does not have extension .nd2.")
self.filename = filename
# first use the parser to parse the file
......
......@@ -4,12 +4,15 @@ import struct
from pims import Frame
from nd2reader.artificial import ArtificialND2
from nd2reader.exceptions import EmptyFileError
from nd2reader.exceptions import EmptyFileError, InvalidFileType
from nd2reader.reader import ND2Reader
from nd2reader.parser import Parser
class TestReader(unittest.TestCase):
def test_invalid_file_extension(self):
self.assertRaises(InvalidFileType, lambda: ND2Reader('test_data/invalid_extension_file.inv'))
def test_extension(self):
self.assertTrue('nd2' in ND2Reader.class_exts())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment