コード例 #1
0
 def test_TryMerge_mutable_key_path_with_skip_data():
     entity = entity_module.EntityProto()
     d = _get_decoder(
         b"\x6a\x0f\x72\x0d\x02\x01\x01\x0b\x12\x01\x44\x18\x01\x22\x01"
         b"\x45\x0c")
     entity.TryMerge(d)
     assert entity.key().has_path()
コード例 #2
0
 def test_TryMerge_with_skip_data():
     entity = entity_module.EntityProto()
     d = _get_decoder(
         b"\x02\x01\x01\x7a\x08\x1a\x01\x46\x2a\x03\x1a\x01" b"\x47"
     )
     entity.TryMerge(d)
     assert entity.entity_props()["F"].decode() == "G"
コード例 #3
0
 def test_TryMerge_property_reference_skip_data():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x72\x0d\x1a\x01\x46\x2a\x08\x63\x02\x01\x01\x6a"
                      b"\x01\x41\x64")
     entity.TryMerge(d)
     assert entity.entity_props()["F"].has_app()
     assert entity.entity_props()["F"].app().decode() == "A"
コード例 #4
0
 def test_TryMerge_property_reference_database_id():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x72\x0b\x1a\x01\x46\x2a\x06\x63\xba\x01\x01\x41"
                      b"\x64")
     entity.TryMerge(d)
     assert entity.entity_props()["F"].has_database_id()
     assert entity.entity_props()["F"].database_id().decode() == "A"
コード例 #5
0
 def test_TryMerge_property_double():
     entity = entity_module.EntityProto()
     d = _get_decoder(
         b"\x72\x0e\x1a\x01\x46\x2a\x09\x21\x00\x00\x00\x00\x00\x00E@"
     )
     entity.TryMerge(d)
     assert entity.entity_props()["F"] == 42.0
コード例 #6
0
 def test_TryMerge_property_reference_pathelement_truncated():
     entity = entity_module.EntityProto()
     d = _get_decoder(
         b"\x72\x14\x1a\x01\x46\x2a\x0f\x63\x73\x7a\x01\x42"
         b"\x8a\x01\x01\x43\x80\x01\x01\x00\x74\x64"
     )
     with pytest.raises(pb_module.ProtocolBufferDecodeError):
         entity.TryMerge(d)
コード例 #7
0
 def test_TryMerge_property_meaning():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x72\x02\x08\x0e")
     entity.TryMerge(d)
     assert entity.property_list()[0].has_meaning()
     meaning = entity.property_list()[0].meaning()
     assert meaning == 14
     assert entity.property_list()[0].Meaning_Name(meaning) == "BLOB"
コード例 #8
0
 def test_TryMerge_property_point_skip_data():
     entity = entity_module.EntityProto()
     d = _get_decoder(
         b"\x72\x1c\x1a\x01\x46\x2a\x17\x2b\x31\x00\x00\x00\x00\x00\x00E@"
         b"\x39\x00\x00\x00\x00\x00\x00E@\x02\x01\x01\x2c")
     entity.TryMerge(d)
     point = entity.entity_props()["F"]
     assert point.has_x()
     assert point.x() == 42.0
     assert point.has_y()
     assert point.y() == 42.0
コード例 #9
0
 def test_TryMerge_property_reference_pathelement_skip_data():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x72\x16\x1a\x01\x46\x2a\x11\x63\x73\x7a\x01\x42"
                      b"\x8a\x01\x01\x43\x80\x01\x01\x02\x01\x01\x74\x64")
     entity.TryMerge(d)
     element = entity.entity_props()["F"].pathelement_list()[0]
     assert element.has_type()
     assert element.type().decode() == "B"
     assert element.has_id()
     assert element.id() == 1
     assert element.has_name()
     assert element.name().decode() == "C"
コード例 #10
0
 def test_TryMerge_mutable_key_path_not_bytes():
     entity = entity_module.EntityProto()
     d = _get_decoder(
         b"\x6a\x0c\x72\x0a\x0b\x12\x01\x44\x18\x01\x22\x01\x45\x0c")
     entity.TryMerge(d)
     assert entity.has_key()  # noqa: W601
     assert entity.key().has_path()
     element = entity.key().path.element_list()[0]
     assert element.has_type()
     assert element.type == "D"
     # Not quite sure how this type could be set from a decoder string
     element.set_type(u"E")
     assert element.type == "E"
コード例 #11
0
 def test_TryMerge_mutable_key_path():
     entity = entity_module.EntityProto()
     d = _get_decoder(
         b"\x6a\x0c\x72\x0a\x0b\x12\x01\x44\x18\x01\x22\x01\x45\x0c")
     entity.TryMerge(d)
     assert entity.has_key()  # noqa: W601
     assert entity.key().has_path()
     element = entity.key().path().element_list()[0]
     assert element.has_type()
     assert element.type().decode() == "D"
     assert element.has_id()
     assert element.id() == 1
     assert element.has_name()
     assert element.name().decode() == "E"
