Skip to content

Commit

Permalink
Merge e00281c into 97bfb36
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-esch committed Dec 10, 2017
2 parents 97bfb36 + e00281c commit b60265f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
12 changes: 4 additions & 8 deletions cartoframes/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,7 @@ def remove_tempfile(filepath):
"""removes temporary file"""
os.remove(filepath)

tempfile = '{temp_dir}/{table_name}.csv'.format(temp_dir=temp_dir,
table_name=table_name)
tempfile = os.path.join(temp_dir, '{}.csv'.format(table_name))
self._debug_print(tempfile=tempfile)
df.drop(labels=[geom_col], axis=1, errors='ignore').to_csv(
path_or_buf=tempfile,
Expand Down Expand Up @@ -881,12 +880,9 @@ def map(self, layers=None, interactive=True,
map_name = self._send_map_template(layers, has_zoom=has_zoom)
api_url = utils.join_url(self.creds.base_url(), 'api/v1/map')

static_url = ('{api_url}/static/named/{map_name}'
'/{width}/{height}.png?{params}').format(
api_url=api_url,
map_name=map_name,
width=size[0],
height=size[1],
static_url = ('{url}.png?{params}').format(
url=utils.join_url(api_url, 'static/named',
map_name, size[0], size[1]),
params=urlencode(params))

html = '<img src="{url}" />'.format(url=static_url)
Expand Down
2 changes: 1 addition & 1 deletion cartoframes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def importify_params(param_arg):

def join_url(*parts):
"""join parts of URL into complete url"""
return '/'.join(s.strip('/') for s in parts)
return '/'.join(str(s).strip('/') for s in parts)


def minify_sql(lines):
Expand Down
35 changes: 18 additions & 17 deletions test/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def add_map_template(self):

@unittest.skipIf(WILL_SKIP, 'Skipping test, no carto credentials found')
def test_cartocontext(self):
"""CartoContext.__init__"""
"""context.CartoContext.__init__ normal usage"""
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)
self.assertEqual(cc.creds.key(), self.apikey)
Expand All @@ -132,7 +132,7 @@ def test_cartocontext(self):

@unittest.skipIf(WILL_SKIP, 'no carto credentials, skipping this test')
def test_cartocontext_credentials(self):
"""CartoContext.__init__ Credentials argument"""
"""context.CartoContext.__init__ Credentials argument"""
creds = cartoframes.Credentials(username=self.username,
key=self.apikey)
cc = cartoframes.CartoContext(creds=creds)
Expand All @@ -149,14 +149,14 @@ def test_cartocontext_credentials(self):

@unittest.skipIf(WILL_SKIP, 'no carto credentials, skipping this test')
def test_cartocontext_isorguser(self):
"""CartoContext._is_org_user"""
"""context.CartoContext._is_org_user"""
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)
self.assertTrue(not cc._is_org_user())

@unittest.skipIf(WILL_SKIP, 'no carto credentials, skipping this test')
def test_cartocontext_read(self):
"""CartoContext.read"""
"""context.CartoContext.read"""
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)
# fails if limit is smaller than zero
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_cartocontext_read(self):

@unittest.skipIf(WILL_SKIP, 'no carto credentials, skipping this test')
def test_cartocontext_write(self):
"""CartoContext.write"""
"""context.CartoContext.write normal usage"""
from cartoframes.context import MAX_ROWS_LNGLAT
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)
Expand Down Expand Up @@ -310,6 +310,7 @@ def test_cartocontext_write_index(self):

@unittest.skipIf(WILL_SKIP, 'no carto credentials, skipping')
def test_cartocontext_mixed_case(self):
"""context.CartoContext.write table name mixed case"""
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)
data = pd.DataFrame({'a': [1, 2, 3],
Expand All @@ -318,15 +319,15 @@ def test_cartocontext_mixed_case(self):

@unittest.skipIf(WILL_SKIP, 'no carto credentials, skipping')
def test_cartocontext_table_exists(self):
"""CartoContext._table_exists"""
"""context.CartoContext._table_exists"""
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)
self.assertFalse(cc._table_exists('acadia_biodiversity'))
with self.assertRaises(NameError):
cc._table_exists(self.test_read_table)

def test_cartocontext_delete(self):
"""CartoContext.delete"""
"""context.CartoContext.delete"""
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)
data = {'col1': [1, 2, 3],
Expand Down Expand Up @@ -354,11 +355,11 @@ def test_cartocontext_delete(self):
assert "Failed to delete" in str(w[-1].message)

def test_cartocontext_send_dataframe(self):
"""CartoContext._send_dataframe"""
"""context.CartoContext._send_dataframe"""
pass

def test_cartocontext_handle_import(self):
"""CartoContext._handle_import"""
"""context.CartoContext._handle_import"""

cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)
Expand All @@ -379,7 +380,7 @@ def test_cartocontext_handle_import(self):

@unittest.skipIf(WILL_SKIP, 'no carto credentials, skipping')
def test_cartoframes_sync(self):
"""cartoframes.CartoContext.sync"""
"""context.CartoContext.sync"""
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)
self.assertIsNone(cc.sync(pd.DataFrame(), 'acadia'))
Expand Down Expand Up @@ -473,7 +474,7 @@ def test_cartoframes_query(self):

@unittest.skipIf(WILL_SKIP, 'no carto credentials, skipping this test')
def test_cartocontext_map(self):
"""CartoContext.map"""
"""context.CartoContext.map normal usage"""
from cartoframes import Layer, QueryLayer, BaseMap
try:
import matplotlib
Expand Down Expand Up @@ -578,7 +579,7 @@ def test_cartocontext_map(self):

@unittest.skipIf(WILL_SKIP, 'no cartocredentials, skipping')
def test_cartocontext_map_time(self):
"""CartoContext.map time options"""
"""context.CartoContext.map time options"""
from cartoframes import Layer
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)
Expand Down Expand Up @@ -613,7 +614,7 @@ def test_cartocontext_map_time(self):

@unittest.skipIf(WILL_SKIP, 'no carto credentials, skipping this test')
def test_cartocontext_map_geom_type(self):
"""CartoContext.map basemap geometry type defaults"""
"""context.CartoContext.map basemap geometry type defaults"""
from cartoframes import Layer, QueryLayer
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)
Expand Down Expand Up @@ -660,7 +661,7 @@ def test_cartocontext_map_geom_type(self):

@unittest.skipIf(WILL_SKIP, 'no carto credentials, skipping')
def test_get_bounds(self):
"""CartoContext._get_bounds"""
"""context.CartoContext._get_bounds"""
from cartoframes.layer import QueryLayer
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)
Expand Down Expand Up @@ -702,7 +703,7 @@ def test_get_bounds(self):

@unittest.skipIf(WILL_SKIP, 'no carto credentials, skipping this test')
def test_cartocontext_check_query(self):
"""CartoContext._check_query"""
"""context.CartoContext._check_query"""
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)
# this table does not exist in this account
Expand Down Expand Up @@ -865,7 +866,7 @@ def test_debug_print(self):
self.assertIsNone(cc._debug_print(resp=test_str))

def test_data_discovery(self):
"""context.data_discovery"""
"""context.CartoContext.data_discovery"""
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)

Expand Down Expand Up @@ -918,7 +919,7 @@ def test_data_discovery(self):
self.assertTrue(dd.shape[0] >= 1)

def test_data(self):
"""context.data"""
"""context.CartoContext.data"""
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)

Expand Down

0 comments on commit b60265f

Please sign in to comment.