Skip to content

Commit

Permalink
---Improves #21, #23, #2---
Browse files Browse the repository at this point in the history
* Refactored main module to match the package name.
* Added unit-tests for the `recon.utils`.
* Added type-annotations for the `recon` module.
  • Loading branch information
DobromirM committed Nov 5, 2019
1 parent ebab861 commit d750587
Show file tree
Hide file tree
Showing 25 changed files with 136 additions and 31 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The **Swim System** Python implementation provides a standalone set of
frameworks for building massively real-time streaming WARP clients.
<br>
## Installation
`pip install swimai`
## Usage

## Development
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='swimai',
version='0.0.3.dev1',
version='0.1.0.dev1',
author='Dobromir Marinov',
author_email='[email protected]',
description='Standalone Python framework for building massively real-time streaming WARP clients.',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from collections import Callable
import inspect

from swim.structures.structs import Absent
from swim.warp.warp import SyncRequest, CommandMessage, Envelope
from swimai.structures.structs import Absent
from swimai.warp.warp import SyncRequest, CommandMessage, Envelope


class ValueDownlink:
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions swim/client/swim_client.py → swimai/client/swim_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from threading import Thread
import websockets

from swim.client.downlinks.value_downlink import ValueDownlink
from swim.client.downlinks.ws_connection import WSConnection
from swim.warp.warp import CommandMessage
from swimai.client.downlinks.value_downlink import ValueDownlink
from swimai.client.downlinks.ws_connection import WSConnection
from swimai.warp.warp import CommandMessage


class SwimClient:
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions swim/recon/parsers.py → swimai/recon/parsers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC

from swim.recon.utils import ReconUtils
from swim.structures.structs import ValueBuilder, Text, Bool, Attr, Value, Record, Slot, Num
from swimai.recon.utils import ReconUtils
from swimai.structures.structs import ValueBuilder, Text, Bool, Attr, Value, Record, Slot, Num


class Parser(ABC):
Expand Down
7 changes: 4 additions & 3 deletions swim/recon/recon.py → swimai/recon/recon.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from swim.recon.parsers import ReconStructureParser
from swim.recon.writers import ReconStructureWriter
from swimai.structures.structs import Value
from swimai.recon.parsers import ReconStructureParser
from swimai.recon.writers import ReconStructureWriter


class Recon:
Expand All @@ -8,7 +9,7 @@ class Recon:
structure_parser = None

@staticmethod
async def parse(recon_string):
async def parse(recon_string: str) -> 'Value':
"""
Parse a Recon message in string format and return a Swim structure object.
Expand Down
13 changes: 8 additions & 5 deletions swim/recon/utils.py → swimai/recon/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from typing import Optional


class ReconUtils:

@staticmethod
async def is_ident_start_char(char):
async def is_ident_start_char(char: (str, int)) -> bool:
"""
Check if a character is a valid first character of an identifier.
Valid start characters for identifiers: [A-Za-z_]
Expand All @@ -17,7 +20,7 @@ async def is_ident_start_char(char):
return False

@staticmethod
async def is_ident_char(char):
async def is_ident_char(char: (str, int)) -> bool:
"""
Check if a character is a valid character of an identifier.
Valid characters for identifiers: [A-Za-z_-]
Expand All @@ -32,7 +35,7 @@ async def is_ident_char(char):
return False

@staticmethod
async def is_space(char):
async def is_space(char: (str, int)) -> bool:
"""
Check if a character is a space character.
Expand All @@ -46,7 +49,7 @@ async def is_space(char):
return False

@staticmethod
async def is_digit(char):
async def is_digit(char: (str, int)) -> bool:
"""
Check if a character is a digit.
Expand All @@ -60,7 +63,7 @@ async def is_digit(char):
return False

@staticmethod
async def to_ord(char):
async def to_ord(char: (str, int)) -> Optional[int]:
"""
Convert a character to its integer representation.
Expand Down
4 changes: 2 additions & 2 deletions swim/recon/writers.py → swimai/recon/writers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod

from swim.recon.utils import ReconUtils
from swim.structures.structs import Field, Attr, Slot, Value, Record, Text, Absent, Num, Extant, Bool
from swimai.recon.utils import ReconUtils
from swimai.structures.structs import Field, Attr, Slot, Value, Record, Text, Absent, Num, Extant, Bool


class Writer(ABC):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions swim/warp/warp.py → swimai/warp/warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
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
from swimai.recon.recon import Recon
from swimai.structures.structs import Item, Record, Attr, Value, Num, RecordMap


class Envelope(ABC):
Expand Down
38 changes: 38 additions & 0 deletions test/recon/test_recon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import unittest

from aiounittest import async_test

from swimai import Recon, RecordMap


class TestRecon(unittest.TestCase):

@async_test
async def test_parse(self):
# Given
recon_string = '@sync(node: "foo/node", lane: "foo/lane")"Hello, World"'
# When
actual = await Recon.parse(recon_string)
# Then
self.assertIsInstance(actual, RecordMap)
self.assertEqual('sync', actual.tag)
self.assertEqual(2, actual.size)
self.assertEqual('foo/node', actual.get_item(0).value.get_item(0).value.value)
self.assertEqual('foo/lane', actual.get_item(0).value.get_item(1).value.value)
self.assertEqual('Hello, World', actual.get_item(1).value)

