Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SOHViewer
Manage
Activity
Members
Labels
Plan
Issues
11
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
3
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
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
PASSOFT
SOHViewer
Commits
725c139b
Commit
725c139b
authored
2 years ago
by
Kien Le
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for downsample
parent
9a87a89d
No related branches found
No related tags found
1 merge request
!27
Draft: Add tests for functions in handling_data.py
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_model/test_handling_data.py
+54
-2
54 additions, 2 deletions
tests/test_model/test_handling_data.py
with
54 additions
and
2 deletions
tests/test_model/test_handling_data.py
+
54
−
2
View file @
725c139b
...
...
@@ -12,7 +12,7 @@ from copy import copy as shallow_copy
import
tracemalloc
from
unittest
import
TestCase
,
expectedFailure
from
unittest.mock
import
patch
from
unittest.mock
import
patch
,
DEFAULT
from
obspy.core
import
Trace
,
read
as
read_ms
import
numpy
as
np
...
...
@@ -31,7 +31,9 @@ from sohstationviewer.model.handling_data import (
checkWFChan
,
checkSOHChan
,
sortData
,
squash_gaps
squash_gaps
,
downsample
,
chunk_minmax
)
from
sohstationviewer.model.reftek.from_rt2ms.core
import
Reftek130
...
...
@@ -775,3 +777,53 @@ class TestSquashGaps(TestCase):
def
test_no_gap_in_data
(
self
):
gaps
=
[]
self
.
assertListEqual
(
squash_gaps
(
gaps
),
[])
class
TestDownsample
(
TestCase
):
def
setUp
(
self
)
->
None
:
patcher
=
patch
(
'
sohstationviewer.model.handling_data.chunk_minmax
'
)
self
.
addCleanup
(
patcher
.
stop
)
self
.
mock_chunk_minmax
=
patcher
.
start
()
self
.
times
=
np
.
arange
(
1000
)
self
.
data
=
np
.
arange
(
1000
)
def
test_first_downsample_step_remove_enough_points
(
self
):
req_points
=
999
downsample
(
self
.
times
,
self
.
data
,
req_points
)
self
.
assertFalse
(
self
.
mock_chunk_minmax
.
called
)
def
test_second_downsample_step_required
(
self
):
req_points
=
1
downsample
(
self
.
times
,
self
.
data
,
req_points
)
self
.
assertTrue
(
self
.
mock_chunk_minmax
.
called
)
times
,
data
,
_
=
self
.
mock_chunk_minmax
.
call_args
[
0
]
self
.
assertIsNot
(
times
,
self
.
times
)
self
.
assertIsNot
(
data
,
self
.
data
)
def
test_requested_points_greater_than_data_size
(
self
):
req_points
=
10000
times
,
data
,
=
downsample
(
self
.
times
,
self
.
data
,
req_points
)
self
.
assertFalse
(
self
.
mock_chunk_minmax
.
called
)
# Check that we did not do any processing on the times and data arrays.
# This ensures that we don't do two unneeded copy operations.
self
.
assertIs
(
times
,
self
.
times
)
self
.
assertIs
(
data
,
self
.
data
)
def
test_requested_points_is_zero
(
self
):
req_points
=
0
downsample
(
self
.
times
,
self
.
data
,
req_points
)
self
.
assertTrue
(
self
.
mock_chunk_minmax
.
called
)
times
,
data
,
_
=
self
.
mock_chunk_minmax
.
call_args
[
0
]
self
.
assertIsNot
(
times
,
self
.
times
)
self
.
assertIsNot
(
data
,
self
.
data
)
def
test_empty_times_and_data
(
self
):
req_points
=
1000
self
.
times
=
np
.
empty
((
0
,
0
))
self
.
data
=
np
.
empty
((
0
,
0
))
times
,
data
=
downsample
(
self
.
times
,
self
.
data
,
req_points
)
self
.
assertFalse
(
self
.
mock_chunk_minmax
.
called
)
# Check that we did not do any processing on the times and data arrays.
# This ensures that we don't do two unneeded copy operations.
self
.
assertIs
(
times
,
self
.
times
)
self
.
assertIs
(
data
,
self
.
data
)
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