def setUp(self): """Set up the necessary objects.""" self._json_string = ( u'{"foo": "bar", "__COUNTERS__": {"foobar": {"stuff": 1245}}, ' u'"foo2": "randombar"}') self._collection_information_object = collection.CollectionInformation( ) self._collection_information_object.AddCounter(u'foobar') self._collection_information_object.IncrementCounter(u'foobar', u'stuff', value=1245) self._collection_information_object.SetValue(u'foo', u'bar') self._collection_information_object.SetValue(u'foo2', u'randombar') self._serializer = json_serializer.JsonCollectionInformationObjectSerializer
def ReadSerializedObject(cls, proto): """Reads a collection information object from serialized form.""" collection_information_object = collection.CollectionInformation() for attribute in proto.attributes: key = attribute.key if key == collection_information_object.RESERVED_COUNTER_KEYWORD: _, counter_dict = ProtobufEventAttributeSerializer.ReadSerializedObject( attribute) for identifier, value_dict in iter(counter_dict.items()): collection_information_object.AddCounterDict(identifier, value_dict) else: _, value = ProtobufEventAttributeSerializer.ReadSerializedObject( attribute) collection_information_object.SetValue(key, value) return collection_information_object
def setUp(self): """Makes preparations before running an individual test.""" self._collection_object = collection.CollectionInformation() self._collection_object.AddCounter(u'foobar') self._collection_object.IncrementCounter( u'foobar', u'random', value=532) self._collection_object.IncrementCounter( u'foobar', u'hat', value=12) self._collection_object.SetValue(u'foo', u'bar') self._collection_object.SetValue(u'bar', u'vitleysa') self._proto_string = ( b'\n\n\n\x03foo\x12\x03bar\n\x0f\n\x03bar\x12\x08vitleysa\n2\n\x0c' b'__COUNTERS__*"\n \n\x06foobar*\x16\n\x0b\n\x06random' b'\x18\x94\x04\n\x07\n\x03hat\x18\x0c') # Rename the protobuf serializer import in order to fit in a single line. module = protobuf_serializer self._serializer = module.ProtobufCollectionInformationObjectSerializer
def ReadSerialized(cls, serialized): """Reads a path filter from serialized form. Args: serialized: an object containing the serialized form. Returns: A collection information object (instance of CollectionInformation). """ json_dict = json.loads(serialized) collection_information_object = collection.CollectionInformation() for key, value in iter(json_dict.items()): if key == collection_information_object.RESERVED_COUNTER_KEYWORD: for identifier, value_dict in iter(value.items()): collection_information_object.AddCounterDict(identifier, value_dict) else: collection_information_object.SetValue(key, value) return collection_information_object
def setUp(self): """Set up the necessary objects.""" self._json_dict = { u'__COUNTERS__': { u'foobar': { u'stuff': 1245 } }, u'foo': u'bar', u'foo2': u'randombar' } self._collection_information_object = collection.CollectionInformation() self._collection_information_object.AddCounter(u'foobar') self._collection_information_object.IncrementCounter( u'foobar', u'stuff', value=1245) self._collection_information_object.SetValue(u'foo', u'bar') self._collection_information_object.SetValue(u'foo2', u'randombar') self._serializer = json_serializer.JSONCollectionInformationObjectSerializer
def setUp(self): """Makes preparations before running an individual test.""" self._json_dict = { u'__COUNTERS__': { u'foobar': { u'stuff': 1245 } }, u'foo': u'bar', u'foo2': u'randombar' } self._collection_information_object = collection.CollectionInformation() self._collection_information_object.AddCounter(u'foobar') self._collection_information_object.IncrementCounter( u'foobar', u'stuff', value=1245) self._collection_information_object.SetValue(u'foo', u'bar') self._collection_information_object.SetValue(u'foo2', u'randombar') self._serializer = json_serializer.JSONCollectionInformationObjectSerializer