Skip to content

Commit

Permalink
Emulate the behavior from 037257e in mocked telnet client
Browse files Browse the repository at this point in the history
  • Loading branch information
nocarryr committed Feb 24, 2017
1 parent 037257e commit aa87287
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def __init__(self, host=None, port=None, timeout=None, loop=None):
self.loop = loop
self.rx_bfr = b''
self.tx_bfr = b''
self.read_ready_event = asyncio.Event()
self.tx_lock = asyncio.Lock()
@property
def port(self):
Expand All @@ -125,10 +126,13 @@ async def open(self, host, port=0, timeout=0, loop=None):
loop = self.loop = asyncio.get_event_loop()
async with self.tx_lock:
self.tx_bfr = PREAMBLES[self.preamble]
self.read_ready_event.set()
def close(self):
pass
self.read_ready_event.set()
async def close_async(self):
pass
self.close()
async def wait_for_data(self):
await self.read_ready_event.wait()
async def write(self, bfr):
self.rx_bfr = b''.join([self.rx_bfr, bfr])
if bfr.endswith(b'\n\n'):
Expand All @@ -142,11 +146,15 @@ async def process_command(self, bfr):
else:
tx_bfr = vidhub_telnet_responses['ack']
self.tx_bfr = b''.join([self.tx_bfr, tx_bfr])
if len(self.tx_bfr):
self.read_ready_event.set()
async def read_very_eager(self):
async with self.tx_lock:
bfr = self.tx_bfr
self.tx_bfr = b''
self.read_ready_event.clear()
return bfr

monkeypatch.setattr('vidhubcontrol.aiotelnetlib._Telnet', Telnet)
monkeypatch.setattr('vidhubcontrol.backends.telnet.aiotelnetlib._Telnet', Telnet)
return Telnet
Expand Down

0 comments on commit aa87287

Please sign in to comment.