Skip to content

Commit

Permalink
Improved pytest coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Jul 24, 2021
1 parent b0645c9 commit 004d509
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 43 deletions.
14 changes: 11 additions & 3 deletions leafmap/heremap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import here_map_widget
import ipywidgets as widgets
from .basemaps import here_basemaps
from .common import shp_to_geojson, gdf_to_geojson, vector_to_geojson
from .common import shp_to_geojson, gdf_to_geojson, vector_to_geojson, random_string

from here_map_widget import (
FullscreenControl,
Expand All @@ -34,7 +34,15 @@ class Map(here_map_widget.Map):
object: here_map_widget map object.
"""

def __init__(self, api_key, **kwargs):
def __init__(self, api_key=None, **kwargs):

if api_key is None:
api_key = os.environ.get("HEREMAPS_API_KEY")
if api_key is None:
raise ValueError(
"Please provide an api_key or set the HEREMAPS_API_KEY environment variable."
)

if "center" not in kwargs:
kwargs["center"] = [40, -100]

Expand Down Expand Up @@ -560,4 +568,4 @@ def add_vector(
info_mode=info_mode,
point_style=point_style,
default_popup=default_popup,
)
)
42 changes: 21 additions & 21 deletions tests/test_foliumap.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,19 @@ def test_add_osm_from_view(self):
out_str = m.to_html()
assert "NYC buildings" not in out_str

# def test_add_planet_by_month(self):
# """Check Planet monthly imagery"""
# m = leafmap.Map()
# m.add_planet_by_month(year=2020, month=8)
# out_str = m.to_html()
# assert "Planet_2020_08" in out_str

# def test_add_planet_by_quarter(self):
# """Check Planet quarterly imagery"""
# m = leafmap.Map()
# m.add_planet_by_quarter(year=2019, quarter=2)
# out_str = m.to_html()
# assert "Planet_2019_q2" in out_str
def test_add_planet_by_month(self):
"""Check Planet monthly imagery"""
m = leafmap.Map()
m.add_planet_by_month(year=2020, month=8)
out_str = m.to_html()
assert "Planet_2020_08" in out_str

def test_add_planet_by_quarter(self):
"""Check Planet quarterly imagery"""
m = leafmap.Map()
m.add_planet_by_quarter(year=2019, quarter=2)
out_str = m.to_html()
assert "Planet_2019_q2" in out_str

def test_add_point_layer(self):
"""Check adding point layer"""
Expand Down Expand Up @@ -304,14 +304,14 @@ def test_add_tile_layer(self):
out_str = m.to_html()
assert "Google Satellite" in out_str

# def test_add_time_slider(self):
# """Check adding time slider"""
# with self.assertRaises(NotImplementedError):
# m = leafmap.Map()
# layers_dict = leafmap.planet_quarterly_tiles()
# m.add_time_slider(layers_dict, time_interval=1)
# out_str = m.to_html()
# assert "Planet_2019_q2" in out_str
def test_add_time_slider(self):
"""Check adding time slider"""
with self.assertRaises(NotImplementedError):
m = leafmap.Map()
layers_dict = leafmap.planet_quarterly_tiles()
m.add_time_slider(layers_dict, time_interval=1)
out_str = m.to_html()
assert "Planet_2019_q2" in out_str

def test_add_vector(self):
"""Check adding vector"""
Expand Down
38 changes: 19 additions & 19 deletions tests/test_leafmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,19 @@ def test_add_osm_from_view(self):
out_str = m.to_html()
assert "NYC buildings" in out_str

# def test_add_planet_by_month(self):
# """Check Planet monthly imagery"""
# m = leafmap.Map()
# m.add_planet_by_month(year=2020, month=8)
# out_str = m.to_html()
# assert "Planet_2020_08" in out_str
def test_add_planet_by_month(self):
"""Check Planet monthly imagery"""
m = leafmap.Map()
m.add_planet_by_month(year=2020, month=8)
out_str = m.to_html()
assert "Planet_2020_08" in out_str

# def test_add_planet_by_quarter(self):
# """Check Planet quarterly imagery"""
# m = leafmap.Map()
# m.add_planet_by_quarter(year=2019, quarter=2)
# out_str = m.to_html()
# assert "Planet_2019_q2" in out_str
def test_add_planet_by_quarter(self):
"""Check Planet quarterly imagery"""
m = leafmap.Map()
m.add_planet_by_quarter(year=2019, quarter=2)
out_str = m.to_html()
assert "Planet_2019_q2" in out_str

def test_add_point_layer(self):
"""Check adding point layer"""
Expand Down Expand Up @@ -299,13 +299,13 @@ def test_add_tile_layer(self):
out_str = m.to_html()
assert "Google Satellite" in out_str

# def test_add_time_slider(self):
# """Check adding time slider"""
# m = leafmap.Map()
# layers_dict = leafmap.planet_quarterly_tiles()
# m.add_time_slider(layers_dict, time_interval=1)
# out_str = m.to_html()
# assert "Planet_2019_q2" in out_str
def test_add_time_slider(self):
"""Check adding time slider"""
m = leafmap.Map()
layers_dict = leafmap.planet_quarterly_tiles()
m.add_time_slider(layers_dict, time_interval=1)
out_str = m.to_html()
assert "Planet_2019_q2" in out_str

def test_add_vector(self):
"""Check adding vector"""
Expand Down

0 comments on commit 004d509

Please sign in to comment.