From 8d5a72e9364a1f1d4ae6a55dc7a7d84a65d4b7cd Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 27 Jun 2020 23:37:46 +0200 Subject: [PATCH] more test, swich to pathlib --- python/tests/conftest.py | 4 +- python/tests/reference/VTK/polyData.vtp | 67 +++++++++++++++++++ .../tests/reference/VTK/rectilinearGrid.vtr | 44 ++++++++++++ python/tests/test_VTK.py | 58 ++++++++++++---- 4 files changed, 157 insertions(+), 16 deletions(-) create mode 100644 python/tests/reference/VTK/polyData.vtp create mode 100644 python/tests/reference/VTK/rectilinearGrid.vtr diff --git a/python/tests/conftest.py b/python/tests/conftest.py index 411c07a8c..2a46bc815 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -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' diff --git a/python/tests/reference/VTK/polyData.vtp b/python/tests/reference/VTK/polyData.vtp new file mode 100644 index 000000000..e93e90f58 --- /dev/null +++ b/python/tests/reference/VTK/polyData.vtp @@ -0,0 +1,67 @@ + + + + + + + AQAAAACAAADwAAAAagAAAA==eF5jYMAGPuyXOV4IRHvsIfQZe8u+xxZ9j1/sh/Eh9B37IjDj4f5QMLhqD6Gf2odB+Pth6iD0G3sFiLn7ofqg+j/CxOH6IfRX+xCouRYQ+6H0D/sCqH6YuRD6D1wd1B9QmsEBxgcAJsNfhw== + + + 0.7453559925 + + + 2.4494897428 + + + + + + + + + AQAAAACAAADwAAAAagAAAA==eF5jYMAGPuyXOV4IRHvsIfQZe8u+xxZ9j1/sh/Eh9B37IjDj4f5QMLhqD6Gf2odB+Pth6iD0G3sFiLn7ofqg+j/CxOH6IfRX+xCouRYQ+6H0D/sCqH6YuRD6D1wd1B9QmsEBxgcAJsNfhw== + + + 0.7453559925 + + + 2.4494897428 + + + + + + + AAAAAACAAAAAAAAA + + + AAAAAACAAAAAAAAA + + + + + AAAAAACAAAAAAAAA + + + AAAAAACAAAAAAAAA + + + + + AAAAAACAAAAAAAAA + + + AAAAAACAAAAAAAAA + + + + + AAAAAACAAAAAAAAA + + + AAAAAACAAAAAAAAA + + + + + diff --git a/python/tests/reference/VTK/rectilinearGrid.vtr b/python/tests/reference/VTK/rectilinearGrid.vtr new file mode 100644 index 000000000..3e965bd2e --- /dev/null +++ b/python/tests/reference/VTK/rectilinearGrid.vtr @@ -0,0 +1,44 @@ + + + + + + + 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= + + + 0 + + + 1.268857754 + + + + + + + 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== + + + 0.10871961483 + + + 1.1607924027 + + + + + + + AQAAAACAAAAwAAAAJwAAAA==eF5jYICAHXKtrwN37LOH0Ofsua4vLrDlug7l37M3BoPH9gCdQxK6 + + + AQAAAACAAAA4AAAAIgAAAA==eF5jYICAUDA4ag+hr9pDRB9A+U/tV4HBK6j4B3sAk7wQqg== + + + AQAAAACAAABAAAAALAAAAA==eF5jYICASSqeQLTJHkIfsr+9LReITkP5l+zB3NvXoOK37SG6HtgDANusGUo= + + + + + diff --git a/python/tests/test_VTK.py b/python/tests/test_VTK.py index 8795e7161..2b15dcd78 100644 --- a/python/tests/test_VTK.py +++ b/python/tests/test_VTK.py @@ -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') +