Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
diapotb
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
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
Remote Modules
diapotb
Commits
8fc8c20c
Commit
8fc8c20c
authored
3 years ago
by
Gaëlle USSEGLIO
Browse files
Options
Downloads
Patches
Plain Diff
TEST : Add tests for ConfigFile
parent
3b9e566e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
3 merge requests
!52
Merge for v1.1.0
,
!50
Finalize Python chains (v1.1.0)
,
!49
Add python tests
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python_src/tests/test_configfile.py
+157
-0
157 additions, 0 deletions
python_src/tests/test_configfile.py
with
157 additions
and
0 deletions
python_src/tests/test_configfile.py
0 → 100644
+
157
−
0
View file @
8fc8c20c
import
pytest
import
shutil
import
os
import
json
from
enum
import
Enum
from
diapotb.lib.core.DiapOTBEnums
import
Sensor
,
ScriptNames
,
ChainNames
from
diapotb.ConfigFile
import
ConfigFile
from
diapotb.lib.DInSAR
import
DInSarParamOthers
,
DInSarParamS1IW
from
diapotb.lib.PreProcessing
import
PreProcessingParamOthers
,
PreProcessingParamS1IW
from
diapotb.lib.PostProcessing
import
PostProcessingParamOthers
,
PostProcessingParamS1IW
from
diapotb.lib.Ground
import
GroundParamOthers
,
GroundParamS1IW
class
MainChains
(
Enum
):
DIAPOTB
=
"
diapOTB
"
DIAPOTB_S1IW
=
"
diapOTB_S1IW
"
SARMULTISLC
=
"
SAR_MultiSlc
"
SARMULTISLC_S1IW
=
"
SAR_MultiSlc_IW
"
def
__str__
(
self
):
return
self
.
value
@pytest.fixture
(
scope
=
"
function
"
)
def
build_configfile
(
chain_name
):
"""
Build a ConfigFile from examples.json
"""
# Load examples according to the selected chain => Init a dictionnary with default parameters
# Check and load configuration file
if
chain_name
==
MainChains
.
DIAPOTB
:
config_handler
=
ConfigFile
.
create_configfile_from_ex
(
str
(
ScriptNames
.
SIMPLE_S1SM
))
config_handler
.
load_configfile
()
elif
chain_name
==
MainChains
.
DIAPOTB_S1IW
:
config_handler
=
ConfigFile
.
create_configfile_from_ex
(
str
(
ScriptNames
.
SIMPLE_S1IW
))
config_handler
.
load_configfile
()
elif
chain_name
==
MainChains
.
SARMULTISLC
:
config_handler
=
ConfigFile
.
create_configfile_from_ex
(
str
(
ScriptNames
.
MULTI_SLC_S1SM
))
config_handler
.
load_configfile
()
elif
chain_name
==
MainChains
.
SARMULTISLC_S1IW
:
config_handler
=
ConfigFile
.
create_configfile_from_ex
(
str
(
ScriptNames
.
MULTI_SLC_S1IW
))
config_handler
.
load_configfile
()
yield
config_handler
def
build_configfile_from_input
(
input_json
,
chain_name
):
"""
Build a ConfigFile from examples.json
"""
# Load examples according to the selected chain => Init a dictionnary with default parameters
# Check and load configuration file
if
chain_name
==
MainChains
.
DIAPOTB
:
config_handler
=
ConfigFile
(
input_json
,
str
(
ScriptNames
.
SIMPLE_S1SM
))
elif
chain_name
==
MainChains
.
DIAPOTB_S1IW
:
config_handler
=
ConfigFile
(
input_json
,
str
(
ScriptNames
.
SIMPLE_S1IW
))
elif
chain_name
==
MainChains
.
SARMULTISLC
:
config_handler
=
ConfigFile
(
input_json
,
str
(
ScriptNames
.
MULTI_SLC_S1SM
))
elif
chain_name
==
MainChains
.
SARMULTISLC_S1IW
:
config_handler
=
ConfigFile
(
input_json
,
str
(
ScriptNames
.
MULTI_SLC_S1IW
))
return
config_handler
#### Tests ####
class
TestConfigFile
():
"""
Test to check ConfigFile class
"""
# In MB
@pytest.fixture
(
scope
=
"
class
"
,
params
=
[
MainChains
.
DIAPOTB
,
MainChains
.
DIAPOTB_S1IW
,
MainChains
.
SARMULTISLC
,
MainChains
.
SARMULTISLC_S1IW
])
def
chain_name
(
self
,
request
):
return
request
.
param
def
test_config_file
(
self
,
build_configfile
,
chain_name
):
"""
Check if an resampling is required
"""
# Get config_ahndler and in-memory json
config_handler
=
build_configfile
data_config
=
config_handler
.
get_data_config
()
# Build each param dict from config_handler
enum_dinsar
=
DInSarParamOthers
if
chain_name
==
MainChains
.
DIAPOTB_S1IW
or
chain_name
==
MainChains
.
SARMULTISLC_S1IW
:
enum_dinsar
=
DInSarParamS1IW
param_dict_dinsar
=
config_handler
.
create_param_dict_from_config_file
(
enum_dinsar
,
str
(
ChainNames
.
DINSAR
))
enum_preproc
=
PreProcessingParamOthers
if
chain_name
==
MainChains
.
DIAPOTB_S1IW
or
chain_name
==
MainChains
.
SARMULTISLC_S1IW
:
enum_preproc
=
PreProcessingParamS1IW
param_dict_pre
=
config_handler
.
create_param_dict_from_config_file
(
enum_preproc
,
str
(
ChainNames
.
PRE_PROCESSING
))
enum_postproc
=
PostProcessingParamOthers
if
chain_name
==
MainChains
.
DIAPOTB_S1IW
or
chain_name
==
MainChains
.
SARMULTISLC_S1IW
:
enum_postproc
=
PostProcessingParamS1IW
param_dict_post
=
config_handler
.
create_param_dict_from_config_file
(
enum_postproc
,
str
(
ChainNames
.
POST_PROCESSING
))
enum_ground
=
GroundParamOthers
if
chain_name
==
MainChains
.
DIAPOTB_S1IW
or
chain_name
==
MainChains
.
SARMULTISLC_S1IW
:
enum_ground
=
GroundParamS1IW
param_dict_ground
=
config_handler
.
create_param_dict_from_config_file
(
enum_ground
,
str
(
ChainNames
.
GROUND
))
# Check some values
ml_key
=
"
ML_ran
"
if
chain_name
==
MainChains
.
DIAPOTB_S1IW
or
chain_name
==
MainChains
.
DIAPOTB
:
ml_key
=
"
ML_range
"
assert
data_config
[
str
(
ChainNames
.
PRE_PROCESSING
)][
"
parameter
"
][
ml_key
]
==
\
param_dict_pre
[
str
(
PreProcessingParamOthers
.
MLRAN
)]
==
\
param_dict_dinsar
[
str
(
DInSarParamOthers
.
MLRAN
)]
assert
data_config
[
str
(
ChainNames
.
DINSAR
)][
"
parameter
"
][
"
Interferogram_gain
"
]
==
\
param_dict_dinsar
[
str
(
DInSarParamOthers
.
INTERF_GAIN
)]
assert
data_config
[
str
(
ChainNames
.
POST_PROCESSING
)][
"
parameter
"
][
"
Spacingxy
"
]
==
\
param_dict_post
[
str
(
PostProcessingParamOthers
.
SPACING_XY
)]
@pytest.mark.xfail
(
reason
=
"
Expected exception
"
)
def
test_config_exception
(
self
,
build_configfile
,
chain_name
,
tmpdir_factory
):
"""
Test a corrupted file as config file => exception
"""
# Create tmp dir (with tmpdir_factory pytest fixture) and tmp_file
my_tmpdir
=
tmpdir_factory
.
mktemp
(
"
run_config_exception
"
+
str
(
chain_name
))
# Get config handler and in-memory data
config_handler
=
build_configfile
data_config
=
config_handler
.
get_data_config
()
# Corrupt data in some way
del
data_config
[
str
(
ChainNames
.
PRE_PROCESSING
)][
"
parameter
"
][
"
ML_gain
"
]
json_file
=
os
.
path
.
join
(
my_tmpdir
,
"
json_file.json
"
)
with
open
(
json_file
,
'
w
'
)
as
outfile
:
json
.
dump
(
data_config
,
outfile
,
indent
=
4
)
# rebuild a config Handler
config_handler_new
=
build_configfile_from_input
(
json_file
,
chain_name
)
# check for the expected exception
config_handler_new
.
load_configfile
()
shutil
.
rmtree
(
str
(
my_tmpdir
))
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