distinguish 'file not found' and 'invalid file'
This commit is contained in:
parent
c74e57f225
commit
903c185ee6
|
@ -139,6 +139,8 @@ class VTK:
|
|||
vtkUnstructuredGrid, and vtkPolyData.
|
||||
|
||||
"""
|
||||
if not os.path.isfile(fname): # vtk has a strange error handling
|
||||
raise FileNotFoundError(f'No such file: {fname}')
|
||||
ext = Path(fname).suffix
|
||||
if ext == '.vtk' or dataset_type is not None:
|
||||
reader = vtk.vtkGenericDataObjectReader()
|
||||
|
@ -166,9 +168,6 @@ class VTK:
|
|||
else:
|
||||
raise TypeError(f'Unknown file extension {ext}')
|
||||
|
||||
if not os.path.isfile(fname):
|
||||
raise FileNotFoundError(f'No such file: {fname}')
|
||||
|
||||
reader.SetFileName(str(fname))
|
||||
reader.Update()
|
||||
vtk_data = reader.GetOutput()
|
||||
|
|
|
@ -299,6 +299,9 @@ def _polar_decomposition(T,requested):
|
|||
if 'U' in requested:
|
||||
output.append(_np.einsum('...ji,...jk',R,T))
|
||||
|
||||
if len(output) == 0:
|
||||
raise ValueError('Output needs to be out of V,R,U')
|
||||
|
||||
return tuple(output)
|
||||
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ class TestGeom:
|
|||
|
||||
def test_invalid_vtr(self,tmp_path):
|
||||
v = VTK.from_rectilinear_grid(np.random.randint(5,10,3)*2,np.random.random(3) + 1.0)
|
||||
v.save(tmp_path/'no_materialpoint.vtr')
|
||||
v.save(tmp_path/'no_materialpoint.vtr',parallel=False)
|
||||
with pytest.raises(ValueError):
|
||||
Geom.load(tmp_path/'no_materialpoint.vtr')
|
||||
|
||||
|
|
|
@ -100,12 +100,17 @@ class TestVTK:
|
|||
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)])
|
||||
def test_invalid_dataset_type(self,name,dataset_type):
|
||||
@pytest.mark.parametrize('fname,dataset_type',[('a_file.vtk', None),
|
||||
('a_file.vtk','vtk'),
|
||||
('a_file.vtx', None)])
|
||||
def test_invalid_dataset_type(self,tmp_path,fname,dataset_type):
|
||||
open(tmp_path/fname,'a').close()
|
||||
with pytest.raises(TypeError):
|
||||
VTK.load(name,dataset_type)
|
||||
VTK.load(tmp_path/fname,dataset_type)
|
||||
|
||||
def test_file_not_found(self):
|
||||
with pytest.raises(FileNotFoundError):
|
||||
VTK.load('/dev/null')
|
||||
|
||||
def test_add_extension(self,tmp_path,default):
|
||||
default.save(tmp_path/'default.txt',parallel=False)
|
||||
|
|
Loading…
Reference in New Issue