Coverage for pygeodesy/unitsBase.py : 99%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
'''
_radians_, _radians2_, _radius_, \ _UNDER_, _std_ # PYCHOK used! # from pygeodesy.props import property_doc_ # from .named
'''(INTERNAL) Base class for C{units}. '''
'''Get the representation (C{bool}, C{True} means standard). '''
'''Set the representation (C{True} or C{"std"} for standard). ''' self._std_repr = std in (True, _std_)
'''(INTERNAL) Representation "<name> (<value>)" or "<classname>(<value>)". ''' Fmt.PAREN( self.classname, value)
'''Get the units name (C{str}). '''
'''Set the units name for this instance (C{str} or C{None} for default). '''
'''Named C{float}. ''' # _std_repr = True # set below
'''New C{Ffloat} instance.
@kwarg arg: The value (any C{type} convertable to C{float}). @kwarg name: Optional instance name (C{str}). @kwarg Error: Optional error to raise, overriding the default L{UnitError}. @kwarg name_arg: Optional C{name=arg} keyword argument, inlieu of B{C{name}} and B{C{arg}}.
@returns: A C{Float} instance.
@raise Error: Invalid B{C{arg}}. '''
except (TypeError, ValueError) as x: # XXX not ... as x: raise _Error(cls, arg, name=name, Error=Error, txt=str(x))
'''Return a representation of this C{Float}.
@see: Method C{Float.toRepr} and property C{Float.std_repr}.
@note: Use C{env} variable C{PYGEODESY_FLOAT_STD_REPR=std} prior to C{import pygeodesy} to get the standard C{repr} or set property C{std_repr=False} to always get the named C{toRepr} representation. '''
'''Return this C{Float} as standard C{str}. ''' # XXX must use super(Float, self)... since super()... # only works for Python 3+ and float.__str__(self) # invokes .__repr__(self); calling self.toRepr(std=True) # super(Float, self).__repr__() mimicks this behavior # XXX the default number of decimals is 10-12 when using # float.__str__(self) with both python 3.8+ and 2.7-, but # float.__repr__(self) shows DIG decimals in python2.7! # return super(Float, self).__repr__() # see .test.testCss.py
'''Return a representation of this C{Float}.
@kwarg std: If C{True} return the standard C{repr}, otherwise the named representation (C{bool}).
@see: Methods L{Float.__repr__}, L{Float.toStr} and function L{pygeodesy.fstr} for more documentation. ''' # XXX must use super(Float, self)... since # super()... only works for Python 3+ # return super(Float, self).__repr__() if std else \ self._toRepr(self.toStr(**prec_fmt_ints))
'''Format this C{Float} as C{str}.
@see: Method L{Float.__repr__} and function L{pygeodesy.fstr} for more documentation. '''
'''Named C{int}. ''' # _std_repr = True # set below
'''New C{Int} instance.
@kwarg arg: The value (any C{type} convertable to C{float}). @kwarg name: Optional instance name (C{str}). @kwarg Error: Optional error to raise, overriding the default L{UnitError}. @kwarg name_arg: Optional C{name=arg} keyword argument, inlieu of B{C{name}} and B{C{arg}}.
@returns: An C{Int} instance.
@raise Error: Invalid B{C{arg}}. '''
except (TypeError, ValueError) as x: # XXX not ... as x: raise _Error(cls, arg, name=name, Error=Error, txt=str(x))
'''Return a representation of this named C{int}.
@see: Method C{Int.toRepr} and property C{Int.std_repr}.
@note: Use C{env} variable C{PYGEODESY_INT_STD_REPR=std} prior to C{import pygeodesy} to get the standard C{repr} or set property C{std_repr=False} to always get the named C{toRepr} representation. '''
'''Return this C{Int} as standard C{str}. '''
'''Return a representation of this C{Int}.
@kwarg std: If C{True} return the standard C{repr}, otherwise the named representation (C{bool}).
@see: Method L{Int.__repr__} for more documentation. '''
'''Return this C{Int} as standard C{str}.
@see: Method L{Int.__repr__} for more documentation. ''' # XXX must use '%d' % (self,) since # int.__str__(self) fails with 3.8+
'''Named C{float} representing a radius, conventionally in C{meter}. ''' '''New L{Radius} instance, see L{Float}. '''
'''Named, callable C{str}. ''' # _std_repr = True # set below
'''New C{Str} instance.
@kwarg cls: This class (C{Str} or sub-class). @kwarg arg: The value (any C{type} convertable to C{str}). @kwarg name: Optional instance name (C{str}). @kwarg Error: Optional error to raise, overriding the default (C{ValueError}). @kwarg name_arg: Optional C{name=arg} keyword argument, inlieu of B{C{name}} and B{C{arg}}.
@returns: A L{Str} instance.
@raise Error: Invalid B{C{arg}}.
@see: Callable, not-nameable class L{pygeodesy.Str_}. '''
except (TypeError, ValueError) as x: # XXX not ... as x: raise _Error(cls, arg, name=name, Error=Error, txt=str(x))
'''Return a representation of this C{Str}.
@see: Method C{Str.toRepr} and property C{Str.std_repr}.
@note: Use C{env} variable C{PYGEODESY_STR_STD_REPR=std} prior to C{import pygeodesy} to get the standard C{repr} or set property C{std_repr=False} to always get the named C{toRepr} representation. '''
'''Return this C{Str} as standard C{str}. '''
'''Join all positional B{C{args}} like C{self.join(B{args})}.
@return: All B{C{args}} joined by this instance (L{Str_}).
@note: An other L{Str} instance is returned to make the result re-callable. '''
'''Return a representation of this C{Str}.
@kwarg std: If C{True} return the standard C{repr}, otherwise the named representation (C{bool}).
@see: Method L{Str.__repr__} for more documentation. ''' # must use super(Str, self).. since # super()... only works for Python 3+ and # str.__repr__(self) fails with Python 3.8+
'''Return this C{Str} as standard C{str}. ''' # must use super(Str, self)... since # super()... only works for Python 3+ and # str.__str__(self) fails with Python 3.8+
'''(INTERNAL) Return an error with explanation.
@arg clas: The C{units} class or sub-class. @arg arg: The original C{unit} value. @kwarg name: The instance name (C{str}). @kwarg Error: Optional error, overriding the default L{UnitError}. @kwarg txt: Optional explanation of the error (C{str}).
@returns: An B{C{Error}} instance. '''
# **) MIT License # # Copyright (C) 2016-2022 -- mrJean1 at Gmail -- All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. |