Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Wrapping/Generators/Python/Tests/PythonTemplateTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,29 @@
reader = readerType.New(FileName='test.png')
assert reader.GetFileName() == 'test.png'

# wwith a wrong attribute name
# with a wrong attribute name
try:
reader = readerType.New(WrongName='test.png')
raise Exception('no exception sent for wrong attribute name')
except AttributeError:
pass

# wwith a wrong attribute type
# with a wrong attribute type
try:
reader = readerType.New(FileName=1)
raise Exception('no exception sent for wrong attribute type')
except:
pass

# with a wrong file name
try:
reader = itk.ImageFileReader.New(FileName="wrong filename")
raise Exception('no exception sent for wrong file name')
except RuntimeError as e:
if not "The file doesn't exist." in str(e):
raise e
pass

# pass filter as argument for input
# to a filter with SetInput method
median = itk.MedianImageFilter[ImageType, ImageType].New(reader)
Expand Down
6 changes: 5 additions & 1 deletion Wrapping/Generators/Python/itkTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,11 @@ def firstIfList(arg):
else:
imageIO = itk.ImageIOFactory.CreateImageIO( inputFileName, itk.ImageIOFactory.ReadMode )
if not imageIO:
raise RuntimeError("No ImageIO is registered to handle the given file.")
msg = ""
if not os.path.isfile(inputFileName):
msg += ("\nThe file doesn't exist. \n" +
"Filename = %s" % inputFileName)
raise RuntimeError("Could not create IO object for reading file %s" % inputFileName + msg)
componentTypeDic= {"float": itk.F, "double": itk.D,
"unsigned_char": itk.UC, "unsigned_short": itk.US, "unsigned_int": itk.UI,
"unsigned_long": itk.UL, "unsigned_long_long": itk.ULL, "char": itk.SC, "short": itk.SS,
Expand Down