Merge branch 'GitHub-Actions-Windows' into 'development'

test python library on Windows

See merge request damask/DAMASK!554
This commit is contained in:
Martin Diehl 2022-03-27 06:20:10 +00:00
commit 2dfde6997b
12 changed files with 41 additions and 24 deletions

View File

@ -10,7 +10,7 @@ jobs:
strategy: strategy:
matrix: matrix:
python-version: ['3.8', '3.9'] #, '3.10'] python-version: ['3.8', '3.9'] #, '3.10']
os: [ubuntu-latest, macos-latest] os: [ubuntu-latest, macos-latest, windows-latest]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -25,11 +25,18 @@ jobs:
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install pytest pandas scipy h5py vtk matplotlib pyyaml pip install pytest pandas scipy h5py vtk matplotlib pyyaml
- name: Install and run unit tests - name: Install and run unit tests (Unix)
if: runner.os != 'Windows'
run: | run: |
python -m pip install ./python --no-deps -vv --use-feature=in-tree-build python -m pip install ./python --no-deps -vv --use-feature=in-tree-build
COLUMNS=256 pytest python COLUMNS=256 pytest python
- name: Install and run unit tests (Windows)
if: runner.os == 'Windows'
run: |
python -m pip install ./python --no-deps -vv --use-feature=in-tree-build
pytest python -k 'not XDMF'
apt: apt:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -144,7 +144,7 @@ class Config(dict):
Configuration from file. Configuration from file.
""" """
fhandle = open(Path(fname).expanduser()) if isinstance(fname, (str, Path)) else \ fhandle = open(Path(fname).expanduser(),newline='\n') if isinstance(fname, (str, Path)) else \
fname fname
return cls(yaml.safe_load(fhandle)) return cls(yaml.safe_load(fhandle))

View File

@ -754,8 +754,8 @@ class Grid:
# materials: 1 # materials: 1
""" """
offset_ = np.array(offset,int) if offset is not None else np.zeros(3,int) offset_ = np.array(offset,np.int64) if offset is not None else np.zeros(3,np.int64)
cells_ = np.array(cells,int) if cells is not None else self.cells cells_ = np.array(cells,np.int64) if cells is not None else self.cells
canvas = np.full(cells_,np.nanmax(self.material) + 1 if fill is None else fill,self.material.dtype) canvas = np.full(cells_,np.nanmax(self.material) + 1 if fill is None else fill,self.material.dtype)
@ -797,7 +797,7 @@ class Grid:
>>> import numpy as np >>> import numpy as np
>>> import damask >>> import damask
>>> g = damask.Grid(np.zeros([32]*3,int), np.ones(3)*1e-4) >>> g = damask.Grid(np.zeros([32]*3,int),np.ones(3)*1e-4)
>>> g.mirror('xy',True) >>> g.mirror('xy',True)
cells : 64 x 64 x 32 cells : 64 x 64 x 32
size : 0.0002 x 0.0002 x 0.0001 size : 0.0002 x 0.0002 x 0.0001

View File

@ -1803,7 +1803,7 @@ class Result:
if type(obj) == h5py.Dataset and _match(output,[name]): if type(obj) == h5py.Dataset and _match(output,[name]):
d = obj.attrs['description'] if h5py3 else obj.attrs['description'].decode() d = obj.attrs['description'] if h5py3 else obj.attrs['description'].decode()
if not Path(name).exists() or overwrite: if not Path(name).exists() or overwrite:
with open(name,'w') as f_out: f_out.write(obj[0].decode()) with open(name,'w',newline='\n') as f_out: f_out.write(obj[0].decode())
print(f'Exported {d} to "{name}".') print(f'Exported {d} to "{name}".')
else: else:
print(f'"{name}" exists, {d} not exported.') print(f'"{name}" exists, {d} not exported.')

View File

@ -260,7 +260,7 @@ class Table:
Table data from file. Table data from file.
""" """
f = open(Path(fname).expanduser()) if isinstance(fname, (str, Path)) else fname f = open(Path(fname).expanduser(),newline='\n') if isinstance(fname, (str, Path)) else fname
f.seek(0) f.seek(0)
comments = [] comments = []
@ -281,7 +281,7 @@ class Table:
else: else:
shapes[label] = (1,) shapes[label] = (1,)
data = pd.read_csv(f,names=list(range(len(labels))),sep=r'\s+') data = pd.read_csv(f,names=list(range(len(labels))),sep=r'\s+',lineterminator='\n')
return Table(shapes,data,comments) return Table(shapes,data,comments)
@ -312,7 +312,7 @@ class Table:
Table data from file. Table data from file.
""" """
f = open(fname) if isinstance(fname, (str, Path)) else fname f = open(Path(fname).expanduser(),newline='\n') if isinstance(fname, (str, Path)) else fname
f.seek(0) f.seek(0)
content = f.readlines() content = f.readlines()
@ -597,4 +597,4 @@ class Table:
f = open(Path(fname).expanduser(),'w',newline='\n') if isinstance(fname, (str, Path)) else fname f = open(Path(fname).expanduser(),'w',newline='\n') if isinstance(fname, (str, Path)) else fname
f.write('\n'.join([f'# {c}' for c in self.comments] + [' '.join(labels)])+('\n' if labels else '')) f.write('\n'.join([f'# {c}' for c in self.comments] + [' '.join(labels)])+('\n' if labels else ''))
self.data.to_csv(f,sep=' ',na_rep='nan',index=False,header=False) self.data.to_csv(f,sep=' ',na_rep='nan',index=False,header=False,line_terminator='\n')

