Put test into test_features, simplify to call parse directly

This commit is contained in:
Danny Weinberg
2020-06-04 13:42:07 -07:00
parent 67422db6b9
commit a914306f33
3 changed files with 16 additions and 41 deletions

View File

@@ -1,6 +1,6 @@
import betterproto
from dataclasses import dataclass
from typing import Optional
from typing import Optional, List, Dict
def test_has_field():
@@ -32,6 +32,21 @@ def test_has_field():
foo.bar = Bar()
assert betterproto.serialized_on_wire(foo.bar) == False
@dataclass
class WithCollections(betterproto.Message):
test_list: List[str] = betterproto.string_field(1)
test_map: Dict[str, str] = betterproto.map_field(2, betterproto.TYPE_STRING, betterproto.TYPE_STRING)
# Unset with empty collections
with_collections_empty = WithCollections().parse(bytes(WithCollections()))
assert betterproto.serialized_on_wire(with_collections_empty) == False
# Set with non-empty collections
with_collections_list = WithCollections().parse(bytes(WithCollections(test_list=['a', 'b', 'c'])))
assert betterproto.serialized_on_wire(with_collections_list) == True
with_collections_map = WithCollections().parse(bytes(WithCollections(test_map={'a': 'b', 'c': 'd'})))
assert betterproto.serialized_on_wire(with_collections_map) == True
def test_class_init():
@dataclass