Remove unused APIs
This commit is contained in:
@@ -14,8 +14,8 @@ def blob_schema():
|
||||
def test_blob_to_dict(blob_schema):
|
||||
blob_value = b"hello world"
|
||||
blob = blob_schema.BlobTest(blob=blob_value)
|
||||
blob_dict = blob.to_dict(encode_bytes_as_base64=True)
|
||||
assert base64.b64decode(blob_dict["blob"]) == blob_value
|
||||
assert blob.to_dict()["blob"] == blob_value
|
||||
blob_dict = {"blob": base64.b64encode(blob_value).decode("ascii")}
|
||||
msg = blob_schema.BlobTest.new_message()
|
||||
msg.from_dict(blob_dict)
|
||||
assert blob.blob == blob_value
|
||||
assert msg.blob == blob_value
|
||||
|
||||
@@ -143,16 +143,15 @@ def test_addressbook(addressbook):
|
||||
def test_addressbook_explicit_fields(addressbook):
|
||||
def writeAddressBook(file):
|
||||
addresses = addressbook.AddressBook.new_message()
|
||||
address_fields = addressbook.AddressBook.schema.fields
|
||||
person_fields = addressbook.Person.schema.fields
|
||||
phone_fields = addressbook.Person.PhoneNumber.schema.fields
|
||||
people = addresses._init_by_field(address_fields["people"], 2)
|
||||
people = addresses.init("people", 2)
|
||||
|
||||
alice = people[0]
|
||||
alice._set_by_field(person_fields["id"], 123)
|
||||
alice._set_by_field(person_fields["name"], "Alice")
|
||||
alice._set_by_field(person_fields["email"], "alice@example.com")
|
||||
alicePhones = alice._init_by_field(person_fields["phones"], 1)
|
||||
alicePhones = alice.init("phones", 1)
|
||||
alicePhones[0]._set_by_field(phone_fields["number"], "555-1212")
|
||||
alicePhones[0]._set_by_field(phone_fields["type"], "mobile")
|
||||
employment = alice._get_by_field(person_fields["employment"])
|
||||
@@ -162,7 +161,7 @@ def test_addressbook_explicit_fields(addressbook):
|
||||
bob._set_by_field(person_fields["id"], 456)
|
||||
bob._set_by_field(person_fields["name"], "Bob")
|
||||
bob._set_by_field(person_fields["email"], "bob@example.com")
|
||||
bobPhones = bob._init_by_field(person_fields["phones"], 2)
|
||||
bobPhones = bob.init("phones", 2)
|
||||
bobPhones[0]._set_by_field(phone_fields["number"], "555-4567")
|
||||
bobPhones[0]._set_by_field(phone_fields["type"], "home")
|
||||
bobPhones[1]._set_by_field(phone_fields["number"], "555-7654")
|
||||
@@ -443,18 +442,6 @@ def test_build(all_types):
|
||||
assert str(root) + "\n" == expectedText
|
||||
|
||||
|
||||
def test_build_first_segment_size(all_types):
|
||||
root = all_types.TestAllTypes.new_message(1)
|
||||
init_all_types(root)
|
||||
expectedText = open(os.path.join(this_dir, "all-types.txt"), "r", encoding="utf8").read()
|
||||
assert str(root) + "\n" == expectedText
|
||||
|
||||
root = all_types.TestAllTypes.new_message(1024 * 1024)
|
||||
init_all_types(root)
|
||||
expectedText = open(os.path.join(this_dir, "all-types.txt"), "r", encoding="utf8").read()
|
||||
assert str(root) + "\n" == expectedText
|
||||
|
||||
|
||||
def test_binary_read(all_types):
|
||||
f = open(os.path.join(this_dir, "all-types.binary"), "rb")
|
||||
with all_types.TestAllTypes.from_bytes(f.read()) as reader:
|
||||
|
||||
@@ -206,30 +206,24 @@ def test_set_dict_union(addressbook):
|
||||
|
||||
|
||||
def test_union_enum(all_types):
|
||||
assert all_types.UnionAllTypes.Union.UnionStructField1 == 0
|
||||
assert all_types.UnionAllTypes.Union.UnionStructField2 == 1
|
||||
|
||||
msg = all_types.UnionAllTypes.new_message(**{"unionStructField1": {"textField": "foo"}})
|
||||
assert msg.which == all_types.UnionAllTypes.Union.UnionStructField1
|
||||
assert msg.which == "unionStructField1"
|
||||
assert msg.which == 0
|
||||
|
||||
msg = all_types.UnionAllTypes.new_message(**{"unionStructField2": {"textField": "foo"}})
|
||||
assert msg.which == all_types.UnionAllTypes.Union.UnionStructField2
|
||||
assert msg.which == "unionStructField2"
|
||||
assert msg.which == 1
|
||||
|
||||
assert all_types.GroupedUnionAllTypes.Union.G1 == 0
|
||||
assert all_types.GroupedUnionAllTypes.Union.G2 == 1
|
||||
|
||||
msg = all_types.GroupedUnionAllTypes.new_message(**{"g1": {"unionStructField1": {"textField": "foo"}}})
|
||||
assert msg.which == all_types.GroupedUnionAllTypes.Union.G1
|
||||
assert msg.which() == "g1"
|
||||
|
||||
msg = all_types.GroupedUnionAllTypes.new_message(**{"g2": {"unionStructField2": {"textField": "foo"}}})
|
||||
assert msg.which == all_types.GroupedUnionAllTypes.Union.G2
|
||||
assert msg.which() == "g2"
|
||||
|
||||
msg = all_types.UnionAllTypes.new_message()
|
||||
msg.unionStructField2 = msg.init(all_types.UnionAllTypes.Union.UnionStructField2)
|
||||
msg.init("unionStructField2")
|
||||
assert msg.which() == "unionStructField2"
|
||||
|
||||
|
||||
def isstr(s):
|
||||
@@ -258,14 +252,11 @@ def test_to_dict_verbose(addressbook):
|
||||
|
||||
assert person.to_dict(verbose=True)["phones"] == []
|
||||
|
||||
if sys.version_info >= (2, 7):
|
||||
assert person.to_dict(verbose=True, ordered=True)["phones"] == []
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
assert person.to_dict()["phones"] == []
|
||||
|
||||
|
||||
def test_to_dict_ordered(addressbook):
|
||||
def test_to_dict_field_order(addressbook):
|
||||
person = addressbook.Person.new_message(
|
||||
**{
|
||||
"name": "Alice",
|
||||
@@ -276,17 +267,7 @@ def test_to_dict_ordered(addressbook):
|
||||
}
|
||||
)
|
||||
|
||||
if sys.version_info >= (2, 7):
|
||||
assert list(person.to_dict(ordered=True).keys()) == [
|
||||
"id",
|
||||
"name",
|
||||
"email",
|
||||
"phones",
|
||||
"employment",
|
||||
]
|
||||
else:
|
||||
with pytest.raises(Exception):
|
||||
person.to_dict(ordered=True)
|
||||
assert list(person.to_dict().keys()) == ["id", "name", "email", "phones", "employment"]
|
||||
|
||||
|
||||
def test_nested_list(addressbook):
|
||||
|
||||
Reference in New Issue
Block a user