def testCustomProperties(self): # The json of the initial data we load to the table. json = ( "{cols:" "[{id:'a',label:'A',type:'number',p:{'col_cp':'col_v'}}," "{id:'b',label:'b',type:'string'}," "{id:'c',label:'c',type:'boolean'}]," "rows:[" "{c:[{v:1},,{v:null,p:{'null_cp':'null_v'}}],p:{'row_cp':'row_v'}}," "{c:[,{v:'z',p:{'cell_cp':'cell_v'}},{v:true}]}," "{c:[{v:3},,{v:null}],p:{'row_cp2':'row_v2'}}]," "p:{'global_cp':'global_v'}" "}") jscode = ("var mytab = new google.visualization.DataTable();\n" "mytab.setTableProperties({'global_cp':'global_v'});\n" "mytab.addColumn('number', 'A', 'a');\n" "mytab.setColumnProperties(0, {'col_cp':'col_v'});\n" "mytab.addColumn('string', 'b', 'b');\n" "mytab.addColumn('boolean', 'c', 'c');\n" "mytab.addRows(3);\n" "mytab.setCell(0, 0, 1);\n" "mytab.setCell(0, 2, null, null, {'null_cp':'null_v'});\n" "mytab.setRowProperties(0, {'row_cp':'row_v'});\n" "mytab.setCell(1, 1, 'z', null, {'cell_cp':'cell_v'});\n" "mytab.setCell(1, 2, true);\n" "mytab.setCell(2, 0, 3);\n" "mytab.setRowProperties(2, {'row_cp2':'row_v2'});\n") table = DataTable([("a", "number", "A", { "col_cp": "col_v" }), "b", ("c", "boolean")], custom_properties={"global_cp": "global_v"}) table.AppendData([[1, None, (None, None, { "null_cp": "null_v" })]], custom_properties={"row_cp": "row_v"}) table.AppendData([[None, ("z", None, { "cell_cp": "cell_v" }), True], [3]]) table.SetRowsCustomProperties(2, {"row_cp2": "row_v2"}) self.assertEqual(json, table.ToJSon()) self.assertEqual(jscode, table.ToJSCode("mytab"))
def testCustomProperties(self): # The json of the initial data we load to the table. json_obj = { "cols": [{ "id": "a", "label": "A", "type": "number", "p": { "col_cp": "col_v" } }, { "id": "b", "label": "b", "type": "string" }, { "id": "c", "label": "c", "type": "boolean" }], "rows": [{ "c": [{ "v": 1 }, None, { "v": None, "p": { "null_cp": "null_v" } }], "p": { "row_cp": "row_v" } }, { "c": [None, { "v": "z", "p": { "cell_cp": "cell_v" } }, { "v": True }] }, { "c": [{ "v": 3 }, None, None], "p": { "row_cp2": "row_v2" } }], "p": { "global_cp": "global_v" } } jscode = ( "var mytab = new google.visualization.DataTable();\n" "mytab.setTableProperties({\"global_cp\":\"global_v\"});\n" "mytab.addColumn(\"number\", \"A\", \"a\");\n" "mytab.setColumnProperties(0, {\"col_cp\":\"col_v\"});\n" "mytab.addColumn(\"string\", \"b\", \"b\");\n" "mytab.addColumn(\"boolean\", \"c\", \"c\");\n" "mytab.addRows(3);\n" "mytab.setCell(0, 0, 1);\n" "mytab.setCell(0, 2, null, null, {\"null_cp\":\"null_v\"});\n" "mytab.setRowProperties(0, {\"row_cp\":\"row_v\"});\n" "mytab.setCell(1, 1, \"z\", null, {\"cell_cp\":\"cell_v\"});\n" "mytab.setCell(1, 2, true);\n" "mytab.setCell(2, 0, 3);\n" "mytab.setRowProperties(2, {\"row_cp2\":\"row_v2\"});\n") table = DataTable([("a", "number", "A", { "col_cp": "col_v" }), "b", ("c", "boolean")], custom_properties={"global_cp": "global_v"}) table.AppendData([[1, None, (None, None, { "null_cp": "null_v" })]], custom_properties={"row_cp": "row_v"}) table.AppendData([[None, ("z", None, { "cell_cp": "cell_v" }), True], [3]]) table.SetRowsCustomProperties(2, {"row_cp2": "row_v2"}) self.assertEqual(json.dumps(json_obj, separators=(",", ":")), table.ToJSon()) self.assertEqual(jscode, table.ToJSCode("mytab"))