Improved docs for testing

This commit is contained in:
Hernan Grecco 2016-02-13 23:21:03 -03:00
parent be1ed57e67
commit 9e204f8d35
9 changed files with 46 additions and 41 deletions

View File

@ -68,63 +68,63 @@ after_success:
matrix:
exclude:
# Do not edit after this line
- python: "3.5"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
- python: "3.5"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.8.2
- python: "3.5"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
- python: "3.5"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
- python: "3.5"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.8.2
- python: "3.5"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
- python: "3.5"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
- python: "3.4"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
- python: "3.4"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
- python: "3.4"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
- python: "3.4"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
- python: "3.4"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
- python: "3.3"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.10.4
- python: "3.3"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
- python: "3.3"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
- python: "3.3"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
- python: "3.3"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
- python: "3.3"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
- python: "3.3"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
- python: "3.3"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
- python: "3.2"
- python: "3.3"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.10.4
- python: "3.2"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
- python: "3.2"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.8.2
- python: "3.2"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
- python: "3.2"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
- python: "3.2"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
- python: "3.2"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
- python: "3.2"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.8.2
- python: "3.2"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
- python: "3.2"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
- python: "3.2"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
- python: "2.6"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.10.4
- python: "2.6"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
- python: "2.6"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
- python: "2.6"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
- python: "2.6"
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
- python: "2.6"
env: UNCERTAINTIES="N" NUMPY_VERSION=1.10.4

View File

@ -50,7 +50,13 @@ author = 'Hernan E. Grecco'
# |version| and |release|, also used in various other places throughout the
# built documents.
version = pkg_resources.get_distribution(project).version
try: # pragma: no cover
version = pkg_resources.get_distribution(project).version
except: # pragma: no cover
# we seem to have a local copy not installed without setuptools
# so the reported version will be unknown
version = "unknown"
release = version
this_year = datetime.date.today().year
copyright = '%s, %s' % (this_year, author)

View File

@ -116,7 +116,7 @@ mass.
.. doctest::
>>> substance = 95 * ureg('g')
>>> moles = substance.to('moles', 'chemistry', mw = 5 * ureg('g/mol'))
>>> substance.to('moles', 'chemistry', mw = 5 * ureg('g/mol'))
<Quantity(19.0, 'mole')>

View File

@ -81,6 +81,7 @@ User Guide
measurement
defining
performance
systems
More information

View File

@ -80,7 +80,7 @@ If you want to add a quantity with absolute unit to one with offset unit, like h
>>> Q_(10., ureg.degC) + heating_rate * Q_(30, ureg.min)
Traceback (most recent call last):
...
pint.unit.OffsetUnitCalculusError: Ambiguous operation with offset unit (degC, kelvin).
pint.errors.OffsetUnitCalculusError: Ambiguous operation with offset unit (degC, kelvin).
you have to avoid the ambiguity by either converting the offset unit to the
absolute unit before addition
@ -157,7 +157,7 @@ You can change the behaviour at any time:
>>> 1/T
Traceback (most recent call last):
...
pint.unit.OffsetUnitCalculusError: Ambiguous operation with offset unit (degC).
pint.errors.OffsetUnitCalculusError: Ambiguous operation with offset unit (degC).
The parser knows about *delta* units and uses them when a temperature unit
is found in a multiplicative context. For example, here:

View File

@ -51,7 +51,7 @@ All usual Pint methods can be used with this quantity. For example:
>>> legs1.to('joule')
Traceback (most recent call last):
...
DimensionalityError: Cannot convert from 'meter' ([length]) to 'joule' ([length] ** 2 * [mass] / [time] ** 2)
pint.errors.DimensionalityError: Cannot convert from 'meter' ([length]) to 'joule' ([length] ** 2 * [mass] / [time] ** 2)
NumPy functions are supported by Pint. For example if we define:
@ -96,7 +96,7 @@ results in an error:
>>> np.arccos(legs2)
Traceback (most recent call last):
...
DimensionalityError: Cannot convert from 'centimeter' ([length]) to 'dimensionless' (dimensionless)
pint.errors.DimensionalityError: Cannot convert from 'centimeter' ([length]) to 'dimensionless' (dimensionless)
Support

View File

@ -1,4 +1,4 @@
.. systems_:
.. _systems:
Different Unit Systems (and default units)
==========================================
@ -16,11 +16,6 @@ This has an effect in the base units. For example:
>>> q.to_base_units()
<Quantity(1.0, 'meter / second')>
We can take a look for the available systems
>>> ureg.systems
frozenset({'US', 'mks', 'imperial', 'cgs'})
But if you change to cgs:
>>> ureg.default_system = 'cgs'
@ -60,7 +55,7 @@ You can check which unit systems are available:
Or which units are available within a particular system:
>>> dir(ureg.sys.imperial)
['acre', 'acre_foot', 'board_foot', 'cable', 'chain', 'fathom', 'foot', 'furlong', 'imperial_bushel', 'imperial_cup', 'imperial_fluid_ounce', 'imperial_gallon', 'imperial_gill', 'imperial_pint', 'imperial_quart', 'inch', 'league', 'mile', 'nautical_mile', 'perch', 'pica', 'point', 'rood', 'square_foot', 'square_yard', 'thou', 'yard']
['acre', 'acre_foot', 'board_foot', 'cable', 'chain', 'fathom', 'foot', 'furlong', 'imperial_barrel', 'imperial_bushel', 'imperial_cup', 'imperial_fluid_ounce', 'imperial_gallon', 'imperial_gill', 'imperial_pint', 'imperial_quart', 'inch', 'league', 'mile', 'nautical_mile', 'perch', 'pica', 'point', 'rood', 'square_foot', 'square_yard', 'thou', 'yard']
Notice that this give you the opportunity to choose within units with colliding names:

View File

@ -19,6 +19,7 @@ and handled. You start by creating your registry::
ureg = UnitRegistry()
Q_ = ureg.Quantity
If no parameter is given to the constructor, the unit registry is populated
with the default list of units and prefixes.
You can now simply use the registry in the following way:
@ -88,7 +89,7 @@ If you ask Pint to perform an invalid conversion:
>>> speed.to(ureg.joule)
Traceback (most recent call last):
...
pint.pint.DimensionalityError: Cannot convert from 'inch / minute' (length / time) to 'joule' (length ** 2 * mass / time ** 2)
pint.errors.DimensionalityError: Cannot convert from 'inch / minute' ([length] / [time]) to 'joule' ([length] ** 2 * [mass] / [time] ** 2)
There are also methods 'to_base_units' and 'ito_base_units' which automatically

View File

@ -63,15 +63,18 @@ Pint provides a more convenient way to do this:
>>> mypp = ureg.wraps(ureg.second, ureg.meter)(pendulum_period)
To understand the syntax, consider the usage in the decorator format:
Or in the decorator format:
.. doctest::
>>> @ureg.wraps(ureg.second, ureg.meter)
... def mypp(length):
... return pendulum_period(length)
>>> mypp(100 * ureg.centimeter)
<Quantity(2.0064092925890407, 'second')>
`wraps` takes 3 input arguments::
`wraps` takes 3 input arguments:
- **ret**: the return units.
Use None to skip conversion.
@ -80,8 +83,7 @@ To understand the syntax, consider the usage in the decorator format:
- **strict**: if `True` all convertible arguments must be a Quantity
and others will raise a ValueError (True by default)
>>> mypp(100 * ureg.centimeter)
<Quantity(2.0064092925890407, 'second')>
Strict Mode
-----------
@ -154,11 +156,11 @@ which can be read as the first argument (`x`) has certain units (we labeled them
the second argument (`y`) has the same units as the first (`A` again). The return value
has the unit of `x` squared (`A**2`)
You can use more than one labels.
You can use more than one label:
>>> @ureg.wraps('=A**2*B', ('=A', '=A*B', '=B'))
... def some_function(x, y, z):
... pass
Ignoring an argument or return value