allow '.' in filenames

This commit is contained in:
Martin Diehl 2020-11-04 18:08:04 +01:00
parent b8503e84b7
commit ae959b9cc2
2 changed files with 9 additions and 4 deletions

View File

@ -197,11 +197,10 @@ class VTK:
elif isinstance(self.vtk_data,vtk.vtkPolyData):
writer = vtk.vtkXMLPolyDataWriter()
default_ext = writer.GetDefaultFileExtension()
default_ext = '.'+writer.GetDefaultFileExtension()
ext = Path(fname).suffix
if ext and ext != '.'+default_ext:
raise ValueError(f'Given extension "{ext}" does not match default ".{default_ext}"')
writer.SetFileName(str(Path(fname).with_suffix('.'+default_ext)))
writer.SetFileName(str(fname)+default_ext if default_ext != ext else '')
if compress:
writer.SetCompressorTypeToZLib()
else:

View File

@ -85,6 +85,12 @@ class TestVTK:
assert(False)
@pytest.mark.parametrize('fname',['a','a.vtp','a.b','a.b.vtp'])
def test_filename_variations(self,tmp_path,fname):
points = np.random.rand(102,3)
v = VTK.from_poly_data(points)
v.save(tmp_path/fname)
@pytest.mark.parametrize('name,dataset_type',[('this_file_does_not_exist.vtk', None),
('this_file_does_not_exist.vtk','vtk'),
('this_file_does_not_exist.vtx', None)])