Spoof out some tests

This commit is contained in:
Luke Murphy 2020-08-05 07:15:47 +02:00
parent bd038c3ca0
commit f466714406
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 53 additions and 3 deletions

View File

@ -1,8 +1,12 @@
import pytest
from simple_message_channels import SimpleMessageChannel as SMC
@pytest.fixture
def smc():
from simple_message_channels import SimpleMessageChannel
def smc1():
return SMC()
return SimpleMessageChannel()
@pytest.fixture
def smc2():
return SMC()

View File

@ -0,0 +1,46 @@
def test_smc_send(smc1):
assert smc1.send(0, 1, b"foo") == b"\x04\x01foo"
def test_smc_recv(smc1, smc2):
payload = smc1.send(0, 1, b"foo")
smc2.recv(payload)
assert len(smc2.messages) == 1
assert smc2.messages[0] == [(0, 1, b"foo")]
def test_smc_recv_multiple(smc1, smc2):
payload = smc1.send_batch([(0, 1, b"foo"), (0, 1, b"bar"), (0, 1, b"baz")])
smc2.recv(payload)
assert len(smc2.messages) == 3
assert smc2.messages[0] == [(0, 1, b"foo"), (0, 1, b"bar"), (0, 1, b"baz")]
def test_smc_recv_empty(smc1, smc2):
payload = smc1.send(0, 1, b"")
smc2.recv(payload)
assert len(smc2.messages) == 1
assert smc2.messages[0] == [(0, 1, b"")]
def test_smc_recv_chunked(smc1, smc2):
payload = smc1.send(0, 1, b"foo")
for idx in range(0, len(payload)):
smc2.recv(payload[idx, idx + 1])
assert len(smc2.messages) == 1
assert smc2.messages[0] == [(0, 1, b"foo")]
def test_smc_recv_chunked_multiple(smc1, smc2):
payload = smc1.send_batch([(0, 1, b"foo"), (0, 1, b"bar"), (0, 1, b"baz")])
for idx in range(0, len(payload)):
smc2.recv(payload[idx, idx + 1])
assert len(smc2.messages) == 3
assert smc2.messages[0] == [(0, 1, b"foo"), (0, 1, b"bar"), (0, 1, b"baz")]