def testSerialization(self):
   foo_fighters = self.Foo('1', 2)
   json_dict = common_util.SerializeAttributesToJsonDict(
       {}, foo_fighters, ['foo_fighters', 'whisky_bar'])
   self.assertDictEqual({'foo_fighters': '1', 'whisky_bar': 2}, json_dict)
   # Partial update
   json_dict = common_util.SerializeAttributesToJsonDict(
       {'baz': 42}, foo_fighters, ['whisky_bar'])
   self.assertDictEqual({'baz': 42, 'whisky_bar': 2}, json_dict)
   # Non-existing attribute.
   with self.assertRaises(AttributeError):
     json_dict = common_util.SerializeAttributesToJsonDict(
         {}, foo_fighters, ['foo_fighters', 'whisky_bar', 'baz'])
示例#2
0
 def ToJsonDict(self):
   return common_util.SerializeAttributesToJsonDict(
       super(_IndexedNode, self).ToJsonDict(), self, ['index'])
示例#3
0
 def ToJsonDict(self):
     """Returns a dict representing this instance."""
     result = {'graph': self.graph.ToJsonDict()}
     return common_util.SerializeAttributesToJsonDict(
         result, self, ['postload_msec'])
示例#4
0
 def ToJsonDict(self):
     result = super(RequestNode, self).ToJsonDict()
     return common_util.SerializeAttributesToJsonDict(
         result, self, self._ATTRS)
示例#5
0
 def ToJsonDict(self):
     return common_util.SerializeAttributesToJsonDict({}, self, self._ATTRS)
示例#6
0
 def ToJsonDict(self):
     return common_util.SerializeAttributesToJsonDict(
         {}, self, ['from_node', 'to_node', 'cost'])
示例#7
0
 def ToJsonDict(self):
     return common_util.SerializeAttributesToJsonDict({}, self, ['cost'])
示例#8
0
 def ToJsonDict(self):
     result = {}
     return common_util.SerializeAttributesToJsonDict(
         result, self, ['reason', 'cost', 'is_timing'])