Expanded type coverage to benchmarks, samples and tests. (#566)
* Renamed json samples to fix duplicate module name. Signed-off-by: dblock <dblock@amazon.com> * Enabled mypy on all source files. Signed-off-by: dblock <dblock@amazon.com> * Added missing types. Signed-off-by: dblock <dblock@amazon.com> * Added CHANGELOG. Signed-off-by: dblock <dblock@amazon.com> * Move type: ignore to fix untyped decorator makes function untyped. Signed-off-by: dblock <dblock@amazon.com> * Fix nox -rs lint-3.7. Signed-off-by: dblock <dblock@amazon.com> * Fixed incorrect import. Signed-off-by: dblock <dblock@amazon.com> * Fix broken test. Signed-off-by: dblock <dblock@amazon.com> * Fixed TestBulk::test_bulk_works_with_bytestring_body. Signed-off-by: dblock <dblock@amazon.com> --------- Signed-off-by: dblock <dblock@amazon.com>
This commit is contained in:
committed by
GitHub
parent
dcb79cc322
commit
56c96d7c4f
@@ -12,6 +12,7 @@
|
||||
|
||||
import asyncio
|
||||
import uuid
|
||||
from typing import Any
|
||||
|
||||
from opensearchpy import AsyncHttpConnection, AsyncOpenSearch
|
||||
|
||||
@@ -22,7 +23,7 @@ index_name = "test-index-async"
|
||||
item_count = 100
|
||||
|
||||
|
||||
async def index_records(client, item_count) -> None:
|
||||
async def index_records(client: Any, item_count: int) -> None:
|
||||
await asyncio.gather(
|
||||
*[
|
||||
client.index(
|
||||
@@ -39,7 +40,7 @@ async def index_records(client, item_count) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_async(client_count=1, item_count=1):
|
||||
async def test_async(client_count: int = 1, item_count: int = 1) -> None:
|
||||
clients = []
|
||||
for i in range(client_count):
|
||||
clients.append(
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
import logging
|
||||
import sys
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
from thread_with_return_value import ThreadWithReturnValue
|
||||
|
||||
@@ -36,8 +37,8 @@ handler.setFormatter(formatter)
|
||||
root.addHandler(handler)
|
||||
|
||||
|
||||
def get_info(client, request_count):
|
||||
tt = 0
|
||||
def get_info(client: Any, request_count: int) -> float:
|
||||
tt: float = 0
|
||||
for n in range(request_count):
|
||||
start = time.time() * 1000
|
||||
client.info()
|
||||
@@ -46,7 +47,7 @@ def get_info(client, request_count):
|
||||
return tt
|
||||
|
||||
|
||||
def test(thread_count=1, request_count=1, client_count=1):
|
||||
def test(thread_count: int = 1, request_count: int = 1, client_count: int = 1) -> None:
|
||||
clients = []
|
||||
for i in range(client_count):
|
||||
clients.append(
|
||||
|
||||
@@ -15,6 +15,7 @@ import logging
|
||||
import sys
|
||||
import time
|
||||
import uuid
|
||||
from typing import Any
|
||||
|
||||
from thread_with_return_value import ThreadWithReturnValue
|
||||
|
||||
@@ -37,10 +38,10 @@ handler.setFormatter(formatter)
|
||||
root.addHandler(handler)
|
||||
|
||||
|
||||
def index_records(client, item_count):
|
||||
def index_records(client: Any, item_count: int) -> Any:
|
||||
tt = 0
|
||||
for n in range(10):
|
||||
data = []
|
||||
data: Any = []
|
||||
for i in range(item_count):
|
||||
data.append(
|
||||
json.dumps({"index": {"_index": index_name, "_id": str(uuid.uuid4())}})
|
||||
@@ -63,7 +64,7 @@ def index_records(client, item_count):
|
||||
return tt
|
||||
|
||||
|
||||
def test(thread_count=1, item_count=1, client_count=1):
|
||||
def test(thread_count: int = 1, item_count: int = 1, client_count: int = 1) -> None:
|
||||
clients = []
|
||||
for i in range(client_count):
|
||||
clients.append(
|
||||
|
||||
@@ -10,19 +10,30 @@
|
||||
|
||||
|
||||
from threading import Thread
|
||||
from typing import Any, Optional
|
||||
|
||||
|
||||
class ThreadWithReturnValue(Thread):
|
||||
_target: Any
|
||||
_args: Any
|
||||
_kwargs: Any
|
||||
|
||||
def __init__(
|
||||
self, group=None, target=None, name=None, args=(), kwargs={}, Verbose=None
|
||||
):
|
||||
self,
|
||||
group: Any = None,
|
||||
target: Any = None,
|
||||
name: Optional[str] = None,
|
||||
args: Any = (),
|
||||
kwargs: Any = {},
|
||||
Verbose: Optional[bool] = None,
|
||||
) -> None:
|
||||
Thread.__init__(self, group, target, name, args, kwargs)
|
||||
self._return = None
|
||||
|
||||
def run(self):
|
||||
def run(self) -> None:
|
||||
if self._target is not None:
|
||||
self._return = self._target(*self._args, **self._kwargs)
|
||||
|
||||
def join(self, *args):
|
||||
def join(self, *args: Any) -> Any:
|
||||
Thread.join(self, *args)
|
||||
return self._return
|
||||
|
||||
Reference in New Issue
Block a user