Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
geomag-algorithms
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
ghsc
National Geomagnetism Program
geomag-algorithms
Commits
13de5c59
Commit
13de5c59
authored
10 years ago
by
Hal Simpson
Browse files
Options
Downloads
Patches
Plain Diff
Removed test for unused methods, added tests for all remaining methods.
parent
b775212f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
geomagio/edge/EdgeFactory_test.py
+80
-35
80 additions, 35 deletions
geomagio/edge/EdgeFactory_test.py
with
80 additions
and
35 deletions
geomagio/edge/EdgeFactory_test.py
+
80
−
35
View file @
13de5c59
"""
Tests for EdgeFactory.py
"""
from
obspy.core.utcdatetime
import
UTCDateTime
from
obspy.core.stream
import
Stream
from
obspy.core.trace
import
Trace
from
EdgeFactory
import
EdgeFactory
from
nose.tools
import
assert_equals
from
nose.tools
import
assert_raises
from
geomagio
import
TimeseriesFactoryException
def
test_get_
edge_channel_codes
():
"""
geomagio.edge.EdgeFactory_test.test_get_
edge_channel_codes
()
def
test_get_
type_from_edge
():
"""
geomagio.edge.EdgeFactory_test.test_get_
type_from_edge
()
"""
# 1) Call get_edge_channel_codes with minute, variation and H,
# expect MVH back
channels
=
EdgeFactory
().
get_edge_channel_codes
(
'
BOU
'
,
(
'
H
'
),
'
variation
'
,
'
minute
'
)
assert_equals
(
channels
,
[
'
MVH
'
],
'
Expect edge channel to equal MVH
'
)
# 2) Call get_edge_channel_codes with second, variation and [H,D,Z,F],
# expect SVN, SVD, SVZ and SSF back
channels
=
EdgeFactory
().
get_edge_channel_codes
(
'
BOU
'
,
(
'
H
'
,
'
D
'
,
'
Z
'
,
'
F
'
),
'
variation
'
,
'
second
'
)
assert_equals
(
channels
[
0
],
'
SVH
'
,
'
Expect edge channels to equal SVH
'
)
assert_equals
(
channels
[
1
],
'
SVD
'
,
'
Expect edge channels to equal SVD
'
)
assert_equals
(
channels
[
2
],
'
SVZ
'
,
'
Expect edge channels to equal SVZ
'
)
assert_equals
(
channels
[
3
],
'
SSF
'
,
'
Expect edge channels to equal SSF
'
)
# Call get_type_from_edge, make certain it returns the type
assert_equals
(
EdgeFactory
().
get_type_from_edge
(
'
R0
'
),
'
variation
'
)
assert_equals
(
EdgeFactory
().
get_type_from_edge
(
'
R1
'
),
'
variation
'
)
assert_equals
(
EdgeFactory
().
get_type_from_edge
(
'
Q0
'
),
'
quasi-definitive
'
)
assert_equals
(
EdgeFactory
().
get_type_from_edge
(
'
D0
'
),
'
definitive
'
)
def
test_get_
interval_from_edge
():
"""
geomagio.edge.EdgeFactory_test.test_get_
interval_from_edge
()
def
test_
_
get_
edge_network
():
"""
geomagio.edge.EdgeFactory_test.test_
_
get_
edge_network
()
"""
# 1) Call get_interval_from_edge with Minute channels, get minute back.
assert_equals
(
EdgeFactory
().
get_interval_from_edge
(
(
'
MVH
'
,
'
MVE
'
)),
'
minute
'
)
# 2) Call get_interval_from_edge with Mixed channels, raise exception.
assert_raises
(
TimeseriesFactoryException
,
EdgeFactory
().
get_interval_from_edge
,
(
'
MVH
'
,
'
SVE
'
))
# _get_edge_network should always return NT for use by USGS geomag
assert_equals
(
EdgeFactory
().
_get_edge_network
(
'
'
,
'
'
,
'
'
,
'
'
),
'
NT
'
)
def
test__get_edge_
code_from_channel
():
"""
geomagio.edge.EdgeFactory_test.test__get_edge_
code_from_channel
()
def
test__get_edge_
station
():
"""
geomagio.edge.EdgeFactory_test.test__get_edge_
station
()
"""
# Call private function _get_edge_code_from_channel, make certain
# _get_edge_station will return the observatory code passed in.
assert_equals
(
EdgeFactory
().
_get_edge_station
(
'
BOU
'
,
'
'
,
'
'
,
'
'
),
'
BOU
'
)
def
test__get_edge_channel
():
"""
geomagio.edge.EdgeFactory_test.test__get_edge_channel()
"""
# Call private function _get_edge_channel, make certain
# it gets back the appropriate 2 character code.
assert_equals
(
EdgeFactory
().
_get_edge_code_from_channel
(
'
D
'
),
'
VD
'
)
assert_equals
(
EdgeFactory
().
_get_edge_code_from_channel
(
'
E
'
),
'
VE
'
)
assert_equals
(
EdgeFactory
().
_get_edge_code_from_channel
(
'
F
'
),
'
SF
'
)
assert_equals
(
EdgeFactory
().
_get_edge_code_from_channel
(
'
H
'
),
'
VH
'
)
assert_equals
(
EdgeFactory
().
_get_edge_code_from_channel
(
'
Z
'
),
'
VZ
'
)
assert_equals
(
EdgeFactory
().
_get_edge_channel
(
''
,
'
D
'
,
''
,
'
minute
'
),
'
MVD
'
)
assert_equals
(
EdgeFactory
().
_get_edge_channel
(
''
,
'
E
'
,
''
,
'
minute
'
),
'
MVE
'
)
assert_equals
(
EdgeFactory
().
_get_edge_channel
(
''
,
'
F
'
,
''
,
'
minute
'
),
'
MSF
'
)
assert_equals
(
EdgeFactory
().
_get_edge_channel
(
''
,
'
H
'
,
''
,
'
minute
'
),
'
MVH
'
)
assert_equals
(
EdgeFactory
().
_get_edge_channel
(
''
,
'
Z
'
,
''
,
'
minute
'
),
'
MVZ
'
)
def
test__get_edge_location
():
"""
geomagio.edge.EdgeFactory_test.test__get_edge_location()
"""
# Call _get_edge_location, make certain it returns the correct edge
# location code.
assert_equals
(
EdgeFactory
().
_get_edge_location
(
''
,
''
,
'
variation
'
,
''
),
'
R0
'
)
assert_equals
(
EdgeFactory
().
_get_edge_location
(
''
,
''
,
'
quasi-definitive
'
,
''
),
'
Q0
'
)
assert_equals
(
EdgeFactory
().
_get_edge_location
(
''
,
''
,
'
definitive
'
,
''
),
'
D0
'
)
def
test__get_interval_from_code
():
"""
geomagio.edge.EdgeFactory_test.test__get_interval_from_code()
"""
# Call _get_interval_from_code with an edge interval code. Make certain
# it returns the appropriate interval.
assert_equals
(
EdgeFactory
().
_get_interval_from_code
(
'
M
'
),
'
minute
'
)
assert_equals
(
EdgeFactory
().
_get_interval_from_code
(
'
S
'
),
'
second
'
)
def
test__get_interval_code
():
"""
geomagio.edge.EdgeFactory_test.test__get_interval_code()
"""
assert_equals
(
EdgeFactory
().
_get_interval_code
(
'
daily
'
),
'
D
'
)
assert_equals
(
EdgeFactory
().
_get_interval_code
(
'
hourly
'
),
'
H
'
)
assert_equals
(
EdgeFactory
().
_get_interval_code
(
'
minute
'
),
'
M
'
)
assert_equals
(
EdgeFactory
().
_get_interval_code
(
'
second
'
),
'
S
'
)
def
test__set_metadata
():
"""
geomagio.edge.EdgeFactory_test.test__set_metadata()
"""
# Call _set_metadata with 2 traces, and make certain the stats get
# set for both traces.
trace1
=
Trace
()
trace2
=
Trace
()
stream
=
Stream
(
traces
=
[
trace1
,
trace2
])
EdgeFactory
().
_set_metadata
(
stream
,
'
BOU
'
,
'
H
'
,
'
variation
'
,
'
minute
'
)
assert_equals
(
stream
[
0
].
stats
[
'
channel
'
],
'
H
'
)
assert_equals
(
stream
[
1
].
stats
[
'
channel
'
],
'
H
'
)
# def test_get_timeseries():
...
...
@@ -59,5 +102,7 @@ def dont_get_timeseries():
timeseries
=
edge_factory
.
get_timeseries
(
UTCDateTime
(
2015
,
3
,
1
,
0
,
0
,
0
),
UTCDateTime
(
2015
,
3
,
1
,
1
,
0
,
0
),
'
BOU
'
,
(
'
H
'
),
'
variation
'
,
'
minute
'
)
assert_equals
(
timeseries
.
select
(
channel
=
'
MV
H
'
)[
0
].
stats
.
station
,
assert_equals
(
timeseries
.
select
(
channel
=
'
H
'
)[
0
].
stats
.
station
,
'
BOU
'
,
'
Expect timeseries to have stats
'
)
assert_equals
(
timeseries
.
select
(
channel
=
'
H
'
)[
0
].
stats
.
channel
,
'
H
'
,
'
Expect timeseries stats channel to be equal to H
'
)
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