Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
CSIRO Geoscience Analytics
python-shared
nvcl_kit
Commits
7a526712
Commit
7a526712
authored
Nov 18, 2020
by
Vincent Fazio
Committed by
Vincent Fazio
Nov 27, 2020
Browse files
NVCL-58 Add parameter testing to asud
parent
4dfbeace
Pipeline
#221957832
passed with stages
in 3 minutes and 34 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
9 deletions
+58
-9
demo.py
demo.py
+3
-2
nvcl_kit/asud.py
nvcl_kit/asud.py
+22
-3
test/test_asud.py
test/test_asud.py
+33
-0
test/test_reader.py
test/test_reader.py
+0
-4
No files found.
demo.py
View file @
7a526712
...
...
@@ -8,7 +8,8 @@ import yaml
#
# A very rough script to demonstrate 'nvcl_kit'
#
# NB: requires 'pyyaml' - install via 'pip3 install pyyaml'
#
# Provider list. Format is (WFS service URL, NVCL service URL, bounding box coords, local filtering, WFS version, max boreholes))
prov_list
=
[
(
"http://www.mrt.tas.gov.au:80/web-services/ows"
,
"http://www.mrt.tas.gov.au/NVCLDataServices/"
,
{
"west"
:
143.75
,
"south"
:
-
43.75
,
"east"
:
148.75
,
"north"
:
-
39.75
},
False
,
"1.1.0"
,
20
),
...
...
@@ -47,7 +48,7 @@ def do_demo(wfs, nvcl, bbox, local_filt, version, max):
bh_list
=
reader
.
get_boreholes_list
()
print
(
"len(bh_list) = "
,
len
(
bh_list
))
# Print borehole details and Australian Stratigraphic Units Database
records
# Print borehole details and
relevant records from
Australian Stratigraphic Units Database
(https://asud.ga.gov.au/)
for
bh
in
bh_list
[:
5
]:
print
(
"
\n
BOREHOLE:"
)
print
(
yaml
.
dump
(
bh
))
...
...
nvcl_kit/asud.py
View file @
7a526712
...
...
@@ -121,11 +121,30 @@ def _get_asud_strat_no(lon, lat):
def
get_asud_record
(
lon
,
lat
):
''' Retrieves a stratigraphy record from the 'Australian Strategraphic Units Database'
:param lon: longitude
:param lat: latitude
:param lon: longitude
(float or string)
:param lat: latitude
(float or string)
:returns: stratigraphy record as a dict or None upon error or not found
'''
strat_no
=
_get_asud_strat_no
(
lon
,
lat
)
# Check input parameters
if
not
isinstance
(
lon
,
float
):
try
:
lon_flt
=
float
(
lon
)
except
(
ValueError
,
TypeError
):
LOGGER
.
warning
(
"lon parameter is not a float"
)
return
None
else
:
lon_flt
=
lon
if
not
isinstance
(
lat
,
float
):
try
:
lat_flt
=
float
(
lat
)
except
(
ValueError
,
TypeError
):
LOGGER
.
warning
(
"lat parameter is not a float"
)
return
None
else
:
lat_flt
=
lat
strat_no
=
_get_asud_strat_no
(
lon_flt
,
lat_flt
)
if
strat_no
is
not
None
:
try
:
resp
=
post
(
GSUD_API
,
data
=
json
.
dumps
({
"actionName"
:
"searchStratigraphicUnitsDetails"
,
"stratNo"
:
strat_no
}))
...
...
test/test_asud.py
0 → 100755
View file @
7a526712
#!/usr/bin/env python3
import
sys
,
os
import
unittest
from
unittest.mock
import
patch
,
Mock
from
requests.exceptions
import
Timeout
,
RequestException
from
owslib.util
import
ServiceException
from
http.client
import
HTTPException
import
logging
from
types
import
SimpleNamespace
from
nvcl_kit.asud
import
get_asud_record
class
TestNVCLAsud
(
unittest
.
TestCase
):
def
try_input_param
(
self
,
lon
,
lat
,
msg
):
''' Used to test variations in erroneous input parameters
:param lon: longitude (float)
:param lat: latitude (float)
:param msg: expected warning message
'''
with
self
.
assertLogs
(
'nvcl_kit.asud'
,
level
=
'WARN'
)
as
nvcl_log
:
rec
=
get_asud_record
(
lon
,
lat
)
self
.
assertIn
(
msg
,
nvcl_log
.
output
[
0
])
self
.
assertEqual
(
rec
,
None
)
def
test_params
(
self
):
''' Tests exception handling in get_borehole_data()
'''
self
.
try_input_param
(
0.0
,
None
,
'lat parameter is not a float'
)
self
.
try_input_param
(
None
,
8.0
,
'lon parameter is not a float'
)
self
.
try_input_param
(
None
,
""
,
'lon parameter is not a float'
)
test/test_reader.py
View file @
7a526712
...
...
@@ -776,7 +776,3 @@ class TestNVCLReader(unittest.TestCase):
self
.
assertEqual
(
log_list
[
0
].
log_id
,
'b80a98e4-6d9b-4a58-ab04-d105c172e67'
)
self
.
assertEqual
(
log_list
[
0
].
log_name
,
'Imagery'
)
self
.
assertEqual
(
log_list
[
0
].
sample_count
,
30954
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment