Skip to content

Commit

Permalink
test coverage, low hanging fruit
Browse files Browse the repository at this point in the history
  • Loading branch information
perrygeo committed Sep 3, 2016
1 parent eac7994 commit 09bbf9f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ numpy>=1.9
rasterio>=0.27
cligj>=0.4
fiona
simplejson
6 changes: 1 addition & 5 deletions src/rasterstats/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
from __future__ import division
import logging

try:
import simplejson as json
except:
import json

import click
import cligj
import simplejson as json

from rasterstats import gen_zonal_stats, gen_point_query
from rasterstats._version import __version__ as version
Expand Down
4 changes: 2 additions & 2 deletions src/rasterstats/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

PY3 = sys.version_info[0] >= 3
if PY3:
string_types = str,
string_types = str, # pragma: no cover
else:
string_types = basestring,
string_types = basestring, # pragma: no cover

def wrap_geom(geom):
""" Wraps a geometry dict in an GeoJSON Feature
Expand Down
6 changes: 0 additions & 6 deletions src/rasterstats/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@ def gen_zonal_stats(
if not affine:
affine = Affine.from_gdal(*transform)

ndv = kwargs.get('nodata_value')
if ndv:
warnings.warn("Use `nodata` instead of `nodata_value`", DeprecationWarning)
if not nodata:
nodata = ndv

cp = kwargs.get('copy_properties')
if cp:
warnings.warn("Use `geojson_out` to preserve feature properties",
Expand Down
6 changes: 4 additions & 2 deletions src/rasterstats/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
['sum', 'std', 'median', 'majority', 'minority', 'unique', 'range', 'nodata']
# also percentile_{q} but that is handled as special case


def get_percentile(stat):
if not stat.startswith('percentile_'):
raise ValueError("must start with 'percentile_'")
Expand Down Expand Up @@ -50,9 +51,10 @@ def rasterize_geom(geom, like, all_touched=False):

def stats_to_csv(stats):
if sys.version_info[0] >= 3:
from io import StringIO as IO
from io import StringIO as IO # pragma: no cover
else:
from cStringIO import StringIO as IO
from cStringIO import StringIO as IO # pragma: no cover

import csv

csv_fh = IO()
Expand Down
17 changes: 16 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import sys
import os
import pytest
from rasterstats.utils import stats_to_csv, get_percentile, remap_categories
from shapely.geometry import LineString
from rasterstats.utils import \
stats_to_csv, get_percentile, remap_categories, boxify_points
from rasterstats import zonal_stats
from rasterstats.utils import VALID_STATS

Expand Down Expand Up @@ -31,6 +33,13 @@ def test_get_percentile():
assert get_percentile('percentile_100') == 100.0
assert get_percentile('percentile_13.2') == 13.2

def test_get_bad_percentile():
with pytest.raises(ValueError):
get_percentile('foo')

with pytest.raises(ValueError):
get_percentile('percentile_101')

with pytest.raises(ValueError):
get_percentile('percentile_101')

Expand All @@ -48,3 +57,9 @@ def test_remap_categories():
assert 1 not in new_stats.keys()
assert 'grassland' in new_stats.keys()
assert 3 in new_stats.keys()


def test_boxify_non_point():
line = LineString([(0, 0), (1, 1)])
with pytest.raises(ValueError):
boxify_points(line, None)

0 comments on commit 09bbf9f

Please sign in to comment.