2020-06-25 04:07:33 +05:30
|
|
|
import pytest
|
|
|
|
import numpy as np
|
2020-06-21 02:21:00 +05:30
|
|
|
from damask import util
|
|
|
|
|
2020-06-25 04:07:33 +05:30
|
|
|
|
2020-06-21 02:21:00 +05:30
|
|
|
class TestUtil:
|
|
|
|
|
|
|
|
def test_execute_direct(self):
|
|
|
|
out,err = util.execute('echo test')
|
|
|
|
assert out=='test\n' and err==''
|
2020-06-25 04:07:33 +05:30
|
|
|
|
2020-06-21 02:21:00 +05:30
|
|
|
def test_execute_env(self):
|
|
|
|
out,err = util.execute('sh -c "echo $test_for_execute"',env={'test_for_execute':'test'})
|
|
|
|
assert out=='test\n' and err==''
|
2020-06-25 04:07:33 +05:30
|
|
|
|
|
|
|
def test_croak(self):
|
|
|
|
util.croak('Burp!')
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('input,output',
|
|
|
|
[
|
2020-09-19 23:08:32 +05:30
|
|
|
([0,-2],[0,-1]),
|
|
|
|
([-0.5,0.5],[-1,1]),
|
2020-06-25 04:07:33 +05:30
|
|
|
([1./2.,1./3.],[3,2]),
|
|
|
|
([2./3.,1./2.,1./3.],[4,3,2]),
|
|
|
|
])
|
|
|
|
|
|
|
|
def test_scale2coprime(self,input,output):
|
|
|
|
assert np.allclose(util.scale_to_coprime(np.array(input)),
|
|
|
|
np.array(output).astype(int))
|
|
|
|
|
|
|
|
def test_lackofprecision(self):
|
|
|
|
with pytest.raises(ValueError):
|
2020-09-19 23:08:32 +05:30
|
|
|
util.scale_to_coprime(np.array([1/333.333,1,1]))
|