View File

@ -159,8 +159,8 @@ def coordinates0_point(cells: _IntSequence,
""" """
size_ = _np.array(size,float) size_ = _np.array(size,float)
start = origin + size_/_np.array(cells,int)*.5 start = origin + size_/_np.array(cells,_np.int64)*.5
end = origin + size_ - size_/_np.array(cells,int)*.5 end = origin + size_ - size_/_np.array(cells,_np.int64)*.5
return _np.stack(_np.meshgrid(_np.linspace(start[0],end[0],cells[0]), return _np.stack(_np.meshgrid(_np.linspace(start[0],end[0],cells[0]),
_np.linspace(start[1],end[1],cells[1]), _np.linspace(start[1],end[1],cells[1]),
@ -290,7 +290,7 @@ def cellsSizeOrigin_coordinates0_point(coordinates0: _np.ndarray,
coords = [_np.unique(coordinates0[:,i]) for i in range(3)] coords = [_np.unique(coordinates0[:,i]) for i in range(3)]
mincorner = _np.array(list(map(min,coords))) mincorner = _np.array(list(map(min,coords)))
maxcorner = _np.array(list(map(max,coords))) maxcorner = _np.array(list(map(max,coords)))
cells = _np.array(list(map(len,coords)),int) cells = _np.array(list(map(len,coords)),_np.int64)
size = cells/_np.maximum(cells-1,1) * (maxcorner-mincorner) size = cells/_np.maximum(cells-1,1) * (maxcorner-mincorner)
delta = size/cells delta = size/cells
origin = mincorner - delta*.5 origin = mincorner - delta*.5
@ -455,7 +455,7 @@ def cellsSizeOrigin_coordinates0_node(coordinates0: _np.ndarray,
coords = [_np.unique(coordinates0[:,i]) for i in range(3)] coords = [_np.unique(coordinates0[:,i]) for i in range(3)]
mincorner = _np.array(list(map(min,coords))) mincorner = _np.array(list(map(min,coords)))
maxcorner = _np.array(list(map(max,coords))) maxcorner = _np.array(list(map(max,coords)))
cells = _np.array(list(map(len,coords)),int) - 1 cells = _np.array(list(map(len,coords)),_np.int64) - 1
size = maxcorner-mincorner size = maxcorner-mincorner
origin = mincorner origin = mincorner

View File

@ -431,7 +431,7 @@ def hybrid_IA(dist: np.ndarray,
scale_,scale,inc_factor = (0.0,float(N_opt_samples),1.0) scale_,scale,inc_factor = (0.0,float(N_opt_samples),1.0)
while (not np.isclose(scale, scale_)) and (N_inv_samples != N_opt_samples): while (not np.isclose(scale, scale_)) and (N_inv_samples != N_opt_samples):
repeats = np.rint(scale*dist).astype(int) repeats = np.rint(scale*dist).astype(np.int64)
N_inv_samples = np.sum(repeats) N_inv_samples = np.sum(repeats)
scale_,scale,inc_factor = (scale,scale+inc_factor*0.5*(scale - scale_), inc_factor*2.0) \ scale_,scale,inc_factor = (scale,scale+inc_factor*0.5*(scale - scale_), inc_factor*2.0) \
if N_inv_samples < N_opt_samples else \ if N_inv_samples < N_opt_samples else \

View File

@ -1,3 +1,4 @@
import sys
import os import os
import pytest import pytest
import numpy as np import numpy as np
@ -41,6 +42,7 @@ class TestConfigMaterial:
material_config['material'][0]['constituents'][0]['O']=[0,0,0,0] material_config['material'][0]['constituents'][0]['O']=[0,0,0,0]
assert not material_config.is_valid assert not material_config.is_valid
@pytest.mark.xfail(sys.platform == 'win32', reason='utf8 "not equal" might cause trouble')
def test_invalid_fraction(self,ref_path): def test_invalid_fraction(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml') material_config = ConfigMaterial.load(ref_path/'material.yaml')
material_config['material'][0]['constituents'][0]['v']=.9 material_config['material'][0]['constituents'][0]['v']=.9

View File

@ -1,3 +1,5 @@
import sys
import pytest import pytest
import numpy as np import numpy as np
import vtk import vtk
@ -47,6 +49,7 @@ class TestGrid:
@pytest.mark.parametrize('cmap',[Colormap.from_predefined('stress'),'viridis']) @pytest.mark.parametrize('cmap',[Colormap.from_predefined('stress'),'viridis'])
@pytest.mark.skipif(sys.platform == 'win32', reason='DISPLAY has no effect on windows')
def test_show(sef,default,cmap,monkeypatch): def test_show(sef,default,cmap,monkeypatch):
monkeypatch.delenv('DISPLAY',raising=False) monkeypatch.delenv('DISPLAY',raising=False)
default.show(cmap) default.show(cmap)

View File

@ -108,7 +108,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 in ['darwin','win32'], 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':

View File

@ -2,6 +2,7 @@ import os
import filecmp import filecmp
import time import time
import string import string
import sys
import pytest import pytest
import numpy as np import numpy as np
@ -31,6 +32,7 @@ class TestVTK:
print('patched damask.util.execution_stamp') print('patched damask.util.execution_stamp')
@pytest.mark.parametrize('cmap',[Colormap.from_predefined('cividis'),'strain']) @pytest.mark.parametrize('cmap',[Colormap.from_predefined('cividis'),'strain'])
@pytest.mark.skipif(sys.platform == 'win32', reason='DISPLAY has no effect on windows')
def test_show(sef,default,cmap,monkeypatch): def test_show(sef,default,cmap,monkeypatch):
monkeypatch.delenv('DISPLAY',raising=False) monkeypatch.delenv('DISPLAY',raising=False)
default.show(colormap=cmap) default.show(colormap=cmap)

View File

@ -1,5 +1,5 @@
import sys
import random import random
import os
import pytest import pytest
import numpy as np import numpy as np
@ -11,14 +11,17 @@ from damask import util
class TestUtil: class TestUtil:
@pytest.mark.xfail(sys.platform == 'win32', reason='echo is not a Windows command')
def test_execute_direct(self): def test_execute_direct(self):
out,err = util.execute('echo test') out,err = util.execute('echo test')
assert out=='test\n' and err=='' assert out=='test\n' and err==''
@pytest.mark.xfail(sys.platform == 'win32', reason='echo is not a Windows command')
def test_execute_env(self): def test_execute_env(self):
out,err = util.execute('sh -c "echo $test_for_execute"',env={'test_for_execute':'test'}) out,err = util.execute('sh -c "echo $test_for_execute"',env={'test_for_execute':'test'})
assert out=='test\n' and err=='' assert out=='test\n' and err==''
@pytest.mark.xfail(sys.platform == 'win32', reason='false is not a Windows command')
def test_execute_runtime_error(self): def test_execute_runtime_error(self):
with pytest.raises(RuntimeError): with pytest.raises(RuntimeError):
util.execute('false') util.execute('false')
@ -125,9 +128,9 @@ class TestUtil:
def test_D3D_base_group(self,tmp_path,complete): def test_D3D_base_group(self,tmp_path,complete):
base_group = ''.join(random.choices('DAMASK', k=10)) base_group = ''.join(random.choices('DAMASK', k=10))
with h5py.File(tmp_path/'base_group.dream3d','w') as f: with h5py.File(tmp_path/'base_group.dream3d','w') as f:
f.create_group(os.path.join(base_group,'_SIMPL_GEOMETRY')) f.create_group('/'.join((base_group,'_SIMPL_GEOMETRY')))
if complete: if complete:
f[os.path.join(base_group,'_SIMPL_GEOMETRY')].create_dataset('SPACING',data=np.ones(3)) f['/'.join((base_group,'_SIMPL_GEOMETRY'))].create_dataset('SPACING',data=np.ones(3))
if complete: if complete:
assert base_group == util.DREAM3D_base_group(tmp_path/'base_group.dream3d') assert base_group == util.DREAM3D_base_group(tmp_path/'base_group.dream3d')
@ -141,12 +144,12 @@ class TestUtil:
cell_data_group = ''.join(random.choices('KULeuven', k=10)) cell_data_group = ''.join(random.choices('KULeuven', k=10))
cells = np.random.randint(1,50,3) cells = np.random.randint(1,50,3)
with h5py.File(tmp_path/'cell_data_group.dream3d','w') as f: with h5py.File(tmp_path/'cell_data_group.dream3d','w') as f:
f.create_group(os.path.join(base_group,'_SIMPL_GEOMETRY')) f.create_group('/'.join((base_group,'_SIMPL_GEOMETRY')))
f[os.path.join(base_group,'_SIMPL_GEOMETRY')].create_dataset('SPACING',data=np.ones(3)) f['/'.join((base_group,'_SIMPL_GEOMETRY'))].create_dataset('SPACING',data=np.ones(3))
f[os.path.join(base_group,'_SIMPL_GEOMETRY')].create_dataset('DIMENSIONS',data=cells[::-1]) f['/'.join((base_group,'_SIMPL_GEOMETRY'))].create_dataset('DIMENSIONS',data=cells[::-1])
f[base_group].create_group(cell_data_group) f[base_group].create_group(cell_data_group)
if complete: if complete:
f[os.path.join(base_group,cell_data_group)].create_dataset('data',shape=np.append(cells,1)) f['/'.join((base_group,cell_data_group))].create_dataset('data',shape=np.append(cells,1))
if complete: if complete:
assert cell_data_group == util.DREAM3D_cell_data_group(tmp_path/'cell_data_group.dream3d') assert cell_data_group == util.DREAM3D_cell_data_group(tmp_path/'cell_data_group.dream3d')