-
Notifications
You must be signed in to change notification settings - Fork 63
/
test_utils.py
89 lines (82 loc) · 4.75 KB
/
test_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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;} ")