author | Lennard de Rijk <ljvderijk@gmail.com> |
Sat, 05 Sep 2009 14:04:24 +0200 | |
changeset 2862 | 27971a13089f |
parent 2373 | 05ab9393303d |
permissions | -rwxr-xr-x |
2373
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
2 |
# |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright (C) 2008 Google Inc. |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
4 |
# |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
8 |
# |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
10 |
# |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
16 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
17 |
"""Tests for the gviz_api module.""" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
18 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
19 |
__author__ = "Amit Weinstein" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
20 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
21 |
from datetime import date |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
22 |
from datetime import datetime |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
23 |
from datetime import time |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
24 |
import re |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
25 |
import unittest |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
26 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
27 |
from gviz_api import DataTable |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
28 |
from gviz_api import DataTableException |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
29 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
30 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
31 |
class DataTableTest(unittest.TestCase): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
32 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
33 |
def testSingleValueToJS(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
34 |
# We first check that given an unknown type it raises exception |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
35 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
36 |
DataTable.SingleValueToJS, 1, "no_such_type") |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
37 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
38 |
# If we give a type which does not match the value, we expect it to fail |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
39 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
40 |
DataTable.SingleValueToJS, "a", "number") |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
41 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
42 |
DataTable.SingleValueToJS, "b", "timeofday") |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
43 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
44 |
DataTable.SingleValueToJS, 10, "date") |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
45 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
46 |
# A tuple for value and formatted value should be of length 2 |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
47 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
48 |
DataTable.SingleValueToJS, (5, "5$", "6$"), "string") |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
49 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
50 |
# Some good examples from all the different types |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
51 |
self.assertEqual("true", DataTable.SingleValueToJS(True, "boolean")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
52 |
self.assertEqual("false", DataTable.SingleValueToJS(False, "boolean")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
53 |
self.assertEqual("true", DataTable.SingleValueToJS(1, "boolean")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
54 |
self.assertEqual("null", DataTable.SingleValueToJS(None, "boolean")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
55 |
self.assertEqual(("false", "'a'"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
56 |
DataTable.SingleValueToJS((False, "a"), "boolean")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
57 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
58 |
self.assertEqual("1", DataTable.SingleValueToJS(1, "number")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
59 |
self.assertEqual("1.0", DataTable.SingleValueToJS(1., "number")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
60 |
self.assertEqual("-5", DataTable.SingleValueToJS(-5, "number")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
61 |
self.assertEqual("null", DataTable.SingleValueToJS(None, "number")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
62 |
self.assertEqual(("5", "'5$'"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
63 |
DataTable.SingleValueToJS((5, "5$"), "number")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
64 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
65 |
self.assertEqual("'-5'", DataTable.SingleValueToJS(-5, "string")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
66 |
self.assertEqual("'abc'", DataTable.SingleValueToJS("abc", "string")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
67 |
self.assertEqual("null", DataTable.SingleValueToJS(None, "string")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
68 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
69 |
self.assertEqual("new Date(2010,0,2)", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
70 |
DataTable.SingleValueToJS(date(2010, 1, 2), "date")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
71 |
self.assertEqual("new Date(2001,1,3)", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
72 |
DataTable.SingleValueToJS(datetime(2001, 2, 3, 4, 5, 6), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
73 |
"date")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
74 |
self.assertEqual("null", DataTable.SingleValueToJS(None, "date")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
75 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
76 |
self.assertEqual("[10,11,12]", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
77 |
DataTable.SingleValueToJS(time(10, 11, 12), "timeofday")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
78 |
self.assertEqual("[3,4,5]", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
79 |
DataTable.SingleValueToJS(datetime(2010, 1, 2, 3, 4, 5), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
80 |
"timeofday")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
81 |
self.assertEqual("null", DataTable.SingleValueToJS(None, "timeofday")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
82 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
83 |
self.assertEqual("new Date(2001,1,3,4,5,6)", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
84 |
DataTable.SingleValueToJS(datetime(2001, 2, 3, 4, 5, 6), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
85 |
"datetime")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
86 |
self.assertEqual("null", DataTable.SingleValueToJS(None, "datetime")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
87 |
self.assertEqual(("null", "'none'"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
88 |
DataTable.SingleValueToJS((None, "none"), "string")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
89 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
90 |
def testDifferentStrings(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
91 |
# Checking escaping of strings |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
92 |
problematic_strings = ["control", "new\nline", "", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
93 |
"single'quote", 'double"quote', |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
94 |
r"one\slash", r"two\\slash", u"unicode eng", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
95 |
u"unicode \u05e2\u05d1\u05e8\u05d9\u05ea"] |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
96 |
for s in problematic_strings: |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
97 |
js_value = DataTable.SingleValueToJS(s, "string") |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
98 |
if isinstance(js_value, unicode): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
99 |
js_value = "u%s" % js_value |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
100 |
self.assertEquals(s, eval(js_value)) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
101 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
102 |
js_value = DataTable.SingleValueToJS(("str", s), "string")[1] |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
103 |
if isinstance(js_value, unicode): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
104 |
js_value = "u%s" % js_value |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
105 |
self.assertEquals(s, eval(js_value)) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
106 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
107 |
def testDifferentCustomProperties(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
108 |
# Checking escaping of custom properties |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
109 |
problematic_cps = [{"control": "test"}, {u"unicode": "value"}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
110 |
{"key": u"unicode"}, {u"unicode": u"unicode"}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
111 |
{"regular": "single'quote"}, {"unicode": u"s'quote"}] |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
112 |
for cp in problematic_cps: |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
113 |
js_value = DataTable._EscapeCustomProperties(cp) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
114 |
self.assertEquals(cp, eval(js_value)) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
115 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
116 |
def testColumnTypeParser(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
117 |
# Checking several wrong formats |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
118 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
119 |
DataTable.ColumnTypeParser, 5) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
120 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
121 |
DataTable.ColumnTypeParser, ("a", "b", "c", "d")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
122 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
123 |
DataTable.ColumnTypeParser, ("a", 5, "c")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
124 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
125 |
# Checking several legal formats |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
126 |
self.assertEqual({"id": "abc", "label": "abc", "type": "string", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
127 |
"custom_properties": {}}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
128 |
DataTable.ColumnTypeParser("abc")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
129 |
self.assertEqual({"id": "abc", "label": "abc", "type": "string", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
130 |
"custom_properties": {}}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
131 |
DataTable.ColumnTypeParser(("abc",))) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
132 |
self.assertEqual({"id": "abc", "label": "bcd", "type": "string", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
133 |
"custom_properties": {}}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
134 |
DataTable.ColumnTypeParser(("abc", "string", "bcd"))) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
135 |
self.assertEqual({"id": "a", "label": "b", "type": "number", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
136 |
"custom_properties": {}}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
137 |
DataTable.ColumnTypeParser(("a", "number", "b"))) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
138 |
self.assertEqual({"id": "a", "label": "a", "type": "number", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
139 |
"custom_properties": {}}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
140 |
DataTable.ColumnTypeParser(("a", "number"))) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
141 |
self.assertEqual({"id": "i", "label": "l", "type": "string", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
142 |
"custom_properties": {"key": "value"}}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
143 |
DataTable.ColumnTypeParser(("i", "string", "l", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
144 |
{"key": "value"}))) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
145 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
146 |
def testTableDescriptionParser(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
147 |
# We expect it to fail with empty lists or dictionaries |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
148 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
149 |
DataTable.TableDescriptionParser, {}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
150 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
151 |
DataTable.TableDescriptionParser, []) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
152 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
153 |
DataTable.TableDescriptionParser, {"a": []}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
154 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
155 |
DataTable.TableDescriptionParser, {"a": {"b": {}}}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
156 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
157 |
# We expect it to fail if we give a non-string at the lowest level |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
158 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
159 |
DataTable.TableDescriptionParser, {"a": 5}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
160 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
161 |
DataTable.TableDescriptionParser, [("a", "number"), 6]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
162 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
163 |
# Some valid examples which mixes both dictionaries and lists |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
164 |
self.assertEqual( |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
165 |
[{"id": "a", "label": "a", "type": "date", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
166 |
"depth": 0, "container": "iter", "custom_properties": {}}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
167 |
{"id": "b", "label": "b", "type": "timeofday", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
168 |
"depth": 0, "container": "iter", "custom_properties": {}}], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
169 |
DataTable.TableDescriptionParser([("a", "date"), ("b", "timeofday")])) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
170 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
171 |
self.assertEqual( |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
172 |
[{"id": "a", "label": "a", "type": "string", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
173 |
"depth": 0, "container": "dict", "custom_properties": {}}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
174 |
{"id": "b", "label": "b", "type": "number", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
175 |
"depth": 1, "container": "iter", "custom_properties": {}}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
176 |
{"id": "c", "label": "column c", "type": "string", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
177 |
"depth": 1, "container": "iter", "custom_properties": {}}], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
178 |
DataTable.TableDescriptionParser({"a": [("b", "number"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
179 |
("c", "string", "column c")]})) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
180 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
181 |
self.assertEqual( |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
182 |
[{"id": "a", "label": "column a", "type": "number", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
183 |
"depth": 0, "container": "dict", "custom_properties": {}}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
184 |
{"id": "b", "label": "b", "type": "number", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
185 |
"depth": 1, "container": "dict", "custom_properties": {}}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
186 |
{"id": "c", "label": "c", "type": "string", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
187 |
"depth": 1, "container": "dict", "custom_properties": {}}], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
188 |
DataTable.TableDescriptionParser({("a", "number", "column a"): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
189 |
{"b": "number", "c": "string"}})) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
190 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
191 |
self.assertEqual( |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
192 |
[{"id": "a", "label": "column a", "type": "number", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
193 |
"depth": 0, "container": "dict", "custom_properties": {}}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
194 |
{"id": "b", "label": "column b", "type": "string", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
195 |
"depth": 1, "container": "scalar", "custom_properties": {}}], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
196 |
DataTable.TableDescriptionParser({("a", "number", "column a"): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
197 |
("b", "string", "column b")})) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
198 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
199 |
def testAppendData(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
200 |
# We check a few examples where the format of the data does not match the |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
201 |
# description and hen a few valid examples. The test for the content itself |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
202 |
# is done inside the ToJSCode and ToJSon functions. |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
203 |
table = DataTable([("a", "number"), ("b", "string")]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
204 |
self.assertEqual(0, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
205 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
206 |
table.AppendData, [[1, "a", True]]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
207 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
208 |
table.AppendData, {1: ["a"], 2: ["b"]}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
209 |
self.assertEquals(None, table.AppendData([[1, "a"], [2, "b"]])) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
210 |
self.assertEqual(2, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
211 |
self.assertEquals(None, table.AppendData([[3, "c"], [4]])) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
212 |
self.assertEqual(4, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
213 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
214 |
table = DataTable({"a": "number", "b": "string"}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
215 |
self.assertEqual(0, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
216 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
217 |
table.AppendData, [[1, "a"]]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
218 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
219 |
table.AppendData, {5: {"b": "z"}}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
220 |
self.assertEquals(None, table.AppendData([{"a": 1, "b": "z"}])) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
221 |
self.assertEqual(1, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
222 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
223 |
table = DataTable({("a", "number"): [("b", "string")]}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
224 |
self.assertEqual(0, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
225 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
226 |
table.AppendData, [[1, "a"]]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
227 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
228 |
table.AppendData, {5: {"b": "z"}}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
229 |
self.assertEquals(None, table.AppendData({5: ["z"], 6: ["w"]})) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
230 |
self.assertEqual(2, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
231 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
232 |
table = DataTable({("a", "number"): {"b": "string", "c": "number"}}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
233 |
self.assertEqual(0, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
234 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
235 |
table.AppendData, [[1, "a"]]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
236 |
self.assertRaises(DataTableException, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
237 |
table.AppendData, {1: ["a", 2]}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
238 |
self.assertEquals(None, table.AppendData({5: {"b": "z", "c": 6}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
239 |
7: {"c": 8}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
240 |
9: {}})) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
241 |
self.assertEqual(3, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
242 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
243 |
def testToJSCode(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
244 |
table = DataTable([("a", "number", "A"), "b", ("c", "timeofday")], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
245 |
[[1], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
246 |
[None, "z", time(1, 2, 3)], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
247 |
[(2, "2$"), "w", time(2, 3, 4)]]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
248 |
self.assertEqual(3, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
249 |
self.assertEqual(("var mytab = new google.visualization.DataTable();\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
250 |
"mytab.addColumn('number', 'A', 'a');\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
251 |
"mytab.addColumn('string', 'b', 'b');\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
252 |
"mytab.addColumn('timeofday', 'c', 'c');\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
253 |
"mytab.addRows(3);\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
254 |
"mytab.setCell(0, 0, 1);\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
255 |
"mytab.setCell(1, 1, 'z');\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
256 |
"mytab.setCell(1, 2, [1,2,3]);\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
257 |
"mytab.setCell(2, 0, 2, '2$');\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
258 |
"mytab.setCell(2, 1, 'w');\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
259 |
"mytab.setCell(2, 2, [2,3,4]);\n"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
260 |
table.ToJSCode("mytab")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
261 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
262 |
table = DataTable({("a", "number"): {"b": "date", "c": "datetime"}}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
263 |
{1: {}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
264 |
2: {"b": date(1, 2, 3)}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
265 |
3: {"c": datetime(1, 2, 3, 4, 5, 6)}}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
266 |
self.assertEqual(3, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
267 |
self.assertEqual(("var mytab2 = new google.visualization.DataTable();\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
268 |
"mytab2.addColumn('datetime', 'c', 'c');\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
269 |
"mytab2.addColumn('date', 'b', 'b');\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
270 |
"mytab2.addColumn('number', 'a', 'a');\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
271 |
"mytab2.addRows(3);\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
272 |
"mytab2.setCell(0, 2, 1);\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
273 |
"mytab2.setCell(1, 1, new Date(1,1,3));\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
274 |
"mytab2.setCell(1, 2, 2);\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
275 |
"mytab2.setCell(2, 0, new Date(1,1,3,4,5,6));\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
276 |
"mytab2.setCell(2, 2, 3);\n"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
277 |
table.ToJSCode("mytab2", columns_order=["c", "b", "a"])) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
278 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
279 |
def testToJSon(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
280 |
# The json of the initial data we load to the table. |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
281 |
init_data_json = ("{cols:" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
282 |
"[{id:'a',label:'A',type:'number'}," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
283 |
"{id:'b',label:'b',type:'string'}," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
284 |
"{id:'c',label:'c',type:'boolean'}]," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
285 |
"rows:[" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
286 |
"{c:[{v:1},,{v:null}]}," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
287 |
"{c:[,{v:'z'},{v:true}]}" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
288 |
"]}") |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
289 |
table = DataTable([("a", "number", "A"), "b", ("c", "boolean")], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
290 |
[[1], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
291 |
[None, "z", True]]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
292 |
self.assertEqual(2, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
293 |
self.assertEqual(init_data_json, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
294 |
table.ToJSon()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
295 |
table.AppendData([[-1, "w", False]]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
296 |
self.assertEqual(3, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
297 |
self.assertEqual(init_data_json[:-2] + ",{c:[{v:-1},{v:'w'},{v:false}]}]}", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
298 |
table.ToJSon()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
299 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
300 |
cols_json = ("{cols:" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
301 |
"[{id:'t',label:'T',type:'timeofday'}," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
302 |
"{id:'d',label:'d',type:'date'}," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
303 |
"{id:'dt',label:'dt',type:'datetime'}],") |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
304 |
table = DataTable({("d", "date"): [("t", "timeofday", "T"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
305 |
("dt", "datetime")]}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
306 |
table.LoadData({date(1, 2, 3): [time(1, 2, 3)]}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
307 |
self.assertEqual(1, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
308 |
self.assertEqual(cols_json + |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
309 |
"rows:[{c:[{v:[1,2,3]},{v:new Date(1,1,3)},{v:null}]}]}", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
310 |
table.ToJSon(columns_order=["t", "d", "dt"])) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
311 |
table.LoadData({date(2, 3, 4): [(time(2, 3, 4), "time 2 3 4"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
312 |
datetime(1, 2, 3, 4, 5, 6)], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
313 |
date(3, 4, 5): []}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
314 |
self.assertEqual(2, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
315 |
self.assertEqual((cols_json + "rows:[" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
316 |
"{c:[{v:[2,3,4],f:'time 2 3 4'},{v:new Date(2,2,4)}," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
317 |
"{v:new Date(1,1,3,4,5,6)}]}," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
318 |
"{c:[,{v:new Date(3,3,5)},{v:null}]}]}"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
319 |
table.ToJSon(columns_order=["t", "d", "dt"])) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
320 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
321 |
json = ("{cols:[{id:'a',label:'a',type:'string'}," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
322 |
"{id:'b',label:'b',type:'number'}]," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
323 |
"rows:[{c:[{v:'a1'},{v:1}]},{c:[{v:'a2'},{v:2}]}," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
324 |
"{c:[{v:'a3'},{v:3}]}]}") |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
325 |
table = DataTable({"a": ("b", "number")}, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
326 |
{"a1": 1, "a2": 2, "a3": 3}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
327 |
self.assertEqual(3, table.NumberOfRows()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
328 |
self.assertEqual(json, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
329 |
table.ToJSon()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
330 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
331 |
def testCustomProperties(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
332 |
# The json of the initial data we load to the table. |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
333 |
json = ("{cols:" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
334 |
"[{id:'a',label:'A',type:'number',p:{'col_cp':'col_v'}}," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
335 |
"{id:'b',label:'b',type:'string'}," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
336 |
"{id:'c',label:'c',type:'boolean'}]," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
337 |
"rows:[" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
338 |
"{c:[{v:1},,{v:null,p:{'null_cp':'null_v'}}],p:{'row_cp':'row_v'}}," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
339 |
"{c:[,{v:'z',p:{'cell_cp':'cell_v'}},{v:true}]}," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
340 |
"{c:[{v:3},,{v:null}],p:{'row_cp2':'row_v2'}}]," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
341 |
"p:{'global_cp':'global_v'}" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
342 |
"}") |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
343 |
jscode = ("var mytab = new google.visualization.DataTable();\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
344 |
"mytab.setTableProperties({'global_cp':'global_v'});\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
345 |
"mytab.addColumn('number', 'A', 'a');\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
346 |
"mytab.setColumnProperties(0, {'col_cp':'col_v'});\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
347 |
"mytab.addColumn('string', 'b', 'b');\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
348 |
"mytab.addColumn('boolean', 'c', 'c');\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
349 |
"mytab.addRows(3);\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
350 |
"mytab.setCell(0, 0, 1);\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
351 |
"mytab.setCell(0, 2, null, null, {'null_cp':'null_v'});\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
352 |
"mytab.setRowProperties(0, {'row_cp':'row_v'});\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
353 |
"mytab.setCell(1, 1, 'z', null, {'cell_cp':'cell_v'});\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
354 |
"mytab.setCell(1, 2, true);\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
355 |
"mytab.setCell(2, 0, 3);\n" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
356 |
"mytab.setRowProperties(2, {'row_cp2':'row_v2'});\n") |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
357 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
358 |
table = DataTable([("a", "number", "A", {"col_cp": "col_v"}), "b", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
359 |
("c", "boolean")], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
360 |
custom_properties={"global_cp": "global_v"}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
361 |
table.AppendData([[1, None, (None, None, {"null_cp": "null_v"})]], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
362 |
custom_properties={"row_cp": "row_v"}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
363 |
table.AppendData([[None, ("z", None, {"cell_cp": "cell_v"}), True], [3]]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
364 |
table.SetRowsCustomProperties(2, {"row_cp2": "row_v2"}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
365 |
self.assertEqual(json, table.ToJSon()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
366 |
self.assertEqual(jscode, table.ToJSCode("mytab")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
367 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
368 |
def testToCsv(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
369 |
init_data_csv = "\n".join(['"A", "b", "c"', |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
370 |
'1, "", ""', |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
371 |
'"", "zz\'top", true']) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
372 |
table = DataTable([("a", "number", "A"), "b", ("c", "boolean")], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
373 |
[[(1, "$1")], [None, "zz'top", True]]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
374 |
self.assertEqual(init_data_csv, table.ToCsv()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
375 |
table.AppendData([[-1, "w", False]]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
376 |
init_data_csv = "%s\n%s" % (init_data_csv, '-1, "w", false') |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
377 |
self.assertEquals(init_data_csv, table.ToCsv()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
378 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
379 |
init_data_csv = "\n".join([ |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
380 |
'"T", "d", "dt"', |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
381 |
'"[1,2,3]", "new Date(1,1,3)", ""', |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
382 |
'"time ""2 3 4""", "new Date(2,2,4)", "new Date(1,1,3,4,5,6)"', |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
383 |
'"", "new Date(3,3,5)", ""']) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
384 |
table = DataTable({("d", "date"): [("t", "timeofday", "T"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
385 |
("dt", "datetime")]}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
386 |
table.LoadData({date(1, 2, 3): [time(1, 2, 3)], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
387 |
date(2, 3, 4): [(time(2, 3, 4), 'time "2 3 4"'), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
388 |
datetime(1, 2, 3, 4, 5, 6)], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
389 |
date(3, 4, 5): []}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
390 |
self.assertEqual(init_data_csv, table.ToCsv(columns_order=["t", "d", "dt"])) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
391 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
392 |
def testToTsvExcel(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
393 |
table = DataTable({("d", "date"): [("t", "timeofday", "T"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
394 |
("dt", "datetime")]}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
395 |
table.LoadData({date(1, 2, 3): [time(1, 2, 3)], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
396 |
date(2, 3, 4): [(time(2, 3, 4), 'time "2 3 4"'), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
397 |
datetime(1, 2, 3, 4, 5, 6)], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
398 |
date(3, 4, 5): []}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
399 |
self.assertEqual(table.ToCsv().replace(", ", "\t").encode("UTF-16LE"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
400 |
table.ToTsvExcel()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
401 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
402 |
def testToHtml(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
403 |
html_table_header = "<html><body><table border='1'>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
404 |
html_table_footer = "</table></body></html>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
405 |
init_data_html = html_table_header + ( |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
406 |
"<thead><tr>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
407 |
"<th>A</th><th>b</th><th>c</th>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
408 |
"</tr></thead>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
409 |
"<tbody>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
410 |
"<tr><td>'$1'</td><td></td><td></td></tr>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
411 |
"<tr><td></td><td>'<z>'</td><td>true</td></tr>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
412 |
"</tbody>") + html_table_footer |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
413 |
table = DataTable([("a", "number", "A"), "b", ("c", "boolean")], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
414 |
[[(1, "$1")], [None, "<z>", True]]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
415 |
self.assertEqual(init_data_html.replace("\n", ""), table.ToHtml()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
416 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
417 |
init_data_html = html_table_header + ( |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
418 |
"<thead><tr>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
419 |
"<th>T</th><th>d</th><th>dt</th>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
420 |
"</tr></thead>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
421 |
"<tbody>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
422 |
"<tr><td>[1,2,3]</td><td>new Date(1,1,3)</td><td></td></tr>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
423 |
"<tr><td>'time 2 3 4'</td><td>new Date(2,2,4)</td>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
424 |
"<td>new Date(1,1,3,4,5,6)</td></tr>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
425 |
"<tr><td></td><td>new Date(3,3,5)</td><td></td></tr>" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
426 |
"</tbody>") + html_table_footer |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
427 |
table = DataTable({("d", "date"): [("t", "timeofday", "T"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
428 |
("dt", "datetime")]}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
429 |
table.LoadData({date(1, 2, 3): [time(1, 2, 3)], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
430 |
date(2, 3, 4): [(time(2, 3, 4), "time 2 3 4"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
431 |
datetime(1, 2, 3, 4, 5, 6)], |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
432 |
date(3, 4, 5): []}) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
433 |
self.assertEqual(init_data_html.replace("\n", ""), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
434 |
table.ToHtml(columns_order=["t", "d", "dt"])) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
435 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
436 |
def testOrderBy(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
437 |
data = [("b", 3), ("a", 3), ("a", 2), ("b", 1)] |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
438 |
description = ["col1", ("col2", "number", "Second Column")] |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
439 |
table = DataTable(description, data) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
440 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
441 |
table_num_sorted = DataTable(description, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
442 |
sorted(data, key=lambda x: (x[1], x[0]))) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
443 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
444 |
table_str_sorted = DataTable(description, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
445 |
sorted(data, key=lambda x: x[0])) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
446 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
447 |
table_diff_sorted = DataTable(description, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
448 |
sorted(sorted(data, key=lambda x: x[1]), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
449 |
key=lambda x: x[0], reverse=True)) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
450 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
451 |
self.assertEqual(table_num_sorted.ToJSon(), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
452 |
table.ToJSon(order_by=("col2", "col1"))) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
453 |
self.assertEqual(table_num_sorted.ToJSCode("mytab"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
454 |
table.ToJSCode("mytab", order_by=("col2", "col1"))) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
455 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
456 |
self.assertEqual(table_str_sorted.ToJSon(), table.ToJSon(order_by="col1")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
457 |
self.assertEqual(table_str_sorted.ToJSCode("mytab"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
458 |
table.ToJSCode("mytab", order_by="col1")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
459 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
460 |
self.assertEqual(table_diff_sorted.ToJSon(), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
461 |
table.ToJSon(order_by=[("col1", "desc"), "col2"])) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
462 |
self.assertEqual(table_diff_sorted.ToJSCode("mytab"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
463 |
table.ToJSCode("mytab", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
464 |
order_by=[("col1", "desc"), "col2"])) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
465 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
466 |
def testToJSonResponse(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
467 |
description = ["col1", "col2", "col3"] |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
468 |
data = [("1", "2", "3"), ("a", "b", "c"), ("One", "Two", "Three")] |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
469 |
req_id = 4 |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
470 |
table = DataTable(description, data) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
471 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
472 |
start_str_default = r"google.visualization.Query.setResponse" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
473 |
start_str_handler = r"MyHandlerFunction" |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
474 |
default_params = (r"\s*'version'\s*:\s*'0.6'\s*,\s*'reqId'\s*:\s*'%s'\s*," |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
475 |
r"\s*'status'\s*:\s*'OK'\s*" % req_id) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
476 |
regex1 = re.compile("%s\(\s*\{%s,\s*'table'\s*:\s*{(.*)}\s*\}\s*\);" % |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
477 |
(start_str_default, default_params)) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
478 |
regex2 = re.compile("%s\(\s*\{%s,\s*'table'\s*:\s*{(.*)}\s*\}\s*\);" % |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
479 |
(start_str_handler, default_params)) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
480 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
481 |
json_str = table.ToJSon().strip() |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
482 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
483 |
json_response = table.ToJSonResponse(req_id=req_id) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
484 |
match = regex1.findall(json_response) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
485 |
self.assertEquals(len(match), 1) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
486 |
# We want to match against the json_str without the curly brackets. |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
487 |
self.assertEquals(match[0], json_str[1:-1]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
488 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
489 |
json_response = table.ToJSonResponse(req_id=req_id, |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
490 |
response_handler=start_str_handler) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
491 |
match = regex2.findall(json_response) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
492 |
self.assertEquals(len(match), 1) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
493 |
# We want to match against the json_str without the curly brackets. |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
494 |
self.assertEquals(match[0], json_str[1:-1]) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
495 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
496 |
def testToResponse(self): |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
497 |
description = ["col1", "col2", "col3"] |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
498 |
data = [("1", "2", "3"), ("a", "b", "c"), ("One", "Two", "Three")] |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
499 |
table = DataTable(description, data) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
500 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
501 |
self.assertEquals(table.ToResponse(), table.ToJSonResponse()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
502 |
self.assertEquals(table.ToResponse(tqx="out:csv"), table.ToCsv()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
503 |
self.assertEquals(table.ToResponse(tqx="out:html"), table.ToHtml()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
504 |
self.assertRaises(DataTableException, table.ToResponse, tqx="version:0.1") |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
505 |
self.assertEquals(table.ToResponse(tqx="reqId:4;responseHandler:handle"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
506 |
table.ToJSonResponse(req_id=4, response_handler="handle")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
507 |
self.assertEquals(table.ToResponse(tqx="out:csv;reqId:4"), table.ToCsv()) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
508 |
self.assertEquals(table.ToResponse(order_by="col2"), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
509 |
table.ToJSonResponse(order_by="col2")) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
510 |
self.assertEquals(table.ToResponse(tqx="out:html", |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
511 |
columns_order=("col3", "col2", "col1")), |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
512 |
table.ToHtml(columns_order=("col3", "col2", "col1"))) |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
513 |
self.assertRaises(ValueError, table.ToResponse, tqx="SomeWrongTqxFormat") |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
514 |
self.assertRaises(DataTableException, table.ToResponse, tqx="out:bad") |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
515 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
516 |
|
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
517 |
if __name__ == "__main__": |
05ab9393303d
Add google-visualization-python project to Melange repository.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
518 |
unittest.main() |