Skip to content
Snippets Groups Projects

Scarlet issue011 unit test init

Merged Ghost User requested to merge scarlet_issue011_unit_test_init into devel
2 files
+ 108
1
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 93
0
"""
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