Skip to content

Commit

Permalink
adding the utils test
Browse files Browse the repository at this point in the history
  • Loading branch information
mehak-sachdeva committed Aug 3, 2017
1 parent d02b5be commit 1312cc1
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/test_context.py
Expand Up @@ -17,7 +17,7 @@ def setUp(self):
os.environ.get('USERNAME') is None):
try:
creds = json.loads(open('test/secret.json').read())
except FileNotFoundError:
except OSError:
print("Create a `secret.json` file by renaming "
"`secret.json.sample` to `secret.json` and updating "
"the credentials to match your environment.")
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_cartocontext_write(self):

# check if table exists
resp = self.sql_client.send('''
SELECT *
SELECT *
FROM {table}
LIMIT 0
'''.format(table=self.test_write_table))
Expand Down
89 changes: 89 additions & 0 deletions test/test_utils.py
@@ -0,0 +1,89 @@
"""Unit tests for cartoframes.utils"""
import unittest
from cartoframes.utils import dict_items, cssify
from cartoframes import styling
from collections import OrderedDict
# from cartoframes import styling

class TestUtils(unittest.TestCase):
"""Tests for functions in utils module"""
def setUp(self):
self.point_style = OrderedDict([(
"#layer['mapnik::geometry_type'=1]", OrderedDict([
('marker-width', "6"),
('marker-fill', "yellow"),
('marker-fill-opacity', "1"),
('marker-allow-overlap', "true"),
('marker-line-width', "0.5"),
('marker-line-color', "black"),
("marker-line-opacity", "1")])
)])
self.point_style_dict = dict_items(self.point_style)
self.point_stylecss = cssify(self.point_style)
self.point_values = []
for value in self.point_style_dict:
self.point_values.append(value)
self.polygon_style = OrderedDict([(
"#layer['mapnik::geometry_type'=3]", OrderedDict([
('polygon-fill', 'ramp([column], (#ffc6c4, #ee919b, #cc607d, #9e3963, #672044), quantiles)'),
('polygon-opacity', '0.9'),
('polygon-gamma', '0.5'),
('line-color', '#FFF'),
('line-width', '0.5'),
('line-opacity', '0.25'),
('line-comp-op', 'hard-light')])
)])
self.polygon_style_dict = dict_items(self.polygon_style)
self.polygon_values = []
for value in self.polygon_style_dict:
self.polygon_values.append(value)

self.polygon_stylecss = cssify(self.polygon_style)

self.complex_style = OrderedDict([
("#layer['mapnik::geometry_type'=1]", OrderedDict([
('marker-width', "5"),
('marker-fill', "yellow"),
('marker-fill-opacity', '1'),
('marker-allow-overlap', 'true'),
('marker-line-width', '0.5'),
('marker-line-color', "black"),
('marker-line-opacity', '1')])),
("#layer['mapnik::geometry_type'=2]", OrderedDict([
('line-width', '1.5'),
('line-color', "black")])),
("#layer['mapnik::geometry_type'=3]", OrderedDict([
('polygon-fill', "blue"),
('polygon-opacity', '0.9'),
('polygon-gamma', '0.5'),
('line-color', '#FFF'),
('line-width', '0.5'),
('line-opacity', '0.25'),
('line-comp-op', 'hard-light')]))
])

self.complex_style_dict = dict_items(self.complex_style)
self.complex_values = []
for value in self.complex_style_dict:
self.complex_values.append(value)

self.complex_stylecss = cssify(self.complex_style)

def test_dict_items(self):
"""utils.dict_items"""
# ensure correct formation of dict items from provided styling
self.assertEqual(self.polygon_values,
self.polygon_style.items())
self.assertEqual(self.point_values,
self.point_style.items())
self.assertEqual(self.complex_values,
self.complex_style.items())

def test_cssify(self):
"""utils.cssify"""
self.assertEqual(self.point_stylecss,
"#layer['mapnik::geometry_type'=1] { marker-width: 6; marker-fill: yellow; marker-fill-opacity: 1; marker-allow-overlap: true; marker-line-width: 0.5; marker-line-color: black; marker-line-opacity: 1;} ")
self.assertEqual(self.polygon_stylecss,
"#layer['mapnik::geometry_type'=3] { polygon-fill: ramp([column], (#ffc6c4, #ee919b, #cc607d, #9e3963, #672044), quantiles); polygon-opacity: 0.9; polygon-gamma: 0.5; line-color: #FFF; line-width: 0.5; line-opacity: 0.25; line-comp-op: hard-light;} ")
self.assertEqual(self.complex_stylecss,
"#layer['mapnik::geometry_type'=1] { marker-width: 5; marker-fill: yellow; marker-fill-opacity: 1; marker-allow-overlap: true; marker-line-width: 0.5; marker-line-color: black; marker-line-opacity: 1;} #layer['mapnik::geometry_type'=2] { line-width: 1.5; line-color: black;} #layer['mapnik::geometry_type'=3] { polygon-fill: blue; polygon-opacity: 0.9; polygon-gamma: 0.5; line-color: #FFF; line-width: 0.5; line-opacity: 0.25; line-comp-op: hard-light;} ")

0 comments on commit 1312cc1

Please sign in to comment.