10000 Modernize tests by akx · Pull Request #180 · maxmind/GeoIP2-python · GitHub
[go: up one dir, main page]

Skip to content

Modernize tests #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
Test client context manager/closing
  • Loading branch information
akx committed Aug 29, 2024
commit 5dbae3f873ca169fb02e70826c56e12bcdc8b8cf
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
Loading
0