removed `Grid.diff` in lieu of `__eq__`
This commit is contained in:
parent
bf4c88a39e
commit
bf2515c4c1
|
@ -69,9 +69,9 @@ class Grid:
|
||||||
copy = __copy__
|
copy = __copy__
|
||||||
|
|
||||||
|
|
||||||
def diff(self,other):
|
def __eq__(self,other):
|
||||||
"""
|
"""
|
||||||
Report property differences of self relative to other.
|
Test equality of other.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
@ -79,34 +79,10 @@ class Grid:
|
||||||
Grid to compare self against.
|
Grid to compare self against.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
message = []
|
return (np.allclose(other.size,self.size)
|
||||||
if np.any(other.cells != self.cells):
|
and np.allclose(other.origin,self.origin)
|
||||||
message.append(util.deemph(f'cells x y z: {util.srepr(other.cells," x ")}'))
|
and np.all(other.cells == self.cells)
|
||||||
message.append(util.emph( f'cells x y z: {util.srepr( self.cells," x ")}'))
|
and np.all(other.material == self.material))
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -41,13 +41,9 @@ class TestGrid:
|
||||||
def _patch_datetime_now(self, patch_datetime_now):
|
def _patch_datetime_now(self, patch_datetime_now):
|
||||||
print('patched datetime.datetime.now')
|
print('patched datetime.datetime.now')
|
||||||
|
|
||||||
def test_diff_equal(self,default):
|
|
||||||
assert not default.diff(default)
|
|
||||||
|
|
||||||
|
def test_equal(self,default):
|
||||||
def test_diff_not_equal(self,default):
|
assert default == 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_repr(self,default):
|
def test_repr(self,default):
|
||||||
print(default)
|
print(default)
|
||||||
|
|
|
@ -326,7 +326,7 @@ class TestResult:
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
if os.path.isfile(tmp_path/fname):
|
if os.path.isfile(tmp_path/fname):
|
||||||
with open(fname) as f:
|
with open(fname) as f:
|
||||||
cur = hashlib.md5(f.get().encode()).hexdigest()
|
cur = hashlib.md5(f.read().encode()).hexdigest()
|
||||||
if cur == last:
|
if cur == last:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@ -336,7 +336,7 @@ class TestResult:
|
||||||
with open((ref_path/'save_VTK'/request.node.name).with_suffix('.md5'),'w') as f:
|
with open((ref_path/'save_VTK'/request.node.name).with_suffix('.md5'),'w') as f:
|
||||||
f.write(cur)
|
f.write(cur)
|
||||||
with open((ref_path/'save_VTK'/request.node.name).with_suffix('.md5')) as f:
|
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'])
|
@pytest.mark.parametrize('mode',['point','cell'])
|
||||||
def test_vtk_mode(self,tmp_path,single_phase,mode):
|
def test_vtk_mode(self,tmp_path,single_phase,mode):
|
||||||
|
@ -352,7 +352,7 @@ class TestResult:
|
||||||
single_phase.save_XDMF()
|
single_phase.save_XDMF()
|
||||||
if update:
|
if update:
|
||||||
shutil.copy(tmp_path/fname,ref_path/fname)
|
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):
|
def test_XDMF_invalid(self,default):
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
|
|
Loading…
Reference in New Issue