Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AQ-Bench
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
esde
machine-learning
AQ-Bench
Merge requests
!5
Scarlet issue011 unit test init
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Scarlet issue011 unit test init
scarlet_issue011_unit_test_init
into
devel
Overview
0
Commits
5
Pipelines
0
Changes
2
Merged
Ghost User
requested to merge
scarlet_issue011_unit_test_init
into
devel
4 years ago
Overview
0
Commits
5
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Compare
devel
devel (base)
and
latest version
latest version
1e087eb0
5 commits,
4 years ago
2 files
+
108
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
test/test_utils.py
0 → 100644
+
93
−
0
Options
"""
Test helper functions
Authors: Clara Betancourt, Scarlet Stadtler
Date: 19.06.2020
run with:
python -m pytest test_utils.py
"""
import
pytest
from
src.utils
import
string_to_dict
import
pdb
# def test_string_to_dict(self):
# # I guess here we can use assertDictEqual
# # Do I have to write a test case, some smaller string wich has to be converted into a dictionary?
# test_string = 'ladida'
# string_to_dict(test_string)
# # Maybe something that can be failed here are special characters or it is not a string!
# pass
def
test_string_to_dict_non_string_argument
():
# Test if TypeError is raised when we pass a non string varible
# This test is passed, because the function is smart enough to raise a TypeError!
with
pytest
.
raises
(
TypeError
):
string_to_dict
(
10
)
def
test_string_to_dict_minimal_example
():
# Test minimal example
example_input
=
'
Water: 98.2 %
'
expected_output
=
{
'
water_25km
'
:
98.2
,
'
evergreen_needleleaf_forest_25km
'
:
0.0
,
'
evergreen_broadleaf_forest_25km
'
:
0.0
,
'
deciduous_needleleaf_forest_25km
'
:
0.0
,
'
deciduous_broadleaf_forest_25km
'
:
0.0
,
'
mixed_forest_25km
'
:
0.0
,
'
closed_shrublands_25km
'
:
0.0
,
'
open_shrublands_25km
'
:
0.0
,
'
woody_savannas_25km
'
:
0.0
,
'
savannas_25km
'
:
0.0
,
'
grasslands_25km
'
:
0.0
,
'
permanent_wetlands_25km
'
:
0.0
,
'
croplands_25km
'
:
0.0
,
'
urban_and_built-up_25km
'
:
0.0
,
'
cropland-natural_vegetation_mosaic_25km
'
:
0.0
,
'
snow_and_ice_25km
'
:
0.0
,
'
barren_or_sparsely_vegetated_25km
'
:
0.0
}
assert
string_to_dict
(
example_input
)
==
expected_output
def
test_string_to_dict_missing_value
():
# Test missing value
example_input_list
=
[
''
,
'
unknown
'
]
expected_output
=
{
'
water_25km
'
:
-
999
,
'
evergreen_needleleaf_forest_25km
'
:
-
999
,
'
evergreen_broadleaf_forest_25km
'
:
-
999
,
'
deciduous_needleleaf_forest_25km
'
:
-
999
,
'
deciduous_broadleaf_forest_25km
'
:
-
999
,
'
mixed_forest_25km
'
:
-
999
,
'
closed_shrublands_25km
'
:
-
999
,
'
open_shrublands_25km
'
:
-
999
,
'
woody_savannas_25km
'
:
-
999
,
'
savannas_25km
'
:
-
999
,
'
grasslands_25km
'
:
-
999
,
'
permanent_wetlands_25km
'
:
-
999
,
'
croplands_25km
'
:
-
999
,
'
urban_and_built-up_25km
'
:
-
999
,
'
cropland-natural_vegetation_mosaic_25km
'
:
-
999
,
'
snow_and_ice_25km
'
:
-
999
,
'
barren_or_sparsely_vegetated_25km
'
:
-
999
}
for
example_input
in
example_input_list
:
assert
string_to_dict
(
example_input
)
==
expected_output
def
test_string_to_dict_crash
():
example_input
=
'
Closed shrublends: 50%
'
with
pytest
.
raises
(
AssertionError
):
string_to_dict
(
example_input
)
# def test_read_csv_to_df(self):
# # What could go wrong with reading a csv file to dataframe?
# # Clara already added some exception handling
# pass
# def test_read_pkl_to_df(self):
# # Again, what can go wrong here except for the file is not there or corrupted?
# pass
Loading