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
18696738
Commit
18696738
authored
3 years ago
by
Maeva Pourpoint
Browse files
Options
Downloads
Patches
Plain Diff
Update variable naming in utils module
parent
b9f1d292
No related branches found
Branches containing commit
No related tags found
1 merge request
!17
Latest updates to the utils and lemi_data modules before MVP release
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lemi2seed/utils.py
+33
-33
33 additions, 33 deletions
lemi2seed/utils.py
tests/test_utils.py
+105
-105
105 additions, 105 deletions
tests/test_utils.py
with
138 additions
and
138 deletions
lemi2seed/utils.py
+
33
−
33
View file @
18696738
...
...
@@ -5,6 +5,7 @@ validation.
Maeva Pourpoint - IRIS/PASSCAL
"""
from
__future__
import
annotations
import
re
...
...
@@ -17,16 +18,16 @@ from lemi2seed.logging import setup_logger
# Set up logging
logger
=
setup_logger
(
__name__
)
ELEC
TRODE
_DEFAULT
=
'
Borin STELTH 4 - Silver-Silver Chloride
'
ELEC_DEFAULT
=
'
Borin STELTH 4 - Silver-Silver Chloride
'
FLUXGATE_DEFAULT
=
'
LEMI-039
'
LOC
=
[
'
00
'
,
'
01
'
,
'
02
'
,
'
03
'
]
MSG_E_CHA
=
(
"
If you did not use that channel number to record data, please
"
"
update your list of recorded components at the station/runs
"
"
levels!
"
)
N
BR
_E_CHA
NNEL
_MAX
=
4
N
UM
_E_CHA_MAX
=
4
def
check_email_format
ting
(
email
:
str
)
->
bool
:
def
check_email_format
(
email
:
str
)
->
bool
:
"""
Basic email check. Check for proper formatting.
Will not catch typos or fake email addresses.
...
...
@@ -45,31 +46,31 @@ def check_email_formatting(email: str) -> bool:
return
bool
(
valid
)
def
check_inst
rument
_specs
(
specs
:
str
,
equipment
:
str
,
cha
nnel
_info
:
str
=
""
)
->
bool
:
def
check_inst_specs
(
specs
:
str
,
equipment
:
str
,
cha_info
:
str
=
""
)
->
bool
:
"""
Check instrument specifications provided by the user.
Both manufacturer and model info are required inputs. Type is optional.
"""
if
specs
in
[
ELEC
TRODE
_DEFAULT
,
FLUXGATE_DEFAULT
]:
if
specs
in
[
ELEC_DEFAULT
,
FLUXGATE_DEFAULT
]:
return
True
elif
re
.
match
(
r
"
^Manufacturer: \w* - Model: \w* - Type: \w*$
"
,
specs
):
manufacturer
,
model
,
_
=
[
x
.
split
(
'
:
'
)[
-
1
].
strip
()
for
x
in
specs
.
split
(
'
-
'
)]
if
manufacturer
==
''
:
logger
.
error
(
"
Please provide {0} manufacturer{1}. Required
"
"
metadata field.
"
.
format
(
equipment
,
cha
nnel
_info
))
"
metadata field.
"
.
format
(
equipment
,
cha_info
))
return
False
if
model
==
''
:
logger
.
error
(
"
Please provide {0} model{1}. Required metadata
"
"
field.
"
.
format
(
equipment
,
cha
nnel
_info
))
"
field.
"
.
format
(
equipment
,
cha_info
))
return
False
return
True
else
:
logger
.
error
(
"
Please provide {0} specs for{1}. Required metadata
"
"
field.
"
.
format
(
equipment
,
cha
nnel
_info
))
"
field.
"
.
format
(
equipment
,
cha_info
))
return
False
def
compare_s
erial_number
(
equipment
:
str
,
s
erial_number
:
str
,
data_input
:
Optional
[
str
]
=
None
)
->
bool
:
def
compare_s
n
(
equipment
:
str
,
s
n
:
str
,
data_input
:
Optional
[
str
]
=
None
)
->
bool
:
"""
Compare user provided serial number for the data logger or fluxgate against
the serial number recorded in the .INF file.
...
...
@@ -77,29 +78,28 @@ def compare_serial_number(equipment: str, serial_number: str, data_input: Option
long.
"""
if
data_input
is
not
None
:
valid
=
(
str
(
s
erial_number
)
==
data_input
)
valid
=
(
str
(
s
n
)
==
data_input
)
if
not
valid
:
logger
.
error
(
"
The serial number of the {} differs from the one
"
"
automatically recorded by the logger in the field
"
"
({} != {}). Please correct!
"
.
format
(
equipment
,
serial_number
,
data_input
))
"
({} != {}). Please correct!
"
.
format
(
equipment
,
sn
,
data_input
))
else
:
valid
=
re
.
match
(
r
"
^\d{3}$
"
,
str
(
s
erial_number
))
# type: ignore
valid
=
re
.
match
(
r
"
^\d{3}$
"
,
str
(
s
n
))
# type: ignore
if
valid
is
None
:
logger
.
error
(
"
The serial number of the {} should be 3 digits
"
"
long.
"
.
format
(
equipment
))
return
valid
def
check_s
erial_number
(
equipment
:
str
,
s
erial_number
:
str
,
data_input
:
Optional
[
str
]
=
None
)
->
bool
:
def
check_s
n
(
equipment
:
str
,
s
n
:
str
,
data_input
:
Optional
[
str
]
=
None
)
->
bool
:
"""
Check user provided serial number for their data logger, fluxgate or
electrodes.
"""
if
s
erial_number
is
not
None
:
if
s
n
is
not
None
:
valid
=
True
if
'
data logger
'
in
equipment
or
'
fluxgate
'
in
equipment
:
valid
=
compare_s
erial_number
(
equipment
,
s
erial_number
,
data_input
)
valid
=
compare_s
n
(
equipment
,
s
n
,
data_input
)
return
valid
else
:
msg
=
"
Please provide a serial number for the {}!
"
.
format
(
equipment
)
...
...
@@ -109,19 +109,19 @@ def check_serial_number(equipment: str, serial_number: str, data_input: Optional
return
False
def
convert_coord
inate
(
coord
inate
:
str
,
hemisphere
:
str
)
->
Optional
[
float
]:
def
convert_coord
(
coord
:
str
,
hemisphere
:
str
)
->
Optional
[
float
]:
"""
Convert coordinates outputted by LEMI to decimal degrees.
"""
if
hemisphere
not
in
[
'
N
'
,
'
S
'
,
'
E
'
,
'
W
'
]:
logger
.
error
(
"
Unexpected hemisphere - {} - listed in data file!
"
.
format
(
hemisphere
))
return
None
try
:
coord
inate
=
float
(
coord
inate
)
/
100
# type: ignore
coord
=
float
(
coord
)
/
100
# type: ignore
except
ValueError
:
logger
.
error
(
"
Failed to convert geographic coordinate - {} - to
"
"
decimal degrees!
"
.
format
(
coord
inate
))
"
decimal degrees!
"
.
format
(
coord
))
return
None
return
-
coord
inate
if
hemisphere
in
[
"
S
"
,
"
W
"
]
else
coord
inate
# type: ignore
return
-
coord
if
hemisphere
in
[
"
S
"
,
"
W
"
]
else
coord
# type: ignore
def
convert_time
(
time_stamp
:
str
)
->
Optional
[
UTCDateTime
]:
...
...
@@ -140,7 +140,7 @@ def convert_time(time_stamp: str) -> Optional[UTCDateTime]:
return
None
def
eval
uate_location
_code
(
e_infos
:
Dict
)
->
bool
:
def
eval
_loc
_code
(
e_infos
:
Dict
)
->
bool
:
"""
Get location code boolean - Needed to define whether location code
should be
''
(i.e. undefined)
...
...
@@ -151,10 +151,10 @@ def evaluate_location_code(e_infos: Dict) -> bool:
return
False
def
get_e_ids
(
n
br
_runs
:
int
)
->
List
[
Tuple
[
str
,
int
]]:
def
get_e_ids
(
n
um
_runs
:
int
)
->
List
[
Tuple
[
str
,
int
]]:
"""
Get permutation of run ids and channel numbers.
"""
run_list
=
get_run_list
(
n
br
_runs
)
return
[(
i
,
j
)
for
i
in
run_list
for
j
in
range
(
1
,
N
BR
_E_CHA
NNEL
_MAX
+
1
)]
run_list
=
get_run_list
(
n
um
_runs
)
return
[(
i
,
j
)
for
i
in
run_list
for
j
in
range
(
1
,
N
UM
_E_CHA_MAX
+
1
)]
def
get_e_loc
(
e_info
:
Dict
)
->
Dict
:
...
...
@@ -163,23 +163,23 @@ def get_e_loc(e_info: Dict) -> Dict:
Only useful when more than two electrode pairs are deployed at a station.
"""
e_loc
=
{}
comp
onent
s
=
{
x
for
x
in
e_info
.
values
()
if
x
}
for
comp
onent
in
comp
onent
s
:
cha
nnel_nbr
=
[
key
for
key
,
val
in
e_info
.
items
()
if
val
==
comp
onent
]
e_loc
.
update
({
key
:
LOC
[
ind
]
for
ind
,
key
in
enumerate
(
cha
nnel_nbr
)})
comps
=
{
x
for
x
in
e_info
.
values
()
if
x
}
for
comp
in
comps
:
cha
_num
=
[
key
for
key
,
val
in
e_info
.
items
()
if
val
==
comp
]
e_loc
.
update
({
key
:
LOC
[
ind
]
for
ind
,
key
in
enumerate
(
cha
_num
)})
return
e_loc
def
get_run_list
(
n
br
_runs
:
int
)
->
List
[
str
]:
def
get_run_list
(
n
um
_runs
:
int
)
->
List
[
str
]:
"""
Get list of run ids.
"""
return
[
chr
(
x
)
for
x
in
range
(
ord
(
'
a
'
),
ord
(
'
a
'
)
+
n
br
_runs
)]
return
[
chr
(
x
)
for
x
in
range
(
ord
(
'
a
'
),
ord
(
'
a
'
)
+
n
um
_runs
)]
def
get_run_n
br
(
run_id
:
str
)
->
int
:
def
get_run_n
um
(
run_id
:
str
)
->
int
:
"""
Get the integer representation of the string run_id.
"""
integer_representation_unicode_character_a
=
97
run_n
br
=
ord
(
run_id
)
-
integer_representation_unicode_character_a
+
1
return
run_n
br
run_n
um
=
ord
(
run_id
)
-
integer_representation_unicode_character_a
+
1
return
run_n
um
def
is_empty
(
val
:
Any
)
->
bool
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_utils.py
+
105
−
105
View file @
18696738
...
...
@@ -7,10 +7,10 @@ import unittest
from
obspy
import
UTCDateTime
from
lemi2seed.logging
import
setup_logger
from
lemi2seed.utils
import
(
convert_coord
inate
,
convert_time
,
str2list
,
check_email_format
ting
,
check_inst
rument
_specs
,
check_serial_number
,
is_empty
,
evaluate_location_code
,
get_e_loc
,
get_e_ids
,
get_run_list
,
get_run_n
br
)
from
lemi2seed.utils
import
(
convert_coord
,
convert_time
,
str2list
,
check_email_format
,
check_inst_specs
,
check_sn
,
is_empty
,
eval_loc_code
,
get_e_loc
,
get_e_ids
,
get_run_list
,
get_run_n
um
)
SCR_DIR
=
"
lemi2seed.utils
"
...
...
@@ -18,48 +18,48 @@ SCR_DIR = "lemi2seed.utils"
logger
=
setup_logger
(
SCR_DIR
)
class
TestConvertCoord
inate
(
unittest
.
TestCase
):
"""
Test suite for convert_coord
inate
.
"""
class
TestConvertCoord
(
unittest
.
TestCase
):
"""
Test suite for convert_coord.
"""
def
test_convert_coord
inate
_positive_lat
(
self
):
"""
Test basic functionality of convert_coord
inate
.
"""
def
test_convert_coord_positive_lat
(
self
):
"""
Test basic functionality of convert_coord.
"""
coordinate
=
3404.83926
hemisphere
=
'
N
'
self
.
assertEqual
(
convert_coord
inate
(
coordinate
,
hemisphere
),
self
.
assertEqual
(
convert_coord
(
coordinate
,
hemisphere
),
34.0483926
)
def
test_convert_coord
inate
_negative_lat
(
self
):
"""
Test basic functionality of convert_coord
inate
.
"""
def
test_convert_coord_negative_lat
(
self
):
"""
Test basic functionality of convert_coord.
"""
coordinate
=
2456.43250
hemisphere
=
'
S
'
self
.
assertEqual
(
convert_coord
inate
(
coordinate
,
hemisphere
),
self
.
assertEqual
(
convert_coord
(
coordinate
,
hemisphere
),
-
24.564325
)
def
test_convert_coord
inate
_positive_lon
(
self
):
"""
Test basic functionality of convert_coord
inate
.
"""
def
test_convert_coord_positive_lon
(
self
):
"""
Test basic functionality of convert_coord.
"""
coordinate
=
4303.74563
hemisphere
=
'
E
'
self
.
assertEqual
(
convert_coord
inate
(
coordinate
,
hemisphere
),
self
.
assertEqual
(
convert_coord
(
coordinate
,
hemisphere
),
43.0374563
)
def
test_convert_coord
inate
_negative_lon
(
self
):
"""
Test basic functionality of convert_coord
inate
.
"""
def
test_convert_coord_negative_lon
(
self
):
"""
Test basic functionality of convert_coord.
"""
coordinate
=
1071.84450
hemisphere
=
'
W
'
self
.
assertEqual
(
convert_coord
inate
(
coordinate
,
hemisphere
),
self
.
assertEqual
(
convert_coord
(
coordinate
,
hemisphere
),
-
10.718445
)
def
test_convert_coord
inate
_erroneous_hemisphere
(
self
):
"""
Test basic functionality of convert_coord
inate
.
"""
def
test_convert_coord_erroneous_hemisphere
(
self
):
"""
Test basic functionality of convert_coord.
"""
coordinate
=
1071.84450
hemisphere
=
'
B
'
self
.
assertEqual
(
convert_coord
inate
(
coordinate
,
hemisphere
),
None
)
self
.
assertEqual
(
convert_coord
(
coordinate
,
hemisphere
),
None
)
def
test_convert_coord
inate
_erroneous_type
(
self
):
"""
Test basic functionality of convert_coord
inate
.
"""
def
test_convert_coord_erroneous_type
(
self
):
"""
Test basic functionality of convert_coord.
"""
coordinate
=
'
1071.84450
'
hemisphere
=
'
B
'
self
.
assertEqual
(
convert_coord
inate
(
coordinate
,
hemisphere
),
None
)
self
.
assertEqual
(
convert_coord
(
coordinate
,
hemisphere
),
None
)
class
TestConvertTime
(
unittest
.
TestCase
):
...
...
@@ -96,128 +96,128 @@ class TestStr2list(unittest.TestCase):
self
.
assertEqual
(
str2list
(
str_input
),
[
'
a
'
,
'
b
'
,
'
c
'
,
'
d
'
,
'
e
'
])
class
TestCheckEmail
F
ormat
ting
(
unittest
.
TestCase
):
"""
Test suite for check_email_format
ting
.
"""
class
TestCheckEmail
f
ormat
(
unittest
.
TestCase
):
"""
Test suite for check_email_format.
"""
def
test_check_email_format
ting
_valid_email
(
self
):
"""
Test basic functionality of check_email_format
ting
.
"""
def
test_check_email_format_valid_email
(
self
):
"""
Test basic functionality of check_email_format.
"""
email
=
'
m@passcal.nmt.edu
'
self
.
assertTrue
(
check_email_format
ting
(
email
))
self
.
assertTrue
(
check_email_format
(
email
))
def
test_check_email_format
ting
_erroneous_type
(
self
):
"""
Test basic functionality of check_email_format
ting
.
"""
def
test_check_email_format_erroneous_type
(
self
):
"""
Test basic functionality of check_email_format.
"""
email
=
12
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
check_email_format
ting
(
email
)
check_email_format
(
email
)
msg
=
"
The provided email
'
{}
'
should be a string.
"
.
format
(
email
)
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
def
test_check_email_format
ting
_erroneous_email
(
self
):
"""
Test basic functionality of check_email_format
ting
.
"""
def
test_check_email_format_erroneous_email
(
self
):
"""
Test basic functionality of check_email_format.
"""
email
=
'
m_passcal.nmt.edu
'
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
check_email_format
ting
(
email
)
check_email_format
(
email
)
msg
=
(
"
Invalid email. The provided email
'
{}
'
does not meet minimum
"
"
formatting requirements: account@domain.
"
.
format
(
email
))
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
class
TestCheckInst
rument
Specs
(
unittest
.
TestCase
):
"""
Test suite for check_inst
rument
_specs.
"""
class
TestCheckInstSpecs
(
unittest
.
TestCase
):
"""
Test suite for check_inst_specs.
"""
def
test_check_inst
rument
_specs_default_value
(
self
):
"""
Test basic functionality of check_inst
rument
_specs.
"""
def
test_check_inst_specs_default_value
(
self
):
"""
Test basic functionality of check_inst_specs.
"""
specs
=
'
LEMI-039
'
self
.
assertTrue
(
check_inst
rument
_specs
(
specs
,
'
fluxgate
'
,
''
))
self
.
assertTrue
(
check_inst_specs
(
specs
,
'
fluxgate
'
,
''
))
def
test_check_inst
rument
_specs_valid_user_input
(
self
):
"""
Test basic functionality of check_inst
rument
_specs.
"""
def
test_check_inst_specs_valid_user_input
(
self
):
"""
Test basic functionality of check_inst_specs.
"""
specs
=
'
Manufacturer: a - Model: b - Type: c
'
self
.
assertTrue
(
check_inst
rument
_specs
(
specs
,
'
fluxgate
'
,
''
))
self
.
assertTrue
(
check_inst_specs
(
specs
,
'
fluxgate
'
,
''
))
def
test_check_inst
rument
_specs_no_type
(
self
):
"""
Test basic functionality of check_inst
rument
_specs.
"""
def
test_check_inst_specs_no_type
(
self
):
"""
Test basic functionality of check_inst_specs.
"""
specs
=
'
Manufacturer: a - Model: b - Type:
'
self
.
assertTrue
(
check_inst
rument
_specs
(
specs
,
'
fluxgate
'
,
''
))
self
.
assertTrue
(
check_inst_specs
(
specs
,
'
fluxgate
'
,
''
))
def
test_check_inst
rument
_specs_no_manufacturer
(
self
):
"""
Test basic functionality of check_inst
rument
_specs.
"""
def
test_check_inst_specs_no_manufacturer
(
self
):
"""
Test basic functionality of check_inst_specs.
"""
specs
=
'
Manufacturer: - Model: b - Type: c
'
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
check_inst
rument
_specs
(
specs
,
'
fluxgate
'
,
''
)
check_inst_specs
(
specs
,
'
fluxgate
'
,
''
)
msg
=
"
Please provide fluxgate manufacturer. Required metadata field.
"
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
def
test_check_inst
rument
_specs_no_model
(
self
):
"""
Test basic functionality of check_inst
rument
_specs.
"""
def
test_check_inst_specs_no_model
(
self
):
"""
Test basic functionality of check_inst_specs.
"""
specs
=
'
Manufacturer: a - Model: - Type: c
'
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
check_inst
rument
_specs
(
specs
,
'
fluxgate
'
,
''
)
check_inst_specs
(
specs
,
'
fluxgate
'
,
''
)
msg
=
"
Please provide fluxgate model. Required metadata field.
"
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
def
test_check_inst
rument
_specs_erroneous_specs
(
self
):
"""
Test basic functionality of check_inst
rument
_specs.
"""
def
test_check_inst_specs_erroneous_specs
(
self
):
"""
Test basic functionality of check_inst_specs.
"""
specs
=
'
Other
'
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
check_inst
rument
_specs
(
specs
,
'
fluxgate
'
,
''
)
check_inst_specs
(
specs
,
'
fluxgate
'
,
''
)
msg
=
"
Please provide fluxgate specs for. Required metadata field.
"
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
class
TestCheckS
erialNumber
(
unittest
.
TestCase
):
"""
Test suite for check_s
erial_number
.
"""
class
TestCheckS
N
(
unittest
.
TestCase
):
"""
Test suite for check_s
n
.
"""
def
test_check_s
erial_number
_no_input
(
self
):
"""
Test basic functionality of check_s
erial_number
.
"""
s
erial_number
=
None
def
test_check_s
n
_no_input
(
self
):
"""
Test basic functionality of check_s
n
.
"""
s
n
=
None
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
valid
=
check_s
erial_number
(
'
data logger
'
,
s
erial_number
)
valid
=
check_s
n
(
'
data logger
'
,
s
n
)
msg
=
"
Please provide a serial number for the data logger!
"
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
self
.
assertFalse
(
valid
)
def
test_check_s
erial_number
_invalid_input_data_logger
(
self
):
"""
Test basic functionality of check_s
erial_number
.
"""
s
erial_number
=
1234
def
test_check_s
n
_invalid_input_data_logger
(
self
):
"""
Test basic functionality of check_s
n
.
"""
s
n
=
1234
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
valid
=
check_s
erial_number
(
'
data logger
'
,
s
erial_number
)
valid
=
check_s
n
(
'
data logger
'
,
s
n
)
msg
=
"
The serial number of the data logger should be 3 digits long.
"
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
self
.
assertFalse
(
valid
)
def
test_check_s
erial_number
_mismatch_between_user_and_data_inputs
(
self
):
"""
Test basic functionality of check_s
erial_number
.
"""
s
erial_number
=
110
def
test_check_s
n
_mismatch_between_user_and_data_inputs
(
self
):
"""
Test basic functionality of check_s
n
.
"""
s
n
=
110
data_input
=
'
132
'
with
self
.
assertLogs
(
logger
,
level
=
'
ERROR
'
)
as
cmd
:
valid
=
check_s
erial_number
(
'
data logger
'
,
s
erial_number
,
data_input
)
valid
=
check_s
n
(
'
data logger
'
,
s
n
,
data_input
)
msg
=
(
"
The serial number of the data logger differs from the one
"
"
automatically recorded by the logger in the field (110 != 132).
"
"
Please correct!
"
)
self
.
assertEqual
(
cmd
.
output
,
[
"
:
"
.
join
([
'
ERROR
'
,
SCR_DIR
,
msg
])])
self
.
assertFalse
(
valid
)
def
test_check_s
erial_number
_match_between_user_and_data_inputs
(
self
):
"""
Test basic functionality of check_s
erial_number
.
"""
s
erial_number
=
110
def
test_check_s
n
_match_between_user_and_data_inputs
(
self
):
"""
Test basic functionality of check_s
n
.
"""
s
n
=
110
data_input
=
'
110
'
self
.
assertTrue
(
check_s
erial_number
(
"
data logger
"
,
s
erial_number
,
data_input
))
self
.
assertTrue
(
check_s
n
(
"
data logger
"
,
s
n
,
data_input
))
def
test_check_s
erial_number
_valid_input_data_logger
(
self
):
"""
Test basic functionality of check_s
erial_number
.
"""
s
erial_number
=
110
self
.
assertTrue
(
check_s
erial_number
(
"
data logger
"
,
s
erial_number
))
def
test_check_s
n
_valid_input_data_logger
(
self
):
"""
Test basic functionality of check_s
n
.
"""
s
n
=
110
self
.
assertTrue
(
check_s
n
(
"
data logger
"
,
s
n
))
def
test_check_s
erial_number
_valid_input_fluxgate
(
self
):
"""
Test basic functionality of check_s
erial_number
.
"""
s
erial_number
=
110
self
.
assertTrue
(
check_s
erial_number
(
"
fluxgate
"
,
s
erial_number
))
def
test_check_s
n
_valid_input_fluxgate
(
self
):
"""
Test basic functionality of check_s
n
.
"""
s
n
=
110
self
.
assertTrue
(
check_s
n
(
"
fluxgate
"
,
s
n
))
def
test_check_s
erial_number
_valid_input_electrode
(
self
):
"""
Test basic functionality of check_s
erial_number
.
"""
s
erial_number
=
1103455
self
.
assertTrue
(
check_s
erial_number
(
"
electrode
"
,
s
erial_number
))
def
test_check_s
n
_valid_input_electrode
(
self
):
"""
Test basic functionality of check_s
n
.
"""
s
n
=
1103455
self
.
assertTrue
(
check_s
n
(
"
electrode
"
,
s
n
))
class
TestIsEmpty
(
unittest
.
TestCase
):
...
...
@@ -244,24 +244,24 @@ class TestIsEmpty(unittest.TestCase):
self
.
assertFalse
(
is_empty
(
val
))
class
Test
GetBoolLoc
(
unittest
.
TestCase
):
"""
Test suite for eval
uate_location
_code.
"""
class
Test
EvalLocCode
(
unittest
.
TestCase
):
"""
Test suite for eval
_loc
_code.
"""
def
test_eval
uate_location
_code_two_electrode_pairs_different_direction
(
self
):
"""
Test basic functionality of eval
uate_location
_code.
"""
def
test_eval
_loc
_code_two_electrode_pairs_different_direction
(
self
):
"""
Test basic functionality of eval
_loc
_code.
"""
e_infos
=
{
'
a
'
:
{
'
E1
'
:
'
Ex
'
,
'
E2
'
:
'
Ey
'
},
'
b
'
:
{
'
E1
'
:
'
Ex
'
,
'
E2
'
:
'
Ey
'
}}
self
.
assertFalse
(
eval
uate_location
_code
(
e_infos
))
self
.
assertFalse
(
eval
_loc
_code
(
e_infos
))
def
test_eval
uate_location
_code_two_electrode_pairs_same_direction
(
self
):
"""
Test basic functionality of eval
uate_location
_code.
"""
def
test_eval
_loc
_code_two_electrode_pairs_same_direction
(
self
):
"""
Test basic functionality of eval
_loc
_code.
"""
e_infos
=
{
'
a
'
:
{
'
E1
'
:
'
Ex
'
,
'
E2
'
:
'
Ex
'
},
'
b
'
:
{
'
E1
'
:
'
Ex
'
,
'
E2
'
:
'
Ex
'
}}
self
.
assertTrue
(
eval
uate_location
_code
(
e_infos
))
self
.
assertTrue
(
eval
_loc
_code
(
e_infos
))
def
test_eval
uate_location
_code_more_than_two_electrode_pairs
(
self
):
"""
Test basic functionality of eval
uate_location
_code.
"""
def
test_eval
_loc
_code_more_than_two_electrode_pairs
(
self
):
"""
Test basic functionality of eval
_loc
_code.
"""
e_infos
=
{
'
a
'
:
{
'
E1
'
:
'
Ex
'
,
'
E2
'
:
'
Ey
'
,
'
E3
'
:
'
Ex
'
,
'
E4
'
:
'
Ey
'
},
'
b
'
:
{
'
E1
'
:
'
Ex
'
,
'
E2
'
:
'
Ey
'
}}
self
.
assertTrue
(
eval
uate_location
_code
(
e_infos
))
self
.
assertTrue
(
eval
_loc
_code
(
e_infos
))
class
TestGetELoc
(
unittest
.
TestCase
):
...
...
@@ -282,20 +282,20 @@ class TestGetELoc(unittest.TestCase):
class
TestGetRunListGetEIds
(
unittest
.
TestCase
):
"""
Test suite for get_run_list and get_e_ids.
"""
def
test_get_run_n
br
(
self
):
"""
Test basic functionality of get_run_n
br
.
"""
self
.
assertEqual
(
get_run_n
br
(
'
a
'
),
1
)
self
.
assertEqual
(
get_run_n
br
(
'
b
'
),
2
)
self
.
assertEqual
(
get_run_n
br
(
'
c
'
),
3
)
def
test_get_run_n
um
(
self
):
"""
Test basic functionality of get_run_n
um
.
"""
self
.
assertEqual
(
get_run_n
um
(
'
a
'
),
1
)
self
.
assertEqual
(
get_run_n
um
(
'
b
'
),
2
)
self
.
assertEqual
(
get_run_n
um
(
'
c
'
),
3
)
def
test_get_run_list
(
self
):
"""
Test basic functionality of get_run_list.
"""
n
br
_runs
=
3
self
.
assertListEqual
(
get_run_list
(
n
br
_runs
),
[
'
a
'
,
'
b
'
,
'
c
'
])
n
um
_runs
=
3
self
.
assertListEqual
(
get_run_list
(
n
um
_runs
),
[
'
a
'
,
'
b
'
,
'
c
'
])
def
test_get_e_ids
(
self
):
"""
Test basic functionality of get_e_ids.
"""
n
br
_runs
=
2
n
um
_runs
=
2
e_ids
=
[(
'
a
'
,
1
),
(
'
a
'
,
2
),
(
'
a
'
,
3
),
(
'
a
'
,
4
),
(
'
b
'
,
1
),
(
'
b
'
,
2
),
(
'
b
'
,
3
),
(
'
b
'
,
4
)]
self
.
assertListEqual
(
get_e_ids
(
n
br
_runs
),
e_ids
)
self
.
assertListEqual
(
get_e_ids
(
n
um
_runs
),
e_ids
)
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