Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d02b5be
commit 1312cc1
Showing
2 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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;} ") |