Skip to content

Commit

Permalink
[uniffi] Use Python 3.9 type hints in tests (#106)
Browse files Browse the repository at this point in the history
I believe this is the recommended way for modern Python code. Since
this only affects the tests, I hope it’s okay to require a recent
Python.

This also fixes a few signatures in PythonGroupStateStorage to use the
same signature as in the parent class.
  • Loading branch information
mgeisler authored Mar 13, 2024
1 parent f23c6e4 commit c2aeb93
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions mls-rs-uniffi/tests/simple_scenario_sync.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
from dataclasses import dataclass, field

from mls_rs_uniffi import CipherSuite, generate_signature_keypair, Client, \
GroupStateStorage, ClientConfig, ProtocolVersion

@dataclass
class EpochData:
id: int
data: bytes
GroupStateStorage, GroupState, EpochRecord, ClientConfig, ProtocolVersion

@dataclass
class GroupStateData:
state: bytes
epoch_data: list[EpochData] = field(default_factory=list)
epoch_data: list[EpochRecord] = field(default_factory=list)

class PythonGroupStateStorage(GroupStateStorage):
def __init__(self):
self.groups = {}
self.groups: dict[str, GroupStateData] = {}

def state(self, group_id: "bytes"):
def state(self, group_id: bytes):
group = self.groups.get(group_id.hex())

if group == None:
return None

return group.state

def epoch(self, group_id: "bytes",epoch_id: "int"):
def epoch(self, group_id: bytes, epoch_id: int):
group = self.groups[group_id.hex()]

if group == None:
return None

for epoch in group.epoch_data:
if epoch.id == epoch_id:
return epoch

return None

def write(self, state: "GroupState",epoch_inserts: "typing.List[EpochRecord]",epoch_updates: "typing.List[EpochRecord]"):
def write(self, state: GroupState, epoch_inserts: list[EpochRecord], epoch_updates: list[EpochRecord]):
if self.groups.get(state.id.hex()) == None:
self.groups[state.id.hex()] = GroupStateData(state.data)

Expand All @@ -50,8 +45,8 @@ def write(self, state: "GroupState",epoch_inserts: "typing.List[EpochRecord]",ep
for i in range(len(group.epoch_data)):
if group.epoch_data[i].id == update.id:
group.epoch_data[i] = update
def max_epoch_id(self, group_id: "bytes"):

def max_epoch_id(self, group_id: bytes):
group = self.groups.get(group_id.hex())

if group == None:
Expand Down

0 comments on commit c2aeb93

Please sign in to comment.