コード例 #12
0
def read_records(fh):
    """Yield a pair of (key, properties) for each entity read from the file.

    The file is in LevelDB format, with each record a datastore entity proto.
    String values are always bytes, with unicode in UTF-8 encoding.
    """
    for rec in records.RecordsReader(fh):
        pb = entity_pb.EntityProto()
        pb.MergePartialFromString(rec)
        key = pb.key()

        # These are _properties_, which is different to the generic entity
        # reference type where the same things are explicit methods.
        entity_key = {
            'path': key_path_as_tuples(key.path),
            'name_space': key.name_space,
            'database_id': key.database_id,
            'app': key.app,
        }
        props = get_entity_properties(pb)

        yield entity_key, props
コード例 #13
0
 def test_TryMerge_set_kind_uri():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x2a\x01\x41")
     entity.TryMerge(d)
     assert entity.has_kind_uri()
     assert entity.kind_uri().decode() == "A"
コード例 #14
0
 def test_TryMerge_mutable_key_app():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x6a\x03\x6a\x01\x41")
     entity.TryMerge(d)
     assert entity.key().has_app()
     assert entity.key().app().decode() == "A"
コード例 #15
0
 def test_TryMerge_decode_error():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x00")
     with pytest.raises(pb_module.ProtocolBufferDecodeError):
         entity.TryMerge(d)
コード例 #16
0
 def test__get_property_value_empty_property():
     entity = entity_module.EntityProto()
     prop = entity_module.PropertyValue()
     assert entity._get_property_value(prop) is None
コード例 #17
0
 def test_TryMerge_raw_property_string():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x7a\x08\x1a\x01\x46\x2a\x03\x1a\x01\x47")
     entity.TryMerge(d)
     assert entity.entity_props()["F"].decode() == "G"
コード例 #18
0
 def test_TryMerge_mutable_key_path_element_truncated():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x6a\x04\x72\x02\x0b\x00")
     with pytest.raises(pb_module.ProtocolBufferDecodeError):
         entity.TryMerge(d)
コード例 #19
0
 def test_TryMerge_property_value_skip_data():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x72\x0a\x1a\x01\x46\x2a\x05\x02\x01\x01\x10\x01")
     entity.TryMerge(d)
     assert entity.entity_props()["F"] == 1
コード例 #20
0
 def test_TryMerge_property_skip_data():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x72\x05\x38\x01\x02\x01\x01")
     entity.TryMerge(d)
     assert entity.property_list()[0].has_computed()
コード例 #21
0
 def test_TryMerge_property_name():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x72\x03\x1a\x01\x41")
     entity.TryMerge(d)
     assert entity.property_list()[0].has_name()
     assert entity.property_list()[0].name().decode() == "A"
コード例 #22
0
 def test_TryMerge_set_kind():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x20\x2a")
     entity.TryMerge(d)
     assert entity.has_kind()
     assert entity.kind() == 42
コード例 #23
0
 def test_constructor():
     entity = entity_module.EntityProto()
     assert entity.property_ == []
コード例 #24
0
 def test_TryMerge_property_boolean():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x72\x07\x1a\x01\x46\x2a\x02\x10\x01")
     entity.TryMerge(d)
     assert entity.entity_props()["F"]
コード例 #25
0
 def test_TryMerge_property_multiple():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x72\x02\x20\x01")
     entity.TryMerge(d)
     assert entity.property_list()[0].has_multiple()
     assert entity.property_list()[0].multiple()
コード例 #26
0
 def test_TryMerge_mutable_key_namespace():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x6a\x04\xa2\x01\x01\x42")
     entity.TryMerge(d)
     assert entity.key().has_name_space()
     assert entity.key().name_space().decode() == "B"
コード例 #27
0
 def test_TryMerge_property_value_truncated():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x72\x03\x2a\x01\x00")
     with pytest.raises(pb_module.ProtocolBufferDecodeError):
         entity.TryMerge(d)
コード例 #28
0
 def test_TryMerge_mutable_key_database():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x6a\x04\xba\x01\x01\x43")
     entity.TryMerge(d)
     assert entity.key().has_database_id()
     assert entity.key().database_id().decode() == "C"
コード例 #29
0
 def test_TryMerge_property_stashed():
     entity = entity_module.EntityProto()
     d = _get_decoder(b"\x72\x02\x30\x02")
     entity.TryMerge(d)
     assert entity.property_list()[0].has_stashed()
     assert entity.property_list()[0].stashed() == 2