Skip to content

Commit

Permalink
---Improves #21. Closes #19---
Browse files Browse the repository at this point in the history
* Changed some of the type annotations in the `warp` module.
* Implemented more unit-tests for the `warp` module.
  • Loading branch information
DobromirM committed Nov 5, 2019
1 parent d0f494a commit ebab861
Show file tree
Hide file tree
Showing 2 changed files with 425 additions and 4 deletions.
9 changes: 5 additions & 4 deletions swim/warp/warp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math
from abc import ABC, abstractmethod
from typing import Optional

from swim.recon.recon import Recon
from swim.structures.structs import Item, Record, Attr, Value, Num, RecordMap
Expand Down Expand Up @@ -169,7 +170,7 @@ def create_envelope_from(self, node_uri: str, lane_uri: str, prio: float, rate:
"""
...

def mold(self, envelope: 'LinkAddressedEnvelope') -> 'Value':
def mold(self, envelope: Optional['LinkAddressedEnvelope']) -> 'Value':

if envelope is not None:

Expand All @@ -188,7 +189,7 @@ def mold(self, envelope: 'LinkAddressedEnvelope') -> 'Value':
else:
return Item.extant()

def cast(self, value: RecordMap) -> 'Envelope':
def cast(self, value: RecordMap) -> Optional['Envelope']:
headers = value.get_headers(self.tag)
node_uri = None
lane_uri = None
Expand Down Expand Up @@ -227,15 +228,15 @@ def create_envelope_from(self, node_uri, lane_uri, body) -> 'Envelope':
"""
...

def mold(self, envelope: 'LaneAddressedEnvelope') -> 'Value':
def mold(self, envelope: Optional['LaneAddressedEnvelope']) -> 'Value':

if envelope is not None:
headers = Record.create().add_slot('node', envelope.node_uri).add_slot('lane', envelope.lane_uri)
return Attr.create_attr(self.tag, headers).concat(envelope.body)
else:
return Item.extant()

def cast(self, item) -> 'Envelope':
def cast(self, item: 'RecordMap') -> Optional['Envelope']:
value = item
headers = value.get_headers(self.tag)
node_uri = None
Expand Down
Loading

0 comments on commit ebab861

Please sign in to comment.