Browse Source

add code to call a shutdown function to allow implementations to clean up

main
John-Mark Gurney 4 years ago
parent
commit
53c3c2a391
1 changed files with 20 additions and 1 deletions
  1. +20
    -1
      wsfwd/__init__.py

+ 20
- 1
wsfwd/__init__.py View File

@@ -3,7 +3,7 @@ import contextlib
import functools
import json
import unittest
from unittest.mock import Mock, AsyncMock
from unittest.mock import patch, Mock, AsyncMock

PIPE = object()

@@ -271,6 +271,15 @@ class WSFWDCommon:
async def __aexit__(self, exc_type, exc, tb):
self._task.cancel()

await self.shutdown()

async def shutdown(self):
'''
Called to clean up resources allocated.
'''

pass

async def _sendcmd(self, cmd):
'''
Internal function for sending the dict in cmd. This
@@ -396,6 +405,16 @@ class Test(unittest.IsolatedAsyncioTestCase):
def runFakeServer(self, func):
return asyncio.create_task(func(self.toserver.get, self.toclient.put))

@timeout(2)
@patch('wsfwd.WSFWDCommon.shutdown')
async def test_shutdown(self, shut):
# make sure that a with block
async with WSFWDCommon(None, None) as st:
pass

# calls shutdown
shut.assert_called()

@timeout(2)
async def test_authfail(self):
async def fake_server(reader, writer):


Loading…
Cancel
Save