From 51cd37ad78cdcb76599d4216a0cba3ccd63e686b Mon Sep 17 00:00:00 2001 From: Adios Automated Script Date: Mon, 29 Nov 2021 21:47:19 -0800 Subject: [PATCH] fixed lru_cache on vapor_pressure --- oil_library/__init__.py | 2 +- oil_library/oil_props.py | 6 +++++ oil_library/tests/test_oil_props.py | 40 +++++++++++++++++++++++++++++ setup.py | 4 +-- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/oil_library/__init__.py b/oil_library/__init__.py index c6f2161..57d0209 100644 --- a/oil_library/__init__.py +++ b/oil_library/__init__.py @@ -15,7 +15,7 @@ from .models import DBSession -__version__ = '2.0.0' +__version__ = '2.0.1' # diff --git a/oil_library/oil_props.py b/oil_library/oil_props.py index 587f7be..990b01a 100644 --- a/oil_library/oil_props.py +++ b/oil_library/oil_props.py @@ -314,6 +314,12 @@ def __eq__(self, other): except Exception: return False + def __hash__(self): + """ + so that we can use lru_cache on the methods of the object + """ + return id(self) + def __ne__(self, other): return not self == other diff --git a/oil_library/tests/test_oil_props.py b/oil_library/tests/test_oil_props.py index 75afdb8..ee3da86 100644 --- a/oil_library/tests/test_oil_props.py +++ b/oil_library/tests/test_oil_props.py @@ -194,3 +194,43 @@ def test_deepcopy(self): assert getattr(op, item) is getattr(dcop, item) else: assert getattr(op, item) is not getattr(dcop, item) + + +def test_hash(): + """ + make sure OilProps is hashable + """ + op = get_oil_props('ALASKA NORTH SLOPE (MIDDLE PIPELINE, 1997)') + + print(dir(op)) + print(op.__hash__) + print(f"Hash is: {op.__hash__()}") + + # this may change, but fpr now + assert hash(op) == id(op) + + +def test_vapor_pressure(): + + # making sure the lru_cache works + op = get_oil_props('ALASKA NORTH SLOPE (MIDDLE PIPELINE, 1997)') + + vp = op.vapor_pressure(303) + + print(f"{vp=}") + + # I have no idea if these values are correct + assert np.allclose(vp, np.array([4.25112967e+04, 4.25112967e+04, + 4.33030879e+03, 4.33030879e+03, + 3.44544154e+02, 3.44544154e+02, + 2.11131481e+01, 2.11131481e+01, + 1.03347266e+00, 1.03347266e+00, + 4.67207773e-02, 4.67207773e-02, + 2.25663515e-03, 2.25663515e-03, + 1.34558585e-04, 1.34558585e-04, + 2.73632461e-05, 2.73632461e-05, + 1.91947361e-05, 1.91947361e-05, + 4.83593789e-19, 4.83593789e-19])) + + + diff --git a/setup.py b/setup.py index ccb68d2..88c9cc1 100755 --- a/setup.py +++ b/setup.py @@ -162,8 +162,8 @@ def run(self): # build_py is an old-style class, so we can't use super() build_py.run(self) -DESCRIPTION = ('{}: The NOAA library of oils and their properties.\n' - 'Branch: {}\n' +DESCRIPTION = ('{}: The NOAA library of oils and their properties.' + 'Branch: {}' 'LastUpdate: {}' .format(pkg_name, *get_repo_data()) )