def testEncoderDefault(self): enc = twc.encoder enc.encode("") res = enc.default(twr.JSSymbol("X")) self.assert_(res.startswith("TW2Encoder_unescape_")) try: res = enc.default(None) self.assert_(False) except TypeError, te: self.assert_(str(te).endswith("is not JSON serializable"))
class MokshaTW2CPUUsageWidget(LiveAreaChartWidget): name = 'CPU Usage (with tw2.jit)' topic = 'moksha_jit_cpu_metrics' width='400px' height='300px' offset = 0 showAggregates = False showLabels = False animate = False type = 'stacked' Tips = { 'enable': True, 'onShow' : res.JSSymbol(src=""" (function(tip, elem) { tip.innerHTML = "<b>" + elem.name + "</b>: " + elem.value; })""") } container_options = { 'icon': 'chart.png', 'height' : 325 } data = {'labels': [], 'values': []}
def testUnEscapeMarked(self): enc = twc.encoder data = dict(foo=twr.JSSymbol("foo"), bar=twr.JSSymbol("bar")) res = enc.unescape_marked(enc.encode(data)) self.assert_("foo" in res, res) self.assert_("bar" in res, res)
def testJSSymbol(self): """ should set the src attribute """ s = twr.JSSymbol("source") self.assert_(s.src == "source")