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
b1f76599
Commit
b1f76599
authored
2 years ago
by
Kien Le
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for checkChan
parent
45a8590d
No related branches found
Branches containing commit
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
+64
-27
64 additions, 27 deletions
tests/test_model/test_handling_data.py
with
64 additions
and
27 deletions
tests/test_model/test_handling_data.py
+
64
−
27
View file @
b1f76599
...
...
@@ -20,6 +20,9 @@ from sohstationviewer.model.handling_data import (
readASCII
,
readText
,
saveData2File
,
checkChan
,
checkWFChan
,
checkSOHChan
)
from
sohstationviewer.model.reftek.from_rt2ms.core
import
Reftek130
...
...
@@ -121,18 +124,6 @@ class TestHandlingData(TestCase):
self
.
assertTrue
(
mock_save_data_2_file
.
called
)
# @skip
# def test_read_text(self):
# self.fail()
#
# @skip
# def test_save_data2file(self):
# self.fail()
#
# @skip
# def test_check_chan(self):
# self.fail()
#
# @skip
# def test_check_sohchan(self):
# self.fail()
...
...
@@ -201,8 +192,8 @@ class TestReadWaveformMSeed(TestCase):
patcher
=
patch
(
'
sohstationviewer.model.handling_data.readWaveformTrace
'
)
self
.
addCleanup
(
patcher
.
stop
)
self
.
mock_read
W
aveform
T
race
=
patcher
.
start
()
self
.
mock_read
W
aveform
T
race
.
return_value
=
{
self
.
mock_read
_w
aveform
_t
race
=
patcher
.
start
()
self
.
mock_read
_w
aveform
_t
race
.
return_value
=
{
'
startTmEpoch
'
:
0
,
'
endTmEpoch
'
:
0
,
}
...
...
@@ -223,10 +214,10 @@ class TestReadWaveformMSeed(TestCase):
self
.
q330_waveform_file
,
self
.
q330_waveform_file
.
name
,
self
.
station_id
,
self
.
channel_id
,
self
.
traces_info
,
self
.
data_time
,
self
.
temp_dir
.
name
)
self
.
assertTrue
(
self
.
mock_read
W
aveform
T
race
.
called
)
self
.
assertTrue
(
self
.
mock_read
_w
aveform
_t
race
.
called
)
def
test_start_data_time_earlier_than_earliest_start_time
(
self
):
self
.
mock_read
W
aveform
T
race
.
return_value
=
{
self
.
mock_read
_w
aveform
_t
race
.
return_value
=
{
'
startTmEpoch
'
:
51251
,
'
endTmEpoch
'
:
2623623
,
}
...
...
@@ -242,7 +233,7 @@ class TestReadWaveformMSeed(TestCase):
def
test_end_data_time_later_than_latest_start_time
(
self
):
# End time set to be the last second of 9999 so as to be later than the
# end time of any test data.
self
.
mock_read
W
aveform
T
race
.
return_value
=
{
self
.
mock_read
_w
aveform
_t
race
.
return_value
=
{
'
startTmEpoch
'
:
51251
,
'
endTmEpoch
'
:
2623623
,
}
...
...
@@ -256,7 +247,7 @@ class TestReadWaveformMSeed(TestCase):
self
.
assertEqual
(
self
.
data_time
[
1
],
end_time
)
def
test_data_time_is_between_earliest_start_and_latest_end_time
(
self
):
self
.
mock_read
W
aveform
T
race
.
return_value
=
{
self
.
mock_read
_w
aveform
_t
race
.
return_value
=
{
'
startTmEpoch
'
:
51251
,
'
endTmEpoch
'
:
2623623
,
}
...
...
@@ -299,8 +290,8 @@ class TestReadWaveformReftek(TestCase):
patcher
=
patch
(
'
sohstationviewer.model.handling_data.readWaveformTrace
'
)
self
.
addCleanup
(
patcher
.
stop
)
self
.
mock_read
W
aveform
T
race
=
patcher
.
start
()
self
.
mock_read
W
aveform
T
race
.
return_value
=
{
self
.
mock_read
_w
aveform
_t
race
=
patcher
.
start
()
self
.
mock_read
_w
aveform
_t
race
.
return_value
=
{
'
startTmEpoch
'
:
0
,
'
endTmEpoch
'
:
0
,
}
...
...
@@ -335,10 +326,10 @@ class TestReadWaveformReftek(TestCase):
def
test_readWaveformTrace_called
(
self
):
readWaveformReftek
(
self
.
rt130_waveform
,
self
.
key
,
self
.
read_data
,
self
.
data_time
,
self
.
temp_dir
.
name
)
self
.
assertTrue
(
self
.
mock_read
W
aveform
T
race
.
called
)
self
.
assertTrue
(
self
.
mock_read
_w
aveform
_t
race
.
called
)
def
test_start_data_time_earlier_than_earliest_start_time
(
self
):
self
.
mock_read
W
aveform
T
race
.
return_value
=
{
self
.
mock_read
_w
aveform
_t
race
.
return_value
=
{
'
startTmEpoch
'
:
51251
,
'
endTmEpoch
'
:
2623623
,
}
...
...
@@ -352,7 +343,7 @@ class TestReadWaveformReftek(TestCase):
def
test_end_data_time_later_than_latest_start_time
(
self
):
# End time set to be the last second of 9999 so as to be later than the
# end time of any test data.
self
.
mock_read
W
aveform
T
race
.
return_value
=
{
self
.
mock_read
_w
aveform
_t
race
.
return_value
=
{
'
startTmEpoch
'
:
51251
,
'
endTmEpoch
'
:
2623623
,
}
...
...
@@ -364,7 +355,7 @@ class TestReadWaveformReftek(TestCase):
self
.
assertEqual
(
self
.
data_time
[
1
],
end_time
)
def
test_data_time_is_between_earliest_start_and_latest_end_time
(
self
):
self
.
mock_read
W
aveform
T
race
.
return_value
=
{
self
.
mock_read
_w
aveform
_t
race
.
return_value
=
{
'
startTmEpoch
'
:
51251
,
'
endTmEpoch
'
:
2623623
,
}
...
...
@@ -413,8 +404,8 @@ class TestReadASCII(TestCase):
# after splitting the log string based on \n
log_lines
=
[
line
.
strip
(
'
\r
'
)
for
line
in
log_lines
]
# The first four elements of log_lines will be there whether anything
# is read from the file, so we know that something
is
read from
the
# file when log_lines have more than four elements
# is read from the file, so we know that something
has been
read from
#
the
file when log_lines have more than four elements
.
self
.
assertGreater
(
len
(
log_lines
),
4
)
# Check that we are not reading in gibberish
self
.
assertEqual
(
...
...
@@ -563,4 +554,50 @@ class TestSaveData2File(TestCase):
with
self
.
assertRaises
(
ValueError
):
saveData2File
(
self
.
temp_dir
.
name
,
self
.
time_data
,
self
.
station_id
,
self
.
channel_id
,
self
.
trace
,
self
.
trace_idx
,
self
.
trace_size
)
\ No newline at end of file
self
.
trace_size
)
class
TestCheckChan
(
TestCase
):
def
setUp
(
self
)
->
None
:
self
.
req_soh_chans
=
[
'
LCE
'
,
'
LCQ
'
,
'
VM1
'
]
self
.
req_wf_chans
=
[
'
LHE
'
,
'
HHE
'
]
check_soh_chan_patcher
=
patch
(
'
sohstationviewer.model.handling_data.checkSOHChan
'
,
wraps
=
checkSOHChan
)
self
.
addCleanup
(
check_soh_chan_patcher
.
stop
)
self
.
mock_check_soh_chan
=
check_soh_chan_patcher
.
start
()
check_wf_chan_patcher
=
patch
(
'
sohstationviewer.model.handling_data.checkWFChan
'
,
wraps
=
checkWFChan
)
self
.
addCleanup
(
check_wf_chan_patcher
.
stop
)
self
.
mock_check_wf_chan
=
check_wf_chan_patcher
.
start
()
def
test_channel_is_waveform_and_is_requested
(
self
):
waveform_channel
=
'
LHE
'
ret
=
checkChan
(
waveform_channel
,
self
.
req_soh_chans
,
self
.
req_wf_chans
)
self
.
assertEqual
(
ret
,
'
WF
'
)
self
.
assertTrue
(
self
.
mock_check_wf_chan
.
called
)
def
test_channel_is_waveform_but_not_requested
(
self
):
waveform_channel
=
'
HH1
'
ret
=
checkChan
(
waveform_channel
,
self
.
req_soh_chans
,
self
.
req_wf_chans
)
self
.
assertFalse
(
ret
)
self
.
assertTrue
(
self
.
mock_check_wf_chan
.
called
)
def
test_channel_is_soh_and_is_requested
(
self
):
soh_channel
=
'
LCE
'
ret
=
checkChan
(
soh_channel
,
self
.
req_soh_chans
,
self
.
req_wf_chans
)
self
.
assertEqual
(
ret
,
'
SOH
'
)
self
.
assertTrue
(
self
.
mock_check_soh_chan
.
called
)
def
test_channel_is_soh_but_not_requested
(
self
):
soh_channel
=
'
VKI
'
ret
=
checkChan
(
soh_channel
,
self
.
req_soh_chans
,
self
.
req_wf_chans
)
self
.
assertFalse
(
ret
)
self
.
assertTrue
(
self
.
mock_check_soh_chan
.
called
)
\ No newline at end of file
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