documentation + consistent string formatting
This commit is contained in:
parent
05c1007add
commit
51e5dda702
|
@ -74,23 +74,23 @@ class Geom:
|
||||||
"""
|
"""
|
||||||
message = []
|
message = []
|
||||||
if np.any(other.grid != self.grid):
|
if np.any(other.grid != self.grid):
|
||||||
message.append(util.delete(f'grid a b c: {util.srepr(other.grid," x ")}'))
|
message.append(util.deemph(f'grid a b c: {util.srepr(other.grid," x ")}'))
|
||||||
message.append(util.emph( f'grid a b c: {util.srepr( self.grid," x ")}'))
|
message.append(util.emph( f'grid a b c: {util.srepr( self.grid," x ")}'))
|
||||||
|
|
||||||
if not np.allclose(other.size,self.size):
|
if not np.allclose(other.size,self.size):
|
||||||
message.append(util.delete(f'size x y z: {util.srepr(other.size," x ")}'))
|
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 ")}'))
|
message.append(util.emph( f'size x y z: {util.srepr( self.size," x ")}'))
|
||||||
|
|
||||||
if not np.allclose(other.origin,self.origin):
|
if not np.allclose(other.origin,self.origin):
|
||||||
message.append(util.delete(f'origin x y z: {util.srepr(other.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," ")}'))
|
message.append(util.emph( f'origin x y z: {util.srepr( self.origin," ")}'))
|
||||||
|
|
||||||
if other.N_materials != self.N_materials:
|
if other.N_materials != self.N_materials:
|
||||||
message.append(util.delete(f'# materials: {other.N_materials}'))
|
message.append(util.deemph(f'# materials: {other.N_materials}'))
|
||||||
message.append(util.emph( f'# materials: { self.N_materials}'))
|
message.append(util.emph( f'# materials: { self.N_materials}'))
|
||||||
|
|
||||||
if np.nanmax(other.material) != np.nanmax(self.material):
|
if np.nanmax(other.material) != np.nanmax(self.material):
|
||||||
message.append(util.delete(f'max material: {np.nanmax(other.material)}'))
|
message.append(util.deemph(f'max material: {np.nanmax(other.material)}'))
|
||||||
message.append(util.emph( f'max material: {np.nanmax( self.material)}'))
|
message.append(util.emph( f'max material: {np.nanmax( self.material)}'))
|
||||||
|
|
||||||
return util.return_message(message)
|
return util.return_message(message)
|
||||||
|
|
|
@ -167,9 +167,7 @@ class Result:
|
||||||
|
|
||||||
|
|
||||||
def allow_modification(self):
|
def allow_modification(self):
|
||||||
print(util.bcolors().WARNING+util.bcolors().BOLD+
|
print(util.warn('Warning: Modification of existing datasets allowed!'))
|
||||||
'Warning: Modification of existing datasets allowed!'+
|
|
||||||
util.bcolors().ENDC)
|
|
||||||
self._allow_modification = True
|
self._allow_modification = True
|
||||||
|
|
||||||
def disallow_modification(self):
|
def disallow_modification(self):
|
||||||
|
|
|
@ -17,7 +17,7 @@ __all__=[
|
||||||
'srepr',
|
'srepr',
|
||||||
'croak',
|
'croak',
|
||||||
'report',
|
'report',
|
||||||
'emph','deemph','delete','strikeout',
|
'emph','deemph','warn','strikeout',
|
||||||
'execute',
|
'execute',
|
||||||
'show_progress',
|
'show_progress',
|
||||||
'scale_to_coprime',
|
'scale_to_coprime',
|
||||||
|
@ -74,7 +74,7 @@ def croak(what, newline = True):
|
||||||
def report(who = None,
|
def report(who = None,
|
||||||
what = None):
|
what = None):
|
||||||
"""
|
"""
|
||||||
Reports script and file name.
|
Report script and file name.
|
||||||
|
|
||||||
DEPRECATED
|
DEPRECATED
|
||||||
|
|
||||||
|
@ -86,16 +86,13 @@ def emph(what):
|
||||||
"""Formats string with emphasis."""
|
"""Formats string with emphasis."""
|
||||||
return bcolors.BOLD+srepr(what)+bcolors.ENDC
|
return bcolors.BOLD+srepr(what)+bcolors.ENDC
|
||||||
|
|
||||||
|
|
||||||
def deemph(what):
|
def deemph(what):
|
||||||
"""Formats string with deemphasis."""
|
"""Formats string with deemphasis."""
|
||||||
return bcolors.DIM+srepr(what)+bcolors.ENDC
|
return bcolors.DIM+srepr(what)+bcolors.ENDC
|
||||||
|
|
||||||
|
def warn(what):
|
||||||
def delete(what):
|
"""Formats string for warning."""
|
||||||
"""Formats string as deleted."""
|
return bcolors.WARNING+emph(what)+bcolors.ENDC
|
||||||
return bcolors.DIM+srepr(what)+bcolors.ENDC
|
|
||||||
|
|
||||||
|
|
||||||
def strikeout(what):
|
def strikeout(what):
|
||||||
"""Formats string as strikeout."""
|
"""Formats string as strikeout."""
|
||||||
|
@ -302,20 +299,38 @@ def shapeblender(a,b):
|
||||||
return a + b[i:]
|
return a + b[i:]
|
||||||
|
|
||||||
|
|
||||||
def extend_docstring(general):
|
def extend_docstring(extra_docstring):
|
||||||
"""Decorator: Append Orientation parameter documentation to function's docstring."""
|
"""
|
||||||
def _decorator(func):
|
Decorator: Append to function's docstring.
|
||||||
func.__doc__ += general
|
|
||||||
return func
|
Parameters
|
||||||
return _decorator
|
----------
|
||||||
|
extra_docstring : str
|
||||||
|
Docstring to append.
|
||||||
|
|
||||||
|
"""
|
||||||
|
def _decorator(func):
|
||||||
|
func.__doc__ += extra_docstring
|
||||||
|
return func
|
||||||
|
return _decorator
|
||||||
|
|
||||||
|
|
||||||
def extended_docstring(f,general):
|
def extended_docstring(f,extra_docstring):
|
||||||
"""Decorator: Combine Orientation parameter documentation with another function's docstring."""
|
"""
|
||||||
def _decorator(func):
|
Decorator: Combine another function's docstring with a given docstring.
|
||||||
func.__doc__ = f.__doc__ + general
|
|
||||||
return func
|
Parameters
|
||||||
return _decorator
|
----------
|
||||||
|
f : function
|
||||||
|
Function of which the docstring is taken.
|
||||||
|
extra_docstring : str
|
||||||
|
Docstring to append.
|
||||||
|
|
||||||
|
"""
|
||||||
|
def _decorator(func):
|
||||||
|
func.__doc__ = f.__doc__ + extra_docstring
|
||||||
|
return func
|
||||||
|
return _decorator
|
||||||
|
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
|
|
|
@ -772,15 +772,15 @@ class TestRotation:
|
||||||
Rotation.from_random(shape)
|
Rotation.from_random(shape)
|
||||||
|
|
||||||
def test_equal(self):
|
def test_equal(self):
|
||||||
r = Rotation.from_random(seed=0)
|
r = Rotation.from_random()
|
||||||
assert r == r
|
assert r == r
|
||||||
|
|
||||||
def test_unequal(self):
|
def test_unequal(self):
|
||||||
r = Rotation.from_random(seed=0)
|
r = Rotation.from_random()
|
||||||
assert not (r != r)
|
assert not (r != r)
|
||||||
|
|
||||||
def test_inversion(self):
|
def test_inversion(self):
|
||||||
r = Rotation.from_random(seed=0)
|
r = Rotation.from_random()
|
||||||
assert r == ~~r
|
assert r == ~~r
|
||||||
|
|
||||||
@pytest.mark.parametrize('shape',[None,1,(1,),(4,2),(1,1,1)])
|
@pytest.mark.parametrize('shape',[None,1,(1,),(4,2),(1,1,1)])
|
||||||
|
|
|
@ -98,6 +98,6 @@ class TestUtil:
|
||||||
def test_shapeblender(self,a,b,answer):
|
def test_shapeblender(self,a,b,answer):
|
||||||
assert util.shapeblender(a,b) == answer
|
assert util.shapeblender(a,b) == answer
|
||||||
|
|
||||||
@pytest.mark.parametrize('style',[util.emph,util.deemph,util.delete,util.strikeout])
|
@pytest.mark.parametrize('style',[util.emph,util.deemph,util.warn,util.strikeout])
|
||||||
def test_decorate(self,style):
|
def test_decorate(self,style):
|
||||||
assert 'DAMASK' in style('DAMASK')
|
assert 'DAMASK' in style('DAMASK')
|
||||||
|
|
Loading…
Reference in New Issue