<s> import sys <EOL> import os <EOL> import pytest <EOL> from rasterstats . utils import stats_to_csv , get_percentile , remap_categories <EOL> from rasterstats import zonal_stats <EOL> from rasterstats . utils import VALID_STATS <EOL> sys . path . append ( os . path . dirname ( os . path . abspath ( __file__ ) ) ) <EOL> DATA = os . path . join ( os . path . dirname ( os . path . abspath ( __file__ ) ) , "<STR_LIT:data>" ) <EOL> raster = os . path . join ( DATA , '<STR_LIT>' ) <EOL> def test_csv ( ) : <EOL> polygons = os . path . join ( DATA , '<STR_LIT>' ) <EOL> stats = zonal_stats ( polygons , raster , stats = "<STR_LIT:*>" ) <EOL> csv = stats_to_csv ( stats ) <EOL> assert csv . split ( ) [ <NUM_LIT:0> ] == '<STR_LIT:U+002C>' . join ( sorted ( VALID_STATS ) ) <EOL> def test_categorical_csv ( ) : <EOL> polygons = os . path . join ( DATA , '<STR_LIT>' ) <EOL> categorical_raster = os . path . join ( DATA , '<STR_LIT>' ) <EOL> stats = zonal_stats ( polygons , categorical_raster , categorical = True ) <EOL> csv = stats_to_csv ( stats ) <EOL> assert csv . split ( ) [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> def test_get_percentile ( ) : <EOL> assert get_percentile ( '<STR_LIT>' ) == <NUM_LIT:0.0> <EOL> assert get_percentile ( '<STR_LIT>' ) == <NUM_LIT> <EOL> assert get_percentile ( '<STR_LIT>' ) == <NUM_LIT> <EOL> with pytest . raises ( ValueError ) : <EOL> get_percentile ( '<STR_LIT>' ) <EOL> with pytest . raises ( ValueError ) : <EOL> get_percentile ( '<STR_LIT>' ) <EOL> with pytest . raises ( ValueError ) : <EOL> get_percentile ( '<STR_LIT>' ) <EOL> def test_remap_categories ( ) : <EOL> feature_stats = { <NUM_LIT:1> : <NUM_LIT> , <NUM_LIT:2> : <NUM_LIT> , <NUM_LIT:3> : <NUM_LIT> } <EOL> category_map = { <NUM_LIT:1> : '<STR_LIT>' , <NUM_LIT:2> : '<STR_LIT>' } <EOL> new_stats = remap_categories ( category_map , feature_stats ) <EOL> assert <NUM_LIT:1> not in new_stats . keys ( ) <EOL> assert '<STR_LIT>' in new_stats . keys ( ) <EOL> assert <NUM_LIT:3> in new_stats . keys ( ) </s>
