removed `Grid.diff` in lieu of `__eq__`

This commit is contained in:
Philip Eisenlohr 2021-04-06 12:10:35 -04:00
parent bf4c88a39e
commit bf2515c4c1
3 changed files with 12 additions and 40 deletions

View File

@ -69,9 +69,9 @@ class Grid:
copy = __copy__
def diff(self,other):
def __eq__(self,other):
"""
Report property differences of self relative to other.
Test equality of other.
Parameters
----------
@ -79,34 +79,10 @@ class Grid:
Grid to compare self against.
"""
message = []
if np.any(other.cells != self.cells):
message.append(util.deemph(f'cells x y z: {util.srepr(other.cells," x ")}'))
message.append(util.emph( f'cells x y z: {util.srepr( self.cells," x ")}'))
if not np.allclose(other.size,self.size):
message.append(util.deemph(f'size x y z: {util.srepr(other.size," x ")}'))
message.append(util.emph( f'size x y z: {util.srepr( self.size," x ")}'))
if not np.allclose(other.origin,self.origin):
message.append(util.deemph(f'origin x y z: {util.srepr(other.origin," ")}'))
message.append(util.emph( f'origin x y z: {util.srepr( self.origin," ")}'))
if other.N_materials != self.N_materials:
message.append(util.deemph(f'# materials: {other.N_materials}'))
message.append(util.emph( f'# materials: { self.N_materials}'))
if np.nanmin(other.material) != np.nanmin(self.material):
message.append(util.deemph(f'min material: {np.nanmin(other.material)}'))
message.append(util.emph( f'min material: {np.nanmin( self.material)}'))
if np.nanmax(other.material) != np.nanmax(self.material):
message.append(util.deemph(f'max material: {np.nanmax(other.material)}'))
message.append(util.emph( f'max material: {np.nanmax( self.material)}'))
print(util.srepr(message))
return True if message != [] or (other.material != self.material).any() else False
return (np.allclose(other.size,self.size)
and np.allclose(other.origin,self.origin)
and np.all(other.cells == self.cells)
and np.all(other.material == self.material))
@property
@ -276,7 +252,7 @@ class Grid:
"""
Load DREAM.3D (HDF5) file.
Data in DREAM.3D files can be stored per cell ('CellData') and/or
Data in DREAM.3D files can be stored per cell ('CellData') and/or
per grain ('Grain Data'). Per default, cell-wise data is assumed.
damask.ConfigMaterial.load_DREAM3D gives the corresponding material definition.

View File

@ -41,13 +41,9 @@ class TestGrid:
def _patch_datetime_now(self, patch_datetime_now):
print('patched datetime.datetime.now')
def test_diff_equal(self,default):
assert not default.diff(default)
def test_diff_not_equal(self,default):
new = Grid(default.material[1:,1:,1:]+1,default.size*.9,np.ones(3)-default.origin,comments=['modified'])
assert default.diff(new)
def test_equal(self,default):
assert default == default
def test_repr(self,default):
print(default)

View File

@ -326,7 +326,7 @@ class TestResult:
for i in range(10):
if os.path.isfile(tmp_path/fname):
with open(fname) as f:
cur = hashlib.md5(f.get().encode()).hexdigest()
cur = hashlib.md5(f.read().encode()).hexdigest()
if cur == last:
break
else:
@ -336,7 +336,7 @@ class TestResult:
with open((ref_path/'save_VTK'/request.node.name).with_suffix('.md5'),'w') as f:
f.write(cur)
with open((ref_path/'save_VTK'/request.node.name).with_suffix('.md5')) as f:
assert cur == f.get()
assert cur == f.read()
@pytest.mark.parametrize('mode',['point','cell'])
def test_vtk_mode(self,tmp_path,single_phase,mode):
@ -352,7 +352,7 @@ class TestResult:
single_phase.save_XDMF()
if update:
shutil.copy(tmp_path/fname,ref_path/fname)
assert sorted(open(tmp_path/fname).get()) == sorted(open(ref_path/fname).get()) # XML is not ordered
assert sorted(open(tmp_path/fname).read()) == sorted(open(ref_path/fname).read()) # XML is not ordered
def test_XDMF_invalid(self,default):
with pytest.raises(TypeError):