Skip to content

Commit

Permalink
Test client context manager/closing
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Aug 29, 2024
1 parent e407bd6 commit 5dbae3f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/webservice_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import copy
import ipaddress
from contextlib import ExitStack, AsyncExitStack
from typing import cast, Dict
import unittest
from pytest_httpserver import HeaderValueMatcher
Expand Down Expand Up @@ -333,22 +334,30 @@ def test_missing_constructor_args(self):

class TestClient(TestBaseClient):
def setUp(self):
self.stack = ExitStack()
self.client_class = Client
self.client = Client(42, "abcdef123456")
self.client._base_uri = self.httpserver.url_for("/geoip/v2.1")
self.stack.enter_context(self.client)

def tearDown(self):
self.stack.close()

def run_client(self, v):
return v


class TestAsyncClient(TestBaseClient):
def setUp(self):
self.stack = AsyncExitStack()
self._loop = asyncio.new_event_loop()
self.client_class = AsyncClient
self.client = AsyncClient(42, "abcdef123456")
self.client._base_uri = self.httpserver.url_for("/geoip/v2.1")
self._loop.run_until_complete(self.stack.enter_async_context(self.client))

def tearDown(self):
self._loop.run_until_complete(self.stack.aclose())
self._loop.run_until_complete(self.client.close())
self._loop.close()

Expand Down

0 comments on commit 5dbae3f

Please sign in to comment.