Add __init__ setup, pytest-trio and split up tests
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
1fb81002d8
commit
eb03ff96ad
@ -1,5 +1,6 @@
|
|||||||
[tool:pytest]
|
[tool:pytest]
|
||||||
testpaths = test
|
testpaths = test
|
||||||
|
trio_mode = true
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
max-line-length = 80
|
max-line-length = 80
|
||||||
|
@ -2,10 +2,37 @@
|
|||||||
|
|
||||||
__all__ = ["SimpleMessageChannel"]
|
__all__ = ["SimpleMessageChannel"]
|
||||||
|
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
import attr
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(auto_attribs=True)
|
||||||
class SimpleMessageChannel:
|
class SimpleMessageChannel:
|
||||||
"""A simple message channel."""
|
"""A simple message channel."""
|
||||||
|
|
||||||
|
message: Optional[bytes] = None
|
||||||
|
ptr: int = 0
|
||||||
|
varint: int = 0
|
||||||
|
factor: int = 1
|
||||||
|
length: int = 0
|
||||||
|
header: int = 0
|
||||||
|
state: int = 0
|
||||||
|
consumed: int = 0
|
||||||
|
max_size: int = 8 * 1024 * 1024
|
||||||
|
types: List = attr.Factory(list)
|
||||||
|
|
||||||
|
receiving: bool = False
|
||||||
|
destroyed: bool = False
|
||||||
|
error: Optional[Exception] = None
|
||||||
|
|
||||||
|
# TODO(decentral1se): need to lookup type of what is being passed in
|
||||||
|
# context: ???
|
||||||
|
|
||||||
|
# TODO(decentral1se): allow to override instead of callback interface!?
|
||||||
|
# onmissing: ???
|
||||||
|
# onmessage: ???
|
||||||
|
|
||||||
async def send(self, channel: int, type: int, message: bytes) -> bytes:
|
async def send(self, channel: int, type: int, message: bytes) -> bytes:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
async def test_send_recv(smc):
|
async def test_send_produces_bytes(smc):
|
||||||
channel, type, message = 0, 0, b"abc"
|
channel, type, message = 0, 0, b"abc"
|
||||||
|
|
||||||
payload = await smc.send(channel, type, message)
|
payload = await smc.send(channel, type, message)
|
||||||
assert isinstance(payload, bytes)
|
assert isinstance(payload, bytes)
|
||||||
|
|
||||||
async with smc.recv(payload) as response:
|
|
||||||
assert response.channel == channel
|
# async def test_recv_context_manager(smc):
|
||||||
assert response.type == type
|
# channel, type, message = 0, 0, b"abc"
|
||||||
assert response.message == message
|
|
||||||
|
# payload = await smc.send(channel, type, message)
|
||||||
|
# assert isinstance(payload, bytes)
|
||||||
|
|
||||||
|
# async with smc.recv(payload) as response:
|
||||||
|
# assert response.channel == channel
|
||||||
|
# assert response.type == type
|
||||||
|
# assert response.message == message
|
||||||
|
1
tox.ini
1
tox.ini
@ -13,6 +13,7 @@ deps =
|
|||||||
pytest
|
pytest
|
||||||
pytest-cov
|
pytest-cov
|
||||||
pytest-mock
|
pytest-mock
|
||||||
|
pytest-trio
|
||||||
commands = pytest test/ --cov={toxinidir}/simple_message_channels/ --no-cov-on-fail {posargs}
|
commands = pytest test/ --cov={toxinidir}/simple_message_channels/ --no-cov-on-fail {posargs}
|
||||||
|
|
||||||
[testenv:lint]
|
[testenv:lint]
|
||||||
|
Loading…
Reference in New Issue
Block a user