Skip to content

Commit

Permalink
Add example to and unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnymaserati committed Dec 16, 2023
1 parent 6d31218 commit 374a056
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
43 changes: 43 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import inspect
import sys

from welleng.units import ureg
from welleng.utils import annular_volume


def test_annular_volume():
av = annular_volume(
od=ureg('12.25 inch').to('meter'),
id=ureg(f'{9+5/8} inch').to('meter'),
length=ureg('1000 meter')
)

assert av.m == 3.491531223156194
assert str(av.u) == 'meter ** 3'

pass


def one_function_to_run_them_all():
"""
Function to gather the test functions so that they can be tested by
running this module.
https://stackoverflow.com/questions/18907712/python-get-list-of-all-
functions-in-current-module-inspecting-current-module
"""
test_functions = [
obj for name, obj in inspect.getmembers(sys.modules[__name__])
if (inspect.isfunction(obj)
and name.startswith('test')
and name != 'all')
]

for f in test_functions:
f()

pass


if __name__ == '__main__':
one_function_to_run_them_all()
8 changes: 1 addition & 7 deletions welleng/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
except ImportError:
MAG_CALC = False
from datetime import datetime
try:
from pyproj import CRS, Proj
GRID_CALC = True
except ImportError:
GRID_CALC = False
from pyproj import CRS, Proj
from scipy.optimize import minimize
from scipy.spatial.transform import Rotation as R

Expand Down Expand Up @@ -70,8 +66,6 @@ def __init__(self, projection: str = "EPSG:23031") -> None:
---------
For codes refer to [EPSG](https://epsg.io).
"""
if not GRID_CALC:
raise ImportError('pyproj dependency required, try ``pip install pyproj``.')
self.crs = CRS(projection)
super().__init__(self.crs)

Expand Down
13 changes: 13 additions & 0 deletions welleng/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,19 @@ def annular_volume(od: float, id: float = None, length: float = None):
-------
annular_volume: float
The (unit) volume of the annulus or cylinder.
Example
-------
```python
>>> from welleng.utils import annular_volume
>>> from welleng.units import ureg
>>> av = annular_volume(
... od=ureg('12.25 inch').to('meters),
... id=ureg(f'{9+5/8} inch').to('meter'),
... length=ureg('1000 meter')
... )
>>> print(av)
... 3.491531223156194 meter ** 3
"""
length = 1 if length is None else length
id = 0 if id is None else id
Expand Down

0 comments on commit 374a056

Please sign in to comment.