diff --git a/Wrapping/Generators/Python/Tests/PythonTemplateTest.py b/Wrapping/Generators/Python/Tests/PythonTemplateTest.py index 8b56c6cd1b8..f4cd84cb788 100644 --- a/Wrapping/Generators/Python/Tests/PythonTemplateTest.py +++ b/Wrapping/Generators/Python/Tests/PythonTemplateTest.py @@ -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) diff --git a/Wrapping/Generators/Python/itkTemplate.py b/Wrapping/Generators/Python/itkTemplate.py index 473879a8d8a..56f2324d8a3 100644 --- a/Wrapping/Generators/Python/itkTemplate.py +++ b/Wrapping/Generators/Python/itkTemplate.py @@ -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,