more systematic monkeypatching
allows comparison of reference files (log/history does not contain information about damask.version and datetime.datetime.now)
This commit is contained in:
parent
9867830d68
commit
c7cbd961a1
|
@ -1,11 +1,29 @@
|
|||
from pathlib import Path
|
||||
import datetime
|
||||
|
||||
import numpy as np
|
||||
|
||||
import pytest
|
||||
from _pytest.monkeypatch import MonkeyPatch
|
||||
|
||||
# Use to monkeypatch damask.version (for comparsion to reference files that contain version information)
|
||||
def pytest_configure():
|
||||
pytest.dummy_version = '99.99.99-9999-pytest'
|
||||
import damask
|
||||
|
||||
|
||||
patched_version = '99.99.99-9999-pytest'
|
||||
@pytest.fixture
|
||||
def patch_damask_version(monkeysession):
|
||||
"""Set damask.version for reproducible tests results."""
|
||||
monkeysession.setattr(damask, 'version', patched_version)
|
||||
|
||||
patched_date = datetime.datetime(2019, 11, 2, 11, 58, 0)
|
||||
@pytest.fixture
|
||||
def patch_datetime_now(monkeysession):
|
||||
"""Set datetime.datetime.now for reproducible tests results."""
|
||||
class mydatetime:
|
||||
@classmethod
|
||||
def now(cls):
|
||||
return patched_date
|
||||
|
||||
monkeysession.setattr(datetime, 'datetime', mydatetime)
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
|
|
|
@ -17,6 +17,10 @@ def reference_dir(reference_dir_base):
|
|||
|
||||
class TestColormap:
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _patch_damask_version(self, patch_damask_version):
|
||||
print('patched damask.version')
|
||||
|
||||
def test_conversion(self):
|
||||
|
||||
specials = np.array([[0.,0.,0.],
|
||||
|
@ -29,7 +33,6 @@ class TestColormap:
|
|||
[1.,1.,1.]
|
||||
])
|
||||
rgbs = np.vstack((specials,np.random.rand(100,3)))
|
||||
pass # class not integrated
|
||||
for rgb in rgbs:
|
||||
print('rgb',rgb)
|
||||
|
||||
|
@ -150,8 +153,7 @@ class TestColormap:
|
|||
('GOM','.legend'),
|
||||
('Gmsh','.msh')
|
||||
])
|
||||
def test_compare_reference(self,format,ext,tmpdir,reference_dir,update,monkeypatch):
|
||||
monkeypatch.setattr(damask, 'version', pytest.dummy_version)
|
||||
def test_compare_reference(self,format,ext,tmpdir,reference_dir,update):
|
||||
name = 'binary'
|
||||
c = Colormap.from_predefined(name)
|
||||
if update:
|
||||
|
|
Loading…
Reference in New Issue