Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lemi2seed
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Public
MT
lemi2seed
Commits
1b14ecea
Commit
1b14ecea
authored
3 years ago
by
Maeva Pourpoint
Browse files
Options
Downloads
Patches
Plain Diff
Unit tests for Station level classes
parent
2eea166e
No related branches found
No related tags found
1 merge request
!6
Metadata station level
Pipeline
#1377
passed with stage
in 5 minutes and 6 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_lemi_metadata.py
+79
-1
79 additions, 1 deletion
tests/test_lemi_metadata.py
with
79 additions
and
1 deletion
tests/test_lemi_metadata.py
+
79
−
1
View file @
1b14ecea
...
...
@@ -10,7 +10,8 @@ from obspy import UTCDateTime
from
pathlib
import
Path
from
lemi2seed.lemi_data
import
LemiData
from
lemi2seed.lemi_metadata
import
BaseSurvey
,
Survey
,
log_file_path
from
lemi2seed.lemi_metadata
import
(
BaseSurvey
,
Survey
,
BaseStation
,
Station_
,
log_file_path
)
OUTPUT_MSEED
=
Path
(
__file__
).
parent
.
joinpath
(
'
MSEED
'
)
TEST_DIR
=
Path
(
__file__
).
parent
.
joinpath
(
'
test_data
'
)
...
...
@@ -171,3 +172,80 @@ class TestSurvey(unittest.TestCase):
"""
Test basic functionality of validate_citation_dataset_doi.
"""
emails
=
'
m@passcal.edu, d@passcal.edu
'
self
.
assertTrue
(
Survey
.
validate_project_lead_email
(
emails
))
class
TestBaseStation
(
unittest
.
TestCase
):
"""
Test suite for BaseStation data class.
"""
def
setUp
(
self
):
"""
Set up test fixtures
"""
data_input
=
2201.77
min_elev
,
max_elev
=
[
abs
(
data_input
)
*
x
for
x
in
[
0.99
,
1.01
]]
param
=
(
"
Station elevation
"
,
-
500
,
8500
,
min_elev
,
max_elev
,
'
m
'
,
''
)
self
.
param
=
param
def
test_validate_geographics_undefined
(
self
):
"""
Test basic functionality of validate_geographics.
"""
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
BaseStation
.
validate_geographics
(
self
.
param
,
None
)
msg
=
"
Station elevation should be a float.
"
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
def
test_validate_geographics_erroneous_type
(
self
):
"""
Test basic functionality of validate_geographics.
"""
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
BaseStation
.
validate_geographics
(
self
.
param
,
'
a
'
)
msg
=
"
Station elevation should be a float.
"
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
def
test_validate_geographics_not_in_range
(
self
):
"""
Test basic functionality of validate_geographics.
"""
geo
,
min_range
,
max_range
,
min_val
,
max_val
,
units
,
msg
=
self
.
param
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
BaseStation
.
validate_geographics
(
self
.
param
,
9000
)
msg
=
(
"
Unexpected {0}! The {0} should be between {1}{3} and {2}{3}.
"
.
format
(
geo
,
min_range
,
max_range
,
units
))
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
def
test_validate_geographics_do_not_match_logger_recorded_metadata
(
self
):
"""
Test basic functionality of validate_geographics.
"""
geo
=
'
Station elevation
'
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
BaseStation
.
validate_geographics
(
self
.
param
,
2250
)
msg
=
(
"
Unexpected {0}! Provided {0} should roughly match the {0}
"
"
recorded by the on-site GPS.
"
.
format
(
geo
))
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
class
TestStation_
(
unittest
.
TestCase
):
"""
Test suite for Station_ data class.
"""
def
test_validate_archive_id_undefined
(
self
):
"""
Test basic functionality of validate_archive_id.
"""
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
Station_
.
validate_archive_id
(
None
)
msg
=
"
The station name should be a string.
"
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
def
test_validate_archive_id_erroneous_type
(
self
):
"""
Test basic functionality of validate_archive_id.
"""
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
Station_
.
validate_archive_id
(
12
)
msg
=
"
The station name should be a string.
"
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
def
test_validate_archive_id_invalid
(
self
):
"""
Test basic functionality of validate_archive_id.
"""
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
Station_
.
validate_archive_id
(
'
KELLYA
'
)
msg
=
(
"
The station name should be between three and five
"
"
alphanumeric character long.
"
)
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
def
test_validate_archive_id_valid
(
self
):
"""
Test basic functionality of validate_archive_id.
"""
self
.
assertTrue
(
Station_
.
validate_archive_id
(
'
KELLY
'
))
def
test_validate_submitter_email_undefined
(
self
):
"""
Test basic functionality of validate_submitter_email.
"""
self
.
assertTrue
(
Station_
.
validate_submitter_email
(
None
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment