Script 'mail_helper' called by obssrc
Hello community,
here is the log from the commit of package python-numericalunits for
openSUSE:Factory checked in at 2021-06-01 10:35:40
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-numericalunits (Old)
and /work/SRC/openSUSE:Factory/.python-numericalunits.new.1898 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-numericalunits"
Tue Jun 1 10:35:40 2021 rev:6 rq:895341 version:1.25
Changes:
--------
---
/work/SRC/openSUSE:Factory/python-numericalunits/python-numericalunits.changes
2019-12-02 11:38:32.246463158 +0100
+++
/work/SRC/openSUSE:Factory/.python-numericalunits.new.1898/python-numericalunits.changes
2021-06-01 10:36:22.072701308 +0200
@@ -1,0 +2,7 @@
+Tue May 25 10:43:16 UTC 2021 - [email protected]
+
+- version update to 1.25
+ * add nu_eval() function.
+- %check: use %pyunittest rpm macro
+
+-------------------------------------------------------------------
Old:
----
numericalunits-1.24.tar.gz
New:
----
numericalunits-1.25.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-numericalunits.spec ++++++
--- /var/tmp/diff_new_pack.FR909x/_old 2021-06-01 10:36:22.588702186 +0200
+++ /var/tmp/diff_new_pack.FR909x/_new 2021-06-01 10:36:22.592702192 +0200
@@ -1,7 +1,7 @@
#
# spec file for package python-numericalunits
#
-# Copyright (c) 2019 SUSE LLC
+# Copyright (c) 2021 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -19,7 +19,7 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%define skip_python2 1
Name: python-numericalunits
-Version: 1.24
+Version: 1.25
Release: 0
Summary: Python module for defining quantities with units
License: MIT
@@ -57,7 +57,7 @@
%python_expand %fdupes %{buildroot}%{$python_sitelib}
%check
-%python_exec setup.py test --test-suite=tests
+%pyunittest discover -v tests/
%files %{python_files}
%license LICENSE.txt
++++++ numericalunits-1.24.tar.gz -> numericalunits-1.25.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/numericalunits-1.24/Changes.txt
new/numericalunits-1.25/Changes.txt
--- old/numericalunits-1.24/Changes.txt 2019-11-30 03:01:09.000000000 +0100
+++ new/numericalunits-1.25/Changes.txt 2020-11-08 02:53:46.000000000 +0100
@@ -41,3 +41,5 @@
version 1.24, 2019-11-29 -- drop support for python 2; update to latest
CODATA; add more
acceleration-related units.
+
+version 1.25, 2020-11-07 -- add nu_eval() function.
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/numericalunits-1.24/PKG-INFO
new/numericalunits-1.25/PKG-INFO
--- old/numericalunits-1.24/PKG-INFO 2019-11-30 03:12:15.000000000 +0100
+++ new/numericalunits-1.25/PKG-INFO 2020-11-08 02:59:04.142990600 +0100
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: numericalunits
-Version: 1.24
+Version: 1.25
Summary: A package that lets you define quantities with units, which can then
be used in almost any numerical calculation in any programming language. Checks
that calculations pass dimensional analysis, performs unit conversions, and
defines physical constants.
Home-page: http://pypi.python.org/pypi/numericalunits
Author: Steven J. Byrnes
@@ -96,7 +96,7 @@
print(x / nm**3) # "Read: x expressed in cubic nanometers is..."
--> 5e21
**Example 2:** An electron is in a 1e5 V/cm electric field. What is its
- acceleration? (Express the answer in m/s^2.) ::
+ acceleration? (Express the answer in m/s????.) ::
from numericalunits import V, cm, e, me, m, s
Efield = 1e5 * (V / cm)
@@ -195,8 +195,10 @@
* You can give a dimension to complex numbers in the same way as real
numbers--for example ``(2.1e3 + 3.9e4j) * ohm``.
- * Should be compatible with any Python version 2.x or 3.x. If you find
bugs,
- please tell me by `email <http://sjbyrnes.com>`_ or
+ * Requires Python 3. (For Python 2 compatibility, install
numericalunits
+ version 1.23 or earlier.)
+
+ * If you find bugs, please tell me by `email <http://sjbyrnes.com>`_
or
`github issue board
<https://github.com/sbyrnes321/numericalunits/issues>`_.
* If you get overflows or underflows, you can edit the unit
initializations.
@@ -236,10 +238,10 @@
# There are eight copies of a protein inside a yeast nucleus of
volume
# 3 cubic microns. What is the concentration of the protein, in
micromolar (uM)?
- print((8. / (3 * um**3)) / uM) # Answer --> 0.0044
+ print((8 / (3 * um**3)) / uM) # Answer --> 0.0044
# 5 kcal / mol is how many joules?
- print((5. * kcal / mol) / J) # Answer --> 3.47e-20
+ print((5 * kcal / mol) / J) # Answer --> 3.47e-20
# How many molecules are in 2.3 femtomoles?
print(2.3 * fmol) # Answer --> 1.39e9
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/numericalunits-1.24/README.rst
new/numericalunits-1.25/README.rst
--- old/numericalunits-1.24/README.rst 2017-11-12 19:08:37.000000000 +0100
+++ new/numericalunits-1.25/README.rst 2020-02-05 03:33:58.000000000 +0100
@@ -88,7 +88,7 @@
print(x / nm**3) # "Read: x expressed in cubic nanometers is..." --> 5e21
**Example 2:** An electron is in a 1e5 V/cm electric field. What is its
-acceleration? (Express the answer in m/s^2.) ::
+acceleration? (Express the answer in m/s??.) ::
from numericalunits import V, cm, e, me, m, s
Efield = 1e5 * (V / cm)
@@ -187,8 +187,10 @@
* You can give a dimension to complex numbers in the same way as real
numbers--for example ``(2.1e3 + 3.9e4j) * ohm``.
-* Should be compatible with any Python version 2.x or 3.x. If you find bugs,
- please tell me by `email <http://sjbyrnes.com>`_ or
+* Requires Python 3. (For Python 2 compatibility, install numericalunits
+ version 1.23 or earlier.)
+
+* If you find bugs, please tell me by `email <http://sjbyrnes.com>`_ or
`github issue board <https://github.com/sbyrnes321/numericalunits/issues>`_.
* If you get overflows or underflows, you can edit the unit initializations.
@@ -228,10 +230,10 @@
# There are eight copies of a protein inside a yeast nucleus of volume
# 3 cubic microns. What is the concentration of the protein, in
micromolar (uM)?
- print((8. / (3 * um**3)) / uM) # Answer --> 0.0044
+ print((8 / (3 * um**3)) / uM) # Answer --> 0.0044
# 5 kcal / mol is how many joules?
- print((5. * kcal / mol) / J) # Answer --> 3.47e-20
+ print((5 * kcal / mol) / J) # Answer --> 3.47e-20
# How many molecules are in 2.3 femtomoles?
print(2.3 * fmol) # Answer --> 1.39e9
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/numericalunits-1.24/numericalunits.egg-info/PKG-INFO
new/numericalunits-1.25/numericalunits.egg-info/PKG-INFO
--- old/numericalunits-1.24/numericalunits.egg-info/PKG-INFO 2019-11-30
03:12:15.000000000 +0100
+++ new/numericalunits-1.25/numericalunits.egg-info/PKG-INFO 2020-11-08
02:59:03.000000000 +0100
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: numericalunits
-Version: 1.24
+Version: 1.25
Summary: A package that lets you define quantities with units, which can then
be used in almost any numerical calculation in any programming language. Checks
that calculations pass dimensional analysis, performs unit conversions, and
defines physical constants.
Home-page: http://pypi.python.org/pypi/numericalunits
Author: Steven J. Byrnes
@@ -96,7 +96,7 @@
print(x / nm**3) # "Read: x expressed in cubic nanometers is..."
--> 5e21
**Example 2:** An electron is in a 1e5 V/cm electric field. What is its
- acceleration? (Express the answer in m/s^2.) ::
+ acceleration? (Express the answer in m/s????.) ::
from numericalunits import V, cm, e, me, m, s
Efield = 1e5 * (V / cm)
@@ -195,8 +195,10 @@
* You can give a dimension to complex numbers in the same way as real
numbers--for example ``(2.1e3 + 3.9e4j) * ohm``.
- * Should be compatible with any Python version 2.x or 3.x. If you find
bugs,
- please tell me by `email <http://sjbyrnes.com>`_ or
+ * Requires Python 3. (For Python 2 compatibility, install
numericalunits
+ version 1.23 or earlier.)
+
+ * If you find bugs, please tell me by `email <http://sjbyrnes.com>`_
or
`github issue board
<https://github.com/sbyrnes321/numericalunits/issues>`_.
* If you get overflows or underflows, you can edit the unit
initializations.
@@ -236,10 +238,10 @@
# There are eight copies of a protein inside a yeast nucleus of
volume
# 3 cubic microns. What is the concentration of the protein, in
micromolar (uM)?
- print((8. / (3 * um**3)) / uM) # Answer --> 0.0044
+ print((8 / (3 * um**3)) / uM) # Answer --> 0.0044
# 5 kcal / mol is how many joules?
- print((5. * kcal / mol) / J) # Answer --> 3.47e-20
+ print((5 * kcal / mol) / J) # Answer --> 3.47e-20
# How many molecules are in 2.3 femtomoles?
print(2.3 * fmol) # Answer --> 1.39e9
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/numericalunits-1.24/numericalunits.py
new/numericalunits-1.25/numericalunits.py
--- old/numericalunits-1.24/numericalunits.py 2019-11-30 03:07:57.000000000
+0100
+++ new/numericalunits-1.25/numericalunits.py 2020-11-08 02:54:14.000000000
+0100
@@ -2,19 +2,17 @@
"""
For information and usage see README, or
http://pypi.python.org/pypi/numericalunits
"""
-#Copyright (C) 2012-2019 Steven J. Byrnes
+# Copyright (C) 2012-2020 Steven J. Byrnes
#
-#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:
+# 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 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.
-
-from __future__ import division
+# 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.
from math import pi
-__version__ = 1.24
+__version__ = 1.25
########## Set all variables, to help introspection libraries ################
@@ -61,12 +59,12 @@
documentation for detailed explanation and examples:
http://pypi.python.org/pypi/numericalunits
- reset_units() --> units are randomized. This is the suggested use. Run this
- before your calculation, display the final answer, then re-run this, then
- re-disply the final answer. If you get the same answers both times, then
- your calculations are almost guaranteed to be free of
- dimensional-analysis-violating errors. reset_units() is run automatically
- the first time this module is imported.
+ reset_units() --> units are randomized. This is the suggested use, and is
+ done automatically the first time the module is imported. So you don't need
+ to call this function explicitly; just do your calculation, display the
+ final answer, then repeat in a fresh Python session. If you get the same
+ answer both times, then your calculations are almost guaranteed to be free
of
+ dimensional-analysis-violating errors.
reset_units('SI') --> Set units so that all values are given in standard SI
units (meters-kilograms-seconds) by default. In this mode, there is no way
@@ -93,11 +91,11 @@
else:
random.seed(seed)
- m = 10. ** random.uniform(-2,2) #meter
- kg = 10. ** random.uniform(-2,2) #kilogram
- s = 10. ** random.uniform(-2,2) #second
- C = 10. ** random.uniform(-2,2) # coulombs
- K = 10. ** random.uniform(-2,2) # kelvins
+ m = 10 ** random.uniform(-2,2) # meter
+ kg = 10 ** random.uniform(-2,2) # kilogram
+ s = 10 ** random.uniform(-2,2) # second
+ C = 10 ** random.uniform(-2,2) # coulomb
+ K = 10 ** random.uniform(-2,2) # kelvin
# Leave the random generator like I found it, in case something else is
# using it.
@@ -125,19 +123,19 @@
angstrom = 1e-10 * m
?? = angstrom # easier-to-read alias (see
https://sjbyrnes.com/unicode.html )
lightyear = 9460730472580800. * m
- astro_unit = 149597870700. * m #astronomical unit
- pc = (648000./pi) * astro_unit #parsec
+ astro_unit = 149597870700. * m # astronomical unit
+ pc = (648000./pi) * astro_unit # parsec
kpc = 1e3 * pc
Mpc = 1e6 * pc
Gpc = 1e9 * pc
inch = 2.54 * cm
foot = 12. * inch
mile = 5280. * foot
- thou = 1e-3 * inch #thousandth of an inch; also called mil
+ thou = 1e-3 * inch # thousandth of an inch; also called mil
# Volume
global L, mL, uL, nL, pL, fL, aL, kL, ML, GL
- L = 1e-3 * m**3 #liter
+ L = 1e-3 * m**3 # liter
mL = 1e-3 * L
uL = 1e-6 * L
nL = 1e-9 * L
@@ -157,9 +155,9 @@
fs = 1e-15 * s
minute = 60. * s
hour = 60. * minute
- day = 24. * hour #solar day
+ day = 24. * hour # solar day
week = 7. * day
- year = 365.256363004 * day #sidereal year
+ year = 365.256363004 * day # sidereal year
# Frequency
global Hz, mHz, kHz, MHz, GHz, THz, PHz, rtHz, rpm
@@ -195,8 +193,8 @@
pg = 1e-12 * g
fg = 1e-15 * g
tonne = 1e3 * kg
- amu = 1.66053906660e-27 * kg #atomic mass unit
- Da = amu #Dalton
+ amu = 1.66053906660e-27 * kg # atomic mass unit
+ Da = amu # Dalton
kDa = 1e3 * Da
lbm = 0.45359237 * kg # pound mass (international avoirdupois pound)
@@ -219,15 +217,15 @@
MeV = 1e6 * eV
GeV = 1e9 * eV
TeV = 1e12 * eV
- btu = 1055.06 * J #British thermal unit
- smallcal = 4.184 * J #small calorie ("gram calorie")
- kcal = 4184. * J #kilocalorie ("large Calorie", "dietary Calorie")
- Wh = 3600. * J #watt-hour
+ btu = 1055.06 * J # British thermal unit
+ smallcal = 4.184 * J # small calorie ("gram calorie")
+ kcal = 4184. * J # kilocalorie ("large Calorie", "dietary Calorie")
+ Wh = 3600. * J # watt-hour
kWh = 1e3 * Wh # kilowatt-hour
# Moles, concentration / molarity
global NA, mol, mmol, umol, nmol, pmol, fmol, M, mM, uM, nM, pM, fM
- NA = 6.02214076e23 #Avogadro's number
+ NA = 6.02214076e23 # Avogadro's number
mol = NA #1 mole (see README)
mmol = 1e-3 * mol
umol = 1e-6 * mol
@@ -243,7 +241,7 @@
# Force
global N, mN, uN, nN, pN, fN, kN, MN, GN, dyn, lbf
- N = (kg * m)/s**2 #newton
+ N = (kg * m)/s**2 # newton
mN = 1e-3 * N
uN = 1e-6 * N
nN = 1e-9 * N
@@ -252,21 +250,21 @@
kN = 1e3 * N
MN = 1e6 * N
GN = 1e9 * N
- dyn = 1e-5 * N #dyne
- lbf = lbm * (9.80665 * m/s**2) #pound-force (international avoirdupois
pound)
+ dyn = 1e-5 * N # dyne
+ lbf = lbm * (9.80665 * m/s**2) # pound-force (international avoirdupois
pound)
# Pressure
global Pa, hPa, kPa, MPa, GPa, bar, mbar, cbar, dbar, kbar, Mbar, atm, \
torr, mtorr, psi
- Pa = N/m**2 #pascal
- hPa = 1e2 * Pa #hectopascal
+ Pa = N/m**2 # pascal
+ hPa = 1e2 * Pa # hectopascal
kPa = 1e3 * Pa
MPa = 1e6 * Pa
GPa = 1e9 * Pa
bar = 1e5 * Pa
mbar = 1e-3 * bar
- cbar = 1e-2 * bar #centibar
- dbar = 0.1 * bar #decibar
+ cbar = 1e-2 * bar # centibar
+ dbar = 0.1 * bar # decibar
kbar = 1e3 * bar
Mbar = 1e6 * bar
atm = 101325. * Pa
@@ -310,7 +308,7 @@
mC = 1e-3 * C
uC = 1e-6 * C
nC = 1e-9 * C
- Ah = 3600. * C #amp-hour
+ Ah = 3600. * C # amp-hour
mAh = 1e-3 * Ah
# Current
@@ -345,82 +343,121 @@
k?? = kohm # easier-to-read alias
M?? = Mohm # easier-to-read alias
G?? = Gohm # easier-to-read alias
- S = 1./ohm #siemens
+ S = 1./ohm # siemens
mS = 1e-3 * S
uS = 1e-6 * S
nS = 1e-9 * S
# Magnetic fields and fluxes
global T, mT, uT, nT, G, mG, uG, kG, Oe, Wb
- T = (V * s) / m**2 #tesla
+ T = (V * s) / m**2 # tesla
mT = 1e-3 * T
uT = 1e-6 * T
nT = 1e-9 * T
- G = 1e-4 * T #gauss
+ G = 1e-4 * T # gauss
mG = 1e-3 * G
uG = 1e-6 * G
kG = 1e3 * G
- Oe = (1000./(4.*pi)) * A/m #oersted
- Wb = J/A #weber
+ Oe = (1000./(4.*pi)) * A/m # oersted
+ Wb = J/A # weber
# Capacitance and inductance
global F, uF, nF, pF, fF, aF, H, mH, uH, nH
- F = C / V #farad
+ F = C / V # farad
uF = 1e-6 * F
nF = 1e-9 * F
pF = 1e-12 * F
fF = 1e-15 * F
aF = 1e-18 * F
- H = m**2 * kg / C**2 #henry
+ H = m**2 * kg / C**2 # henry
mH = 1e-3 * H
uH = 1e-6 * H
nH = 1e-9 * H
- #Constants--general
+ # Constants--general
global c0, mu0, ??0, eps0, ??0, Z0, hPlanck, hbar, ??, kB, GNewton,
sigmaSB, ??SB, alphaFS, ??FS
- c0 = 299792458. * m/s #speed of light in vacuum
- mu0 = 1.25663706212e-6 * N/A**2 #magnetic constant, permeability of vacuum
+ c0 = 299792458. * m/s # speed of light in vacuum
+ mu0 = 1.25663706212e-6 * N/A**2 # magnetic constant, permeability of
vacuum
??0 = mu0 # easier-to-read alias (see https://sjbyrnes.com/unicode.html )
- eps0 = 1./(mu0 * c0**2) #electric constant, permittivity of vacuum
+ eps0 = 1./(mu0 * c0**2) # electric constant, permittivity of vacuum
??0 = eps0 # easier-to-read alias
- Z0 = mu0 * c0 #vacuum impedance, 377 ohms
- hPlanck = 6.62607015e-34 * J*s #planck constant
- hbar = hPlanck / (2.*pi) #reduced planck constant
+ Z0 = mu0 * c0 # vacuum impedance, 377 ohms
+ hPlanck = 6.62607015e-34 * J*s # planck constant
+ hbar = hPlanck / (2.*pi) # reduced planck constant
?? = hbar # easier-to-read alias
- kB = 1.380649e-23 * J/K #Boltzmann constant
- GNewton = 6.67430e-11 * m**3 / (kg * s**2) #Gravitational constant
- sigmaSB = (pi**2 / 60.) * kB**4 / (hbar**3 * c0**2) #Stefan-Boltzmann
constant
+ kB = 1.380649e-23 * J/K # Boltzmann constant
+ GNewton = 6.67430e-11 * m**3 / (kg * s**2) # Gravitational constant
+ sigmaSB = (pi**2 / 60.) * kB**4 / (hbar**3 * c0**2) # Stefan-Boltzmann
constant
??SB = sigmaSB # easier-to-read alias
- alphaFS = 7.2973525693e-3 #fine-structure constant
+ alphaFS = 7.2973525693e-3 # fine-structure constant
??FS = alphaFS # easier-to-read alias
- #Constants--chemistry, atomic physics, electrons
+ # Constants--chemistry, atomic physics, electrons
global Rgas, e, uBohr, uNuc, aBohr, me, mp, mn, Rinf, Ry, Hartree, \
ARichardson, Phi0, KJos, RKlitz
- Rgas = kB #ideal gas constant (see README)
- e = 1.602176634e-19 * C #charge of proton
- uBohr = 9.2740100783e-24 * J/T #Bohr magneton
- uNuc = 5.0507837461e-27 * J/T #nuclear magneton
- aBohr = 5.29177210903e-11 * m #Bohr radius
- me = 9.1093837015e-31 * kg #electron mass
- mp = 1.67262192369e-27 * kg #proton mass
- mn = 1.67492749804e-27 * kg #neutron mass
- Rinf = 10973731.568160 / m #Rydberg constant
- Ry = 2.1798723611035e-18 * J #Rydberg energy, approximately 13.6 eV
- Hartree = 2*Ry #Hartree energy, approximately 27.2 eV
- ARichardson = (4.*pi*e*me*kB**2) / hPlanck**3 #Richardson constant
- Phi0 = hPlanck / (2*e) #magnetic flux quantum
- KJos = (2*e) / hPlanck #Josephson constant
- RKlitz = hPlanck / e**2 #von Klitzing constant
+ Rgas = kB # ideal gas constant (see README)
+ e = 1.602176634e-19 * C # charge of proton
+ uBohr = 9.2740100783e-24 * J/T # Bohr magneton
+ uNuc = 5.0507837461e-27 * J/T # nuclear magneton
+ aBohr = 5.29177210903e-11 * m # Bohr radius
+ me = 9.1093837015e-31 * kg # electron mass
+ mp = 1.67262192369e-27 * kg # proton mass
+ mn = 1.67492749804e-27 * kg # neutron mass
+ Rinf = 10973731.568160 / m # Rydberg constant
+ Ry = 2.1798723611035e-18 * J # Rydberg energy, approximately 13.6 eV
+ Hartree = 2*Ry # Hartree energy, approximately 27.2 eV
+ ARichardson = (4.*pi*e*me*kB**2) / hPlanck**3 # Richardson constant
+ Phi0 = hPlanck / (2*e) # magnetic flux quantum
+ KJos = (2*e) / hPlanck # Josephson constant
+ RKlitz = hPlanck / e**2 # von Klitzing constant
- #Constants--astronomical and properties of earth
+ # Constants--astronomical and properties of earth
global REarth, g0, Msolar, MEarth
- REarth = 6371. * km #radius of earth
- g0 = 9.80665 * m / s**2 #standard earth gravitational acceleration
- Msolar = 1.98847e30 * kg #mass of the sun
- MEarth = 5.9722e24 * kg #mass of earth
+ REarth = 6371. * km # radius of earth
+ g0 = 9.80665 * m / s**2 # standard earth gravitational acceleration
+ Msolar = 1.98847e30 * kg # mass of the sun
+ MEarth = 5.9722e24 * kg # mass of earth
# Set units randomly when this module is initialized. (Don't worry: If the
# module is imported many times from many places, this command will only
# execute during the first import.)
reset_units()
+
+
+def nu_eval(expression):
+ """
+ Evaluates a string expression in the context of this module, so that you
+ can make APIs that don't require their users to import numericalunits;
+ instead the API user can run a function like load_data(data, unit='km')
+
+ For example:
+
+ import numericalunits as nu
+ x = nu.nu_eval('kg * m / s**2')
+
+ ...is exactly equivalent to...
+
+ import numericalunits as nu
+ x = nu.kg * nu.m / nu.s**2
+
+ Input strings are required to be of the form of stereotypical unit
+ expressions???e.g. addition and subtraction are banned???to catch user
errors.
+ """
+ # Based on https://stackoverflow.com/a/9558001
+ import ast
+ import operator as op
+ operators = {ast.Mult: op.mul, ast.Div: op.truediv, ast.Pow: op.pow,
ast.USub: op.neg}
+
+ def _eval(node):
+ if isinstance(node, ast.Num):
+ return node.n
+ elif isinstance(node, ast.BinOp): # <left> <operator> <right>
+ return operators[type(node.op)](_eval(node.left),
_eval(node.right))
+ elif isinstance(node, ast.UnaryOp): # <operator> <operand> e.g., -1
+ return operators[type(node.op)](_eval(node.operand))
+ elif isinstance(node, ast.Name):
+ return globals()[node.id]
+ else:
+ raise TypeError(node)
+
+ return _eval(ast.parse(expression, mode='eval').body)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/numericalunits-1.24/tests/tests.py
new/numericalunits-1.25/tests/tests.py
--- old/numericalunits-1.24/tests/tests.py 2019-11-30 02:18:15.000000000
+0100
+++ new/numericalunits-1.25/tests/tests.py 2020-07-12 20:12:32.000000000
+0200
@@ -4,32 +4,33 @@
"""
import unittest
import numericalunits as nu
+from math import isclose
class TestStuff(unittest.TestCase):
def setUp(self):
pass
- def assert_almost_equal(self, a, b, rtol):
- """helper function to check if two floats are approximately equal,
- allowing for rounding errors etc. Similar to math.isclose in py3."""
- self.assertTrue(abs(a-b) <= rtol * (abs(a) + abs(b)))
-
def test_everything(self):
"""just some very basic smoke tests"""
# example from README
- x = 5 * nu.mL
- self.assert_almost_equal(x, 5e21 * nu.nm**3, rtol=1e-9)
+ self.assertTrue(isclose(5 * nu.mL, 5e21 * nu.nm**3, rel_tol=1e-9))
# example from README
Efield = 1e5 * (nu.V / nu.cm)
force = nu.e * Efield
accel = force / nu.me
- self.assert_almost_equal(accel, 1.75882002e18 * nu.m / nu.s**2,
rtol=1e-6)
+ self.assertTrue(isclose(accel, 1.75882002e18 * nu.m / nu.s**2,
rel_tol=1e-6))
+
+ # check nu_eval()
+ self.assertTrue(isclose(nu.nu_eval('kg'), nu.kg, rel_tol=1e-9))
+ self.assertTrue(isclose(nu.nu_eval('kg * m / s**2'), nu.kg * nu.m /
nu.s**2, rel_tol=1e-9))
+ self.assertTrue(isclose(nu.nu_eval('kg**-3.6'), nu.kg**-3.6,
rel_tol=1e-9))
# make sure reset_units('SI') works
nu.reset_units('SI')
- self.assert_almost_equal(nu.G, 1e-4, rtol=1e-9)
+ self.assertTrue(isclose(nu.G, 1e-4, rel_tol=1e-9))
+
if __name__ == '__main__':
unittest.main()