documentation + consistent string formatting

This commit is contained in:
Martin Diehl 2020-11-15 10:53:23 +01:00
parent 05c1007add
commit 51e5dda702
5 changed files with 45 additions and 32 deletions

View File

@ -74,23 +74,23 @@ class Geom:
"""
message = []
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 ")}'))
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 ")}'))
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," ")}'))
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}'))
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)}'))
return util.return_message(message)

View File

@ -167,9 +167,7 @@ class Result:
def allow_modification(self):
print(util.bcolors().WARNING+util.bcolors().BOLD+
'Warning: Modification of existing datasets allowed!'+
util.bcolors().ENDC)
print(util.warn('Warning: Modification of existing datasets allowed!'))
self._allow_modification = True
def disallow_modification(self):

View File

@ -17,7 +17,7 @@ __all__=[
'srepr',
'croak',
'report',
'emph','deemph','delete','strikeout',
'emph','deemph','warn','strikeout',
'execute',
'show_progress',
'scale_to_coprime',
@ -74,7 +74,7 @@ def croak(what, newline = True):
def report(who = None,
what = None):
"""
Reports script and file name.
Report script and file name.
DEPRECATED
@ -86,16 +86,13 @@ def emph(what):
"""Formats string with emphasis."""
return bcolors.BOLD+srepr(what)+bcolors.ENDC
def deemph(what):
"""Formats string with deemphasis."""
return bcolors.DIM+srepr(what)+bcolors.ENDC
def delete(what):
"""Formats string as deleted."""
return bcolors.DIM+srepr(what)+bcolors.ENDC
def warn(what):
"""Formats string for warning."""
return bcolors.WARNING+emph(what)+bcolors.ENDC
def strikeout(what):
"""Formats string as strikeout."""
@ -302,20 +299,38 @@ def shapeblender(a,b):
return a + b[i:]
def extend_docstring(general):
"""Decorator: Append Orientation parameter documentation to function's docstring."""
def _decorator(func):
func.__doc__ += general
return func
return _decorator
def extend_docstring(extra_docstring):
"""
Decorator: Append to function's docstring.
Parameters
----------
extra_docstring : str
Docstring to append.
"""
def _decorator(func):
func.__doc__ += extra_docstring
return func
return _decorator
def extended_docstring(f,general):
"""Decorator: Combine Orientation parameter documentation with another function's docstring."""
def _decorator(func):
func.__doc__ = f.__doc__ + general
return func
return _decorator
def extended_docstring(f,extra_docstring):
"""
Decorator: Combine another function's docstring with a given docstring.
Parameters
----------
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
####################################################################################################

View File

@ -772,15 +772,15 @@ class TestRotation:
Rotation.from_random(shape)
def test_equal(self):
r = Rotation.from_random(seed=0)
r = Rotation.from_random()
assert r == r
def test_unequal(self):
r = Rotation.from_random(seed=0)
r = Rotation.from_random()
assert not (r != r)
def test_inversion(self):
r = Rotation.from_random(seed=0)
r = Rotation.from_random()
assert r == ~~r
@pytest.mark.parametrize('shape',[None,1,(1,),(4,2),(1,1,1)])

View File

@ -98,6 +98,6 @@ class TestUtil:
def test_shapeblender(self,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):
assert 'DAMASK' in style('DAMASK')