Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the test coverage of maps.py in test_maps.py #603

Merged
merged 4 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions datascience/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,20 +395,21 @@ def read_geojson(cls, path_or_json_or_string_or_url):
data = None
if isinstance(path_or_json_or_string_or_url, (dict, list)):
data = path_or_json_or_string_or_url
try:
data = json.loads(path_or_json_or_string_or_url)
except ValueError:
pass
try:
path = path_or_json_or_string_or_url
if path.endswith('.gz') or path.endswith('.gzip'):
import gzip
contents = gzip.open(path, 'r').read().decode('utf-8')
else:
contents = open(path, 'r').read()
data = json.loads(contents)
except FileNotFoundError:
pass
else:
try:
data = json.loads(path_or_json_or_string_or_url)
except ValueError:
pass
try:
path = path_or_json_or_string_or_url
if path.endswith('.gz') or path.endswith('.gzip'):
import gzip
contents = gzip.open(path, 'r').read().decode('utf-8')
else:
contents = open(path, 'r').read()
data = json.loads(contents)
except FileNotFoundError:
pass
if not data:
import urllib.request
with urllib.request.urlopen(path_or_json_or_string_or_url) as url:
Expand All @@ -425,7 +426,7 @@ def _read_geojson_features(data, features=None, prefix=""):
key = feature.get('id', prefix + str(i))
feature_type = feature['geometry']['type']
if feature_type == 'FeatureCollection':
_read_geojson_features(feature, features, prefix + '.' + key)
value = Map._read_geojson_features(feature['geometry'], features, prefix + '.' + key)
elif feature_type == 'Point':
value = Circle._convert_point(feature)
elif feature_type in ['Polygon', 'MultiPolygon']:
Expand Down Expand Up @@ -575,7 +576,7 @@ def _convert_point(cls, feature):
"""Convert a GeoJSON point to a Marker."""
lon, lat = feature['geometry']['coordinates']
popup = feature['properties'].get('name', '')
return cls(lat, lon)
return cls(lat, lon, popup=popup)

@classmethod
def map(cls, latitudes, longitudes, labels=None, colors=None, areas=None, other_attrs=None, clustered_marker=False, **kwargs):
Expand Down
Loading