Merge branch 'github-actions' into 'development'
Using GitHub actions for additional testing See merge request damask/DAMASK!435
This commit is contained in:
commit
af1e27379b
|
@ -0,0 +1,46 @@
|
||||||
|
name: Test Python Library
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
pip:
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
python-version: [3.7, 3.8, 3.9]
|
||||||
|
os: [ubuntu-latest, macos-latest]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install pytest pandas scipy h5py vtk matplotlib pyyaml
|
||||||
|
- name: Install and run unit tests
|
||||||
|
run: |
|
||||||
|
python -m pip install ./python --no-deps -vv --use-feature=in-tree-build
|
||||||
|
COLUMNS=256 pytest python
|
||||||
|
|
||||||
|
apt:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Install pytest
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install pytest
|
||||||
|
- name: Install dependencies
|
||||||
|
run: >
|
||||||
|
sudo apt-get update &&
|
||||||
|
sudo apt-get install python3-pip python3-pytest python3-pandas python3-scipy
|
||||||
|
python3-h5py python3-vtk7 python3-matplotlib python3-yaml -y
|
||||||
|
- name: Run unit tests
|
||||||
|
run: |
|
||||||
|
export PYTHONPATH=${PWD}/python
|
||||||
|
COLUMNS=256 python -m pytest python
|
|
@ -121,7 +121,7 @@ class VTK:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
vtk_nodes = vtk.vtkPoints()
|
vtk_nodes = vtk.vtkPoints()
|
||||||
vtk_nodes.SetData(np_to_vtk(nodes))
|
vtk_nodes.SetData(np_to_vtk(np.ascontiguousarray(nodes)))
|
||||||
cells = vtk.vtkCellArray()
|
cells = vtk.vtkCellArray()
|
||||||
cells.SetNumberOfCells(connectivity.shape[0])
|
cells.SetNumberOfCells(connectivity.shape[0])
|
||||||
T = np.concatenate((np.ones((connectivity.shape[0],1),dtype=np.int64)*connectivity.shape[1],
|
T = np.concatenate((np.ones((connectivity.shape[0],1),dtype=np.int64)*connectivity.shape[1],
|
||||||
|
@ -157,7 +157,7 @@ class VTK:
|
||||||
"""
|
"""
|
||||||
N = points.shape[0]
|
N = points.shape[0]
|
||||||
vtk_points = vtk.vtkPoints()
|
vtk_points = vtk.vtkPoints()
|
||||||
vtk_points.SetData(np_to_vtk(points))
|
vtk_points.SetData(np_to_vtk(np.ascontiguousarray(points)))
|
||||||
|
|
||||||
vtk_cells = vtk.vtkCellArray()
|
vtk_cells = vtk.vtkCellArray()
|
||||||
vtk_cells.SetNumberOfCells(N)
|
vtk_cells.SetNumberOfCells(N)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import pytest
|
import pytest
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import vtk
|
||||||
|
|
||||||
from damask import VTK
|
from damask import VTK
|
||||||
from damask import Grid
|
from damask import Grid
|
||||||
|
@ -410,6 +411,7 @@ class TestGrid:
|
||||||
|
|
||||||
@pytest.mark.parametrize('periodic',[True,False])
|
@pytest.mark.parametrize('periodic',[True,False])
|
||||||
@pytest.mark.parametrize('direction',['x','y','z',['x','y'],'zy','xz',['x','y','z']])
|
@pytest.mark.parametrize('direction',['x','y','z',['x','y'],'zy','xz',['x','y','z']])
|
||||||
|
@pytest.mark.xfail(int(vtk.vtkVersion.GetVTKVersion().split('.')[0])<8, reason='missing METADATA')
|
||||||
def test_get_grain_boundaries(self,update,ref_path,periodic,direction):
|
def test_get_grain_boundaries(self,update,ref_path,periodic,direction):
|
||||||
grid = Grid.load(ref_path/'get_grain_boundaries_8g12x15x20.vti')
|
grid = Grid.load(ref_path/'get_grain_boundaries_8g12x15x20.vti')
|
||||||
current = grid.get_grain_boundaries(periodic,direction)
|
current = grid.get_grain_boundaries(periodic,direction)
|
||||||
|
|
|
@ -18,6 +18,7 @@ from damask import tensor
|
||||||
from damask import mechanics
|
from damask import mechanics
|
||||||
from damask import grid_filters
|
from damask import grid_filters
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def default(tmp_path,ref_path):
|
def default(tmp_path,ref_path):
|
||||||
"""Small Result file in temp location for modification."""
|
"""Small Result file in temp location for modification."""
|
||||||
|
@ -108,7 +109,7 @@ class TestResult:
|
||||||
assert np.allclose(in_memory,in_file)
|
assert np.allclose(in_memory,in_file)
|
||||||
|
|
||||||
@pytest.mark.parametrize('mode',
|
@pytest.mark.parametrize('mode',
|
||||||
['direct',pytest.param('function',marks=pytest.mark.xfail(sys.platform=="darwin",reason='n/a'))])
|
['direct',pytest.param('function',marks=pytest.mark.xfail(sys.platform=='darwin',reason='n/a'))])
|
||||||
def test_add_calculation(self,default,tmp_path,mode):
|
def test_add_calculation(self,default,tmp_path,mode):
|
||||||
|
|
||||||
if mode == 'direct':
|
if mode == 'direct':
|
||||||
|
@ -374,6 +375,7 @@ class TestResult:
|
||||||
@pytest.mark.parametrize('output',['F','*',['P'],['P','F']],ids=range(4))
|
@pytest.mark.parametrize('output',['F','*',['P'],['P','F']],ids=range(4))
|
||||||
@pytest.mark.parametrize('fname',['12grains6x7x8_tensionY.hdf5'],ids=range(1))
|
@pytest.mark.parametrize('fname',['12grains6x7x8_tensionY.hdf5'],ids=range(1))
|
||||||
@pytest.mark.parametrize('inc',[4,0],ids=range(2))
|
@pytest.mark.parametrize('inc',[4,0],ids=range(2))
|
||||||
|
@pytest.mark.xfail(int(vtk.vtkVersion.GetVTKVersion().split('.')[0])<9, reason='missing "Direction" attribute')
|
||||||
def test_vtk(self,request,tmp_path,ref_path,update,patch_execution_stamp,patch_datetime_now,output,fname,inc):
|
def test_vtk(self,request,tmp_path,ref_path,update,patch_execution_stamp,patch_datetime_now,output,fname,inc):
|
||||||
result = Result(ref_path/fname).view('increments',inc)
|
result = Result(ref_path/fname).view('increments',inc)
|
||||||
os.chdir(tmp_path)
|
os.chdir(tmp_path)
|
||||||
|
@ -425,7 +427,8 @@ class TestResult:
|
||||||
|
|
||||||
assert sorted(open(tmp_path/fname).read()) == sorted(open(ref_path/fname).read()) # XML is not ordered
|
assert sorted(open(tmp_path/fname).read()) == sorted(open(ref_path/fname).read()) # XML is not ordered
|
||||||
|
|
||||||
@pytest.mark.skipif(not hasattr(vtk,'vtkXdmfReader'),reason='https://discourse.vtk.org/t/2450')
|
@pytest.mark.skipif(not (hasattr(vtk,'vtkXdmfReader') and hasattr(vtk.vtkXdmfReader(),'GetOutput')),
|
||||||
|
reason='https://discourse.vtk.org/t/2450')
|
||||||
def test_XDMF_shape(self,tmp_path,single_phase):
|
def test_XDMF_shape(self,tmp_path,single_phase):
|
||||||
os.chdir(tmp_path)
|
os.chdir(tmp_path)
|
||||||
|
|
||||||
|
@ -437,19 +440,14 @@ class TestResult:
|
||||||
dim_xdmf = reader_xdmf.GetOutput().GetDimensions()
|
dim_xdmf = reader_xdmf.GetOutput().GetDimensions()
|
||||||
bounds_xdmf = reader_xdmf.GetOutput().GetBounds()
|
bounds_xdmf = reader_xdmf.GetOutput().GetBounds()
|
||||||
|
|
||||||
single_phase.view('increments',0).export_VTK()
|
single_phase.view('increments',0).export_VTK(parallel=False)
|
||||||
fname = os.path.splitext(os.path.basename(single_phase.fname))[0]+'_inc00.vti'
|
fname = os.path.splitext(os.path.basename(single_phase.fname))[0]+'_inc00.vti'
|
||||||
for i in range(10): # waiting for parallel IO
|
reader_vti = vtk.vtkXMLImageDataReader()
|
||||||
reader_vti = vtk.vtkXMLImageDataReader()
|
reader_vti.SetFileName(fname)
|
||||||
reader_vti.SetFileName(fname)
|
reader_vti.Update()
|
||||||
reader_vti.Update()
|
dim_vti = reader_vti.GetOutput().GetDimensions()
|
||||||
dim_vti = reader_vti.GetOutput().GetDimensions()
|
bounds_vti = reader_vti.GetOutput().GetBounds()
|
||||||
bounds_vti = reader_vti.GetOutput().GetBounds()
|
assert dim_vti == dim_xdmf and bounds_vti == bounds_xdmf
|
||||||
if dim_vti == dim_xdmf and bounds_vti == bounds_xdmf:
|
|
||||||
return
|
|
||||||
time.sleep(.5)
|
|
||||||
|
|
||||||
assert False
|
|
||||||
|
|
||||||
def test_XDMF_invalid(self,default):
|
def test_XDMF_invalid(self,default):
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
|
|
|
@ -5,6 +5,7 @@ import time
|
||||||
import pytest
|
import pytest
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import numpy.ma as ma
|
import numpy.ma as ma
|
||||||
|
import vtk
|
||||||
|
|
||||||
from damask import VTK
|
from damask import VTK
|
||||||
from damask import grid_filters
|
from damask import grid_filters
|
||||||
|
@ -162,6 +163,7 @@ class TestVTK:
|
||||||
new = VTK.load(tmp_path/'with_comments.vtr')
|
new = VTK.load(tmp_path/'with_comments.vtr')
|
||||||
assert new.get_comments() == ['this is a comment']
|
assert new.get_comments() == ['this is a comment']
|
||||||
|
|
||||||
|
@pytest.mark.xfail(int(vtk.vtkVersion.GetVTKVersion().split('.')[0])<8, reason='missing METADATA')
|
||||||
def test_compare_reference_polyData(self,update,ref_path,tmp_path):
|
def test_compare_reference_polyData(self,update,ref_path,tmp_path):
|
||||||
points=np.dstack((np.linspace(0.,1.,10),np.linspace(0.,2.,10),np.linspace(-1.,1.,10))).squeeze()
|
points=np.dstack((np.linspace(0.,1.,10),np.linspace(0.,2.,10),np.linspace(-1.,1.,10))).squeeze()
|
||||||
polyData = VTK.from_poly_data(points)
|
polyData = VTK.from_poly_data(points)
|
||||||
|
@ -173,14 +175,15 @@ class TestVTK:
|
||||||
assert polyData.__repr__() == reference.__repr__() and \
|
assert polyData.__repr__() == reference.__repr__() and \
|
||||||
np.allclose(polyData.get('coordinates'),points)
|
np.allclose(polyData.get('coordinates'),points)
|
||||||
|
|
||||||
|
@pytest.mark.xfail(int(vtk.vtkVersion.GetVTKVersion().split('.')[0])<8, reason='missing METADATA')
|
||||||
def test_compare_reference_rectilinearGrid(self,update,ref_path,tmp_path):
|
def test_compare_reference_rectilinearGrid(self,update,ref_path,tmp_path):
|
||||||
cells = np.array([5,6,7],int)
|
cells = np.array([5,6,7],int)
|
||||||
size = np.array([.6,1.,.5])
|
size = np.array([.6,1.,.5])
|
||||||
rectilinearGrid = VTK.from_rectilinear_grid(cells,size)
|
rectilinearGrid = VTK.from_rectilinear_grid(cells,size)
|
||||||
c = grid_filters.coordinates0_point(cells,size).reshape(-1,3,order='F')
|
c = grid_filters.coordinates0_point(cells,size).reshape(-1,3,order='F')
|
||||||
n = grid_filters.coordinates0_node(cells,size).reshape(-1,3,order='F')
|
n = grid_filters.coordinates0_node(cells,size).reshape(-1,3,order='F')
|
||||||
rectilinearGrid.add(c,'cell')
|
rectilinearGrid.add(np.ascontiguousarray(c),'cell')
|
||||||
rectilinearGrid.add(n,'node')
|
rectilinearGrid.add(np.ascontiguousarray(n),'node')
|
||||||
if update:
|
if update:
|
||||||
rectilinearGrid.save(ref_path/'rectilinearGrid')
|
rectilinearGrid.save(ref_path/'rectilinearGrid')
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue