more test, swich to pathlib
This commit is contained in:
parent
8c8132bcd7
commit
8d5a72e936
|
@ -1,4 +1,4 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -15,4 +15,4 @@ def update(request):
|
|||
@pytest.fixture
|
||||
def reference_dir_base():
|
||||
"""Directory containing reference results."""
|
||||
return os.path.join(os.path.dirname(__file__),'reference')
|
||||
return Path(__file__).parent/'reference'
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0"?>
|
||||
<VTKFile type="PolyData" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
|
||||
<PolyData>
|
||||
<Piece NumberOfPoints="10" NumberOfVerts="0" NumberOfLines="0" NumberOfStrips="0" NumberOfPolys="0">
|
||||
<PointData>
|
||||
<DataArray type="Float64" Name="coordinates" NumberOfComponents="3" format="binary" RangeMin="0.7453559924999299" RangeMax="2.449489742783178">
|
||||
AQAAAACAAADwAAAAagAAAA==eF5jYMAGPuyXOV4IRHvsIfQZe8u+xxZ9j1/sh/Eh9B37IjDj4f5QMLhqD6Gf2odB+Pth6iD0G3sFiLn7ofqg+j/CxOH6IfRX+xCouRYQ+6H0D/sCqH6YuRD6D1wd1B9QmsEBxgcAJsNfhw==
|
||||
<InformationKey name="L2_NORM_RANGE" location="vtkDataArray" length="2">
|
||||
<Value index="0">
|
||||
0.7453559925
|
||||
</Value>
|
||||
<Value index="1">
|
||||
2.4494897428
|
||||
</Value>
|
||||
</InformationKey>
|
||||
</DataArray>
|
||||
</PointData>
|
||||
<CellData>
|
||||
</CellData>
|
||||
<Points>
|
||||
<DataArray type="Float64" Name="Points" NumberOfComponents="3" format="binary" RangeMin="0.7453559924999299" RangeMax="2.449489742783178">
|
||||
AQAAAACAAADwAAAAagAAAA==eF5jYMAGPuyXOV4IRHvsIfQZe8u+xxZ9j1/sh/Eh9B37IjDj4f5QMLhqD6Gf2odB+Pth6iD0G3sFiLn7ofqg+j/CxOH6IfRX+xCouRYQ+6H0D/sCqH6YuRD6D1wd1B9QmsEBxgcAJsNfhw==
|
||||
<InformationKey name="L2_NORM_RANGE" location="vtkDataArray" length="2">
|
||||
<Value index="0">
|
||||
0.7453559925
|
||||
</Value>
|
||||
<Value index="1">
|
||||
2.4494897428
|
||||
</Value>
|
||||
</InformationKey>
|
||||
</DataArray>
|
||||
</Points>
|
||||
<Verts>
|
||||
<DataArray type="Int64" Name="connectivity" format="binary" RangeMin="1e+299" RangeMax="-1e+299">
|
||||
AAAAAACAAAAAAAAA
|
||||
</DataArray>
|
||||
<DataArray type="Int64" Name="offsets" format="binary" RangeMin="1e+299" RangeMax="-1e+299">
|
||||
AAAAAACAAAAAAAAA
|
||||
</DataArray>
|
||||
</Verts>
|
||||
<Lines>
|
||||
<DataArray type="Int64" Name="connectivity" format="binary" RangeMin="1e+299" RangeMax="-1e+299">
|
||||
AAAAAACAAAAAAAAA
|
||||
</DataArray>
|
||||
<DataArray type="Int64" Name="offsets" format="binary" RangeMin="1e+299" RangeMax="-1e+299">
|
||||
AAAAAACAAAAAAAAA
|
||||
</DataArray>
|
||||
</Lines>
|
||||
<Strips>
|
||||
<DataArray type="Int64" Name="connectivity" format="binary" RangeMin="1e+299" RangeMax="-1e+299">
|
||||
AAAAAACAAAAAAAAA
|
||||
</DataArray>
|
||||
<DataArray type="Int64" Name="offsets" format="binary" RangeMin="1e+299" RangeMax="-1e+299">
|
||||
AAAAAACAAAAAAAAA
|
||||
</DataArray>
|
||||
</Strips>
|
||||
<Polys>
|
||||
<DataArray type="Int64" Name="connectivity" format="binary" RangeMin="1e+299" RangeMax="-1e+299">
|
||||
AAAAAACAAAAAAAAA
|
||||
</DataArray>
|
||||
<DataArray type="Int64" Name="offsets" format="binary" RangeMin="1e+299" RangeMax="-1e+299">
|
||||
AAAAAACAAAAAAAAA
|
||||
</DataArray>
|
||||
</Polys>
|
||||
</Piece>
|
||||
</PolyData>
|
||||
</VTKFile>
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0"?>
|
||||
<VTKFile type="RectilinearGrid" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
|
||||
<RectilinearGrid WholeExtent="0 5 0 6 0 7">
|
||||
<Piece Extent="0 5 0 6 0 7">
|
||||
<PointData>
|
||||
<DataArray type="Float64" Name="node" NumberOfComponents="3" format="binary" RangeMin="0" RangeMax="1.268857754044952">
|
||||
AQAAAACAAACAHwAAywMAAA==eF51mTGKVUEQRX88izByB8byY0MDlyG4CTfgFswMDWQigw8/Ejr40E7woGkYXqLJW4LDb8qmz71VDDjvWMGhijvd0KeTr8dXn/++f/x59rwIf3j6+untw1PS34S/udez8KgP97r+///w8bwIDx/f34SHD3nU4DXxIS/CVx/2N+GrTxWfUV18PC/C132xvwlf9zV51PDck/mQF+HrfNjfhK/z2cXn273+iI/nRXj4+P4mPHzI1zqSfZEX4eu+2N+Er/uanPXl9buXn+9n5n3lRTjzvvY34cx78Pgee7ye6eN5Ec6804ecefc+NfEhL8KZd+9TE58qPqO6+HhehDPv9CFn3v189mQ+5EU48+7ns4sPefhE7ujjeRHOvNOHnHmnz6gj2Rd5Ec6804ecefc+kbtLkvcLfCb3eb/AZ3Kf90uS9+njOfN+SfI+fch93ulTEx9y5p0+7Gfe6VPFZ1QXH8+Zd+6L/cw799XFZ3ju4uM58875sJ9553x28VlzN308Z94vSd6nD7nPO/d1iI/nzDv3xX7mnfs6Ep/Tafvx8eXnl+R95UU48772N+HMe/D4Hnu8nunjeRHOvNOHnHn3PjXxIS/CmXfvUxOfKj6juvh4XoQz7/QhZ979fPZkPuRFOPPu57OLD3n4RO7o43kRzrzTh5x5p8+oI9kXeRHOvNOHnHn3PnHO3iTvK+f5fkvO9xt8Jmfeg8f32GOcs9PHc57vN8k7fciZd+9TEx9ynu/0YT/Pd/pU8RnVxcdznu/cF/t5vnNfXXyG5y4+nvN853zYz/Od89nFZz1np4/nPN9vknf6kDPv9Bl1iI/nPN+5L/bzfOe+jsTndLr/Gdh+S95XXoQz72t/E868B4/vscfrmT6eF+HMO33ImXfvUxMf8iKcefc+NfGp4jOqi4/nRTjzTh9y5t3PZ0/mQ16EM+9+Prv4kIdP5I4+nhfhzDt9yJl3+ow6kn2RF+HMO33ImXfvE/fqTfK+ct7nt+Q+v8FncuY9eHyPPca9evp4zvv8JnmnDznz7n1q4kPO+zx92M/7PH2q+Izq4uM57/PcF/t5n+e+uvgMz118POd9nvNhP+/znM8uPpE7+njO+/wmeacPOfNOn1GH+HjO+zz3xX7e57mvI/GJ6pL3lfM9rkve1/4mnHkPHr+NPca72PTxnO9xXfK+9jfhzLv3qYkPOd/j6MP+Jpx5p8/6zX2R8z2O+2J/E868r//yPY7zIed7HOfD/iaceadP5I4+nvM9rkve6UPOvNNn1CE+nvM9jvtifxPOvAf/B5cwXsg=
|
||||
<InformationKey name="L2_NORM_RANGE" location="vtkDataArray" length="2">
|
||||
<Value index="0">
|
||||
0
|
||||
</Value>
|
||||
<Value index="1">
|
||||
1.268857754
|
||||
</Value>
|
||||
</InformationKey>
|
||||
</DataArray>
|
||||
</PointData>
|
||||
<CellData>
|
||||
<DataArray type="Float64" Name="cell" NumberOfComponents="3" format="binary" RangeMin="0.10871961482881586" RangeMax="1.160792402743735">
|
||||
AQAAAACAAACwEwAAZQIAAA==eF511r2KFEEYRmHjjY2N9Ao0lQ79yQy8jBVjc29gL0Ezhc1maDBfU0FB3NVgNyqQuged1leZ56sqBpo5HRx4+wS13nn989l6vjzfzm45u/vk9+/NcvL17cuHJx8Lf3D/cD4XfvPq9vmj68vCH19vLwpf/3pvbedT8crjlccrj1ce77vtXBavPF55vPJ45fG+3/hN8crjlccrj1d+vHOb7NyKV368cyte+XrUVZ901YtXftxVL175Ss/f96dX+9MPpedwew6353B7DrdnvXJ71iu3Z73pTa/cnvXK7VlvetMrt2e9cnse79wmO7fildvzeOdWvOlt3FUvXrk9j7vqE+9uWQ/46qL0HG7P4fYcbs/h9qxXbs965fasN73plduzXrk9601veuX2rFduz+Od22TnVrxyex7v3Io3vY276sUrt+dxV33i3f37/vYcbs/h9hxuz+H2rFduz3rl9pynPYfbs165PeuV27NeuT3rlduz3j//22TnVrxyew6353B7DrdnvXJ71iu353uHa8jZl9JzuD2H23O4PYfbs165PeuV27Pe9KZXbs965fasN73plduzXrk9j3duk51b8crtebxzK970Nu6qF6/cnsdd9Yl3tzzdLtbfSs/h9hxuz+H2HG7PeuX2rFduz3rTm165PeuV27Pe9KZXbs965fY83rlNdm7FK7fn8c6teNPbuKtevHJ7HnfVJ97d8uJwDdn/KD2H23O4PYfbc7g965Xbs165PetNb3rl9qxXbs9605teuT3rldvzeOc22bkVr9yexzu34k1v46568crtedzVf/4LDINsdg==
|
||||
<InformationKey name="L2_NORM_RANGE" location="vtkDataArray" length="2">
|
||||
<Value index="0">
|
||||
0.10871961483
|
||||
</Value>
|
||||
<Value index="1">
|
||||
1.1607924027
|
||||
</Value>
|
||||
</InformationKey>
|
||||
</DataArray>
|
||||
</CellData>
|
||||
<Coordinates>
|
||||
<DataArray type="Float64" Name="x" format="binary" RangeMin="0" RangeMax="0.6">
|
||||
AQAAAACAAAAwAAAAJwAAAA==eF5jYICAHXKtrwN37LOH0Ofsua4vLrDlug7l37M3BoPH9gCdQxK6
|
||||
</DataArray>
|
||||
<DataArray type="Float64" Name="y" format="binary" RangeMin="0" RangeMax="1">
|
||||
AQAAAACAAAA4AAAAIgAAAA==eF5jYICAUDA4ag+hr9pDRB9A+U/tV4HBK6j4B3sAk7wQqg==
|
||||
</DataArray>
|
||||
<DataArray type="Float64" Name="z" format="binary" RangeMin="0" RangeMax="0.5">
|
||||
AQAAAACAAABAAAAALAAAAA==eF5jYICASSqeQLTJHkIfsr+9LReITkP5l+zB3NvXoOK37SG6HtgDANusGUo=
|
||||
</DataArray>
|
||||
</Coordinates>
|
||||
</Piece>
|
||||
</RectilinearGrid>
|
||||
</VTKFile>
|
|
@ -1,14 +1,16 @@
|
|||
import os
|
||||
import filecmp
|
||||
import time
|
||||
|
||||
import pytest
|
||||
import numpy as np
|
||||
|
||||
from damask import VTK
|
||||
from damask import grid_filters
|
||||
|
||||
@pytest.fixture
|
||||
def reference_dir(reference_dir_base):
|
||||
"""Directory containing reference results."""
|
||||
return os.path.join(reference_dir_base,'Result')
|
||||
return reference_dir_base/'VTK'
|
||||
|
||||
class TestVTK:
|
||||
|
||||
|
@ -18,22 +20,22 @@ class TestVTK:
|
|||
origin = np.random.random(3)
|
||||
v = VTK.from_rectilinearGrid(grid,size,origin)
|
||||
string = v.__repr__()
|
||||
v.write(os.path.join(tmp_path,'rectilinearGrid'))
|
||||
vtr = VTK.from_file(os.path.join(tmp_path,'rectilinearGrid.vtr'))
|
||||
with open(os.path.join(tmp_path,'rectilinearGrid.vtk'),'w') as f:
|
||||
v.write(tmp_path/'rectilinearGrid')
|
||||
vtr = VTK.from_file(tmp_path/'rectilinearGrid.vtr')
|
||||
with open(tmp_path/'rectilinearGrid.vtk','w') as f:
|
||||
f.write(string)
|
||||
vtk = VTK.from_file(os.path.join(tmp_path,'rectilinearGrid.vtk'),'VTK_rectilinearGrid')
|
||||
vtk = VTK.from_file(tmp_path/'rectilinearGrid.vtk','VTK_rectilinearGrid')
|
||||
assert(string == vtr.__repr__() == vtk.__repr__())
|
||||
|
||||
def test_polyData(self,tmp_path):
|
||||
points = np.random.rand(3,100)
|
||||
v = VTK.from_polyData(points)
|
||||
string = v.__repr__()
|
||||
v.write(os.path.join(tmp_path,'polyData'))
|
||||
vtp = VTK.from_file(os.path.join(tmp_path,'polyData.vtp'))
|
||||
with open(os.path.join(tmp_path,'polyData.vtk'),'w') as f:
|
||||
v.write(tmp_path/'polyData')
|
||||
vtp = VTK.from_file(tmp_path/'polyData.vtp')
|
||||
with open(tmp_path/'polyData.vtk','w') as f:
|
||||
f.write(string)
|
||||
vtk = VTK.from_file(os.path.join(tmp_path,'polyData.vtk'),'polyData')
|
||||
vtk = VTK.from_file(tmp_path/'polyData.vtk','polyData')
|
||||
assert(string == vtp.__repr__() == vtk.__repr__())
|
||||
|
||||
@pytest.mark.parametrize('cell_type,n',[
|
||||
|
@ -48,11 +50,11 @@ class TestVTK:
|
|||
connectivity = np.random.choice(np.arange(n),n,False).reshape(-1,n)
|
||||
v = VTK.from_unstructuredGrid(nodes,connectivity,cell_type)
|
||||
string = v.__repr__()
|
||||
v.write(os.path.join(tmp_path,'unstructuredGrid'))
|
||||
vtu = VTK.from_file(os.path.join(tmp_path,'unstructuredGrid.vtu'))
|
||||
with open(os.path.join(tmp_path,'unstructuredGrid.vtk'),'w') as f:
|
||||
v.write(tmp_path/'unstructuredGrid')
|
||||
vtu = VTK.from_file(tmp_path/'unstructuredGrid.vtu')
|
||||
with open(tmp_path/'unstructuredGrid.vtk','w') as f:
|
||||
f.write(string)
|
||||
vtk = VTK.from_file(os.path.join(tmp_path,'unstructuredGrid.vtk'),'unstructuredgrid')
|
||||
vtk = VTK.from_file(tmp_path/'unstructuredGrid.vtk','unstructuredgrid')
|
||||
assert(string == vtu.__repr__() == vtk.__repr__())
|
||||
|
||||
@pytest.mark.parametrize('name,dataset_type',[('this_file_does_not_exist.vtk',None),
|
||||
|
@ -61,3 +63,31 @@ class TestVTK:
|
|||
def test_invalid_dataset_type(self,dataset_type,name):
|
||||
with pytest.raises(TypeError):
|
||||
VTK.from_file('this_file_does_not_exist.vtk',dataset_type)
|
||||
|
||||
|
||||
def test_compare_reference_polyData(self,update,reference_dir,tmp_path):
|
||||
points=np.dstack((np.linspace(0.,1.,10),np.linspace(0.,2.,10),np.linspace(-1.,1.,10))).squeeze()
|
||||
polyData = VTK.from_polyData(points)
|
||||
polyData.add(points,'coordinates')
|
||||
if update:
|
||||
polyData.write(reference_dir/'polyData')
|
||||
else:
|
||||
polyData.write(tmp_path/'polyData')
|
||||
time.sleep(.5)
|
||||
assert filecmp.cmp(tmp_path/'polyData.vtp',reference_dir/'polyData.vtp')
|
||||
|
||||
def test_compare_reference_rectilinearGrid(self,update,reference_dir,tmp_path):
|
||||
grid = np.array([5,6,7],int)
|
||||
size = np.array([.6,1.,.5])
|
||||
rectilinearGrid = VTK.from_rectilinearGrid(grid,size)
|
||||
c = grid_filters.cell_coord0(grid,size).reshape(-1,3,order='F')
|
||||
n = grid_filters.node_coord0(grid,size).reshape(-1,3,order='F')
|
||||
rectilinearGrid.add(c,'cell')
|
||||
rectilinearGrid.add(n,'node')
|
||||
if update:
|
||||
rectilinearGrid.write(reference_dir/'rectilinearGrid')
|
||||
else:
|
||||
rectilinearGrid.write(tmp_path/'rectilinearGrid')
|
||||
time.sleep(.5)
|
||||
assert filecmp.cmp(tmp_path/'rectilinearGrid.vtr',reference_dir/'rectilinearGrid.vtr')
|
||||
|
||||
|
|
Loading…
Reference in New Issue