@async_test
async def test_to_string(self):
pass

def test_get_structure_writer_once(self):
pass

def test_get_structure_writer_multiple(self):
pass

def get_structure_parser_once(self):
pass

def get_structure_parser_multiple(self):
pass
66 changes: 64 additions & 2 deletions test/recon/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import unittest

from aiounittest import async_test

from swim.recon.utils import ReconUtils
from swimai.recon.utils import ReconUtils


class TestUtils(unittest.TestCase):
Expand Down Expand Up @@ -97,6 +96,15 @@ async def test_is_invalid_ident_start_char_dollar(self):
# Then
self.assertFalse(actual)

@async_test
async def test_is_invalid_ident_start_char_empty(self):
# Given
character = ''
# When
actual = await ReconUtils.is_ident_start_char(character)
# Then
self.assertFalse(actual)

@async_test
async def test_is_valid_ident_char_A(self):
# Given
Expand Down Expand Up @@ -214,6 +222,15 @@ async def test_is_invalid_ident_char_dollar(self):
# Then
self.assertFalse(actual)

@async_test
async def test_is_invalid_ident_char_empty(self):
# Given
character = ''
# When
actual = await ReconUtils.is_ident_char(character)
# Then
self.assertFalse(actual)

@async_test
async def test_is_valid_space_char_space(self):
# Given
Expand Down Expand Up @@ -250,6 +267,15 @@ async def test_is_invalid_space_char_letter(self):
# Then
self.assertFalse(actual)

@async_test
async def test_is_invalid_space_char_empty(self):
# Given
character = ''
# When
actual = await ReconUtils.is_space(character)
# Then
self.assertFalse(actual)

@async_test
async def test_is_valid_digit_char_1(self):
# Given
Expand Down Expand Up @@ -303,3 +329,39 @@ async def test_is_invalid_digit_char_underscore(self):
actual = await ReconUtils.is_digit(character)
# Then
self.assertFalse(actual)

@async_test
async def test_is_invalid_digit_char_empty(self):
# Given
character = ''
# When
actual = await ReconUtils.is_digit(character)
# Then
self.assertFalse(actual)

@async_test
async def test_to_ord_str(self):
# Given
character = 'p'
# When
actual = await ReconUtils.to_ord(character)
# Then
self.assertEqual(112, actual)

@async_test
async def test_to_ord_int(self):
# Given
character = 3
# When
actual = await ReconUtils.to_ord(character)
# Then
self.assertEqual(3, actual)

@async_test
async def test_to_ord_other(self):
# Given
character = 3.12
# When
actual = await ReconUtils.to_ord(character)
# Then
self.assertEqual(None, actual)
2 changes: 1 addition & 1 deletion test/structures/test_structs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from swim import Record, Num, Attr, Slot, Text, RecordMap, Bool, Item, Extant, Absent, Value, RecordFlags, RecordMapView, ValueBuilder
from swimai import Record, Num, Attr, Slot, Text, RecordMap, Bool, Item, Extant, Absent, Value, RecordFlags, RecordMapView, ValueBuilder
from test.test_utils import CustomString, CustomItem


Expand Down
2 changes: 1 addition & 1 deletion test/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from swim import Item
from swimai import Item


class CustomString:
Expand Down
2 changes: 1 addition & 1 deletion test/warp/test_envelope_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest

from aiounittest import async_test
from swim.warp.warp import Envelope
from swimai.warp.warp import Envelope


class TestParser(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions test/warp/test_envelope_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import unittest

from aiounittest import async_test
from swim import Num, Text, RecordMap, Attr, Slot, Extant, Bool
from swim.warp.warp import SyncRequest, SyncedResponse, EventMessage, LinkedResponse, CommandMessage
from swimai import Num, Text, RecordMap, Attr, Slot, Extant, Bool
from swimai.warp.warp import SyncRequest, SyncedResponse, EventMessage, LinkedResponse, CommandMessage


class TestWriters(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions test/warp/test_envelopes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest

from swim import Absent, Text
from swim.warp.warp import Envelope, SyncRequestForm, SyncedResponseForm, LinkedResponseForm, EventMessageForm, CommandMessageForm, SyncRequest, \
from swimai import Absent, Text
from swimai.warp.warp import Envelope, SyncRequestForm, SyncedResponseForm, LinkedResponseForm, EventMessageForm, CommandMessageForm, SyncRequest, \
SyncedResponse, LinkedResponse, CommandMessage, EventMessage


Expand Down
4 changes: 2 additions & 2 deletions test/warp/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import math
import unittest

from swim import Value, Text, RecordMap, Slot, Attr, Num
from swim.warp.warp import SyncedResponseForm, SyncedResponse, SyncRequestForm, SyncRequest, LinkedResponseForm, CommandMessageForm, \
from swimai import Value, Text, RecordMap, Slot, Attr, Num
from swimai.warp.warp import SyncedResponseForm, SyncedResponse, SyncRequestForm, SyncRequest, LinkedResponseForm, CommandMessageForm, \
EventMessageForm, LinkedResponse, CommandMessage, EventMessage


Expand Down

0 comments on commit d750587

Please sign in to comment.