Skip to content

Commit

Permalink
test coverage and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcoding committed Jun 26, 2022
1 parent ad415a4 commit fb03019
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 89 deletions.
4 changes: 2 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
filename = *.pyx,*.px*,*.py
filename = *.pyx, *.pxd, *.pxi, *.py, *.pyi
exclude = .eggs,*.egg,build,env*,temp,asynctnt/__init__.py
ignore = E999,E225,E227,E402,E127,E226,W503
ignore = E999,E225,E227,E402,E127,E226,W503,E704
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build debug test coverage clean annotate all
.PHONY: build debug test coverage clean annotate all style


PYTHON?=python
Expand Down
6 changes: 2 additions & 4 deletions asynctnt/_testbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,9 @@ def _check_version(version, *, min=None, max=None,
min_included=False,
max_included=False) -> Tuple[bool, Optional[str]]:
if min and (version < min or (min_included and version <= min)):
return False, \
'version mismatch - required min={} got={}'.format(min, version)
return False, f'version mismatch - required min={min} got={version}'

if max and (version > max or (max_included and version >= max)):
return False, \
'version mismatch - required max={} got={}'.format(max, version)
return False, f'version mismatch - required max={max} got={version}'

return True, None
10 changes: 5 additions & 5 deletions asynctnt/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __init__(self, *,

if hasattr(self._loop, 'create_task'):
self.__create_task = self._loop.create_task
else:
else: # pragma: nocover
self.__create_task = asyncio.ensure_future

def _set_state(self, new_state: ConnectionState):
Expand Down Expand Up @@ -200,7 +200,7 @@ def _start_reconnect(self, return_exceptions: bool = False):
self.fingerprint)
return

if self._reconnect_task:
if self._reconnect_task: # pragma: nocover
return

logger.info('%s Started reconnecting', self.fingerprint)
Expand Down Expand Up @@ -277,7 +277,7 @@ async def full_connect():

await asyncio.wait_for(connected_fut,
timeout=timeout)
except asyncio.TimeoutError:
except asyncio.TimeoutError: # pragma: nocover
tr.close()
continue # try again
except Exception:
Expand Down Expand Up @@ -575,7 +575,7 @@ def schema_id(self) -> Optional[int]:

@property
def schema(self) -> Optional[protocol.Schema]:
if self._protocol is None:
if self._protocol is None: # pragma: nocover
return None
return self._protocol.schema

Expand All @@ -597,7 +597,7 @@ def _normalize_api(self):
Api.call = Api.call16
Connection.call = Connection.call16

if self.version < (2, 10):
if self.version < (2, 10): # pragma: nocover
def stream_stub(_):
raise TarantoolError(
"streams are available only in Tarantool 2.10+"
Expand Down
20 changes: 10 additions & 10 deletions asynctnt/iproto/buffer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ from libc.string cimport memcpy
from libc.stdint cimport uint32_t, uint64_t, int64_t, uint8_t
from libc.stdio cimport printf

from decimal import Decimal
from uuid import UUID
from decimal import Decimal # pragma: nocover
from uuid import UUID # pragma: nocover

# noinspection PyUnresolvedReferences
# noinspection PyAttributeOutsideInit
Expand All @@ -35,7 +35,7 @@ cdef class WriteBuffer:
self._buf = NULL
self._size = 0

if self._view_count:
if self._view_count: # pragma: nocover
raise RuntimeError(
'Deallocating buffer with attached memoryviews')

Expand All @@ -51,7 +51,7 @@ cdef class WriteBuffer:
def __releasebuffer__(self, Py_buffer *buffer):
self._view_count -= 1

def hex(self):
def hex(self): # pragma: nocover
return ":".join("{:02x}".format(ord(<bytes> (self._buf[i])))
for i in range(self._length))

Expand All @@ -62,7 +62,7 @@ cdef class WriteBuffer:
buf._encoding = encoding
return buf

cdef inline _check_readonly(self):
cdef inline _check_readonly(self): # pragma: nocover
if self._view_count:
raise BufferError('the buffer is in read-only mode')

Expand Down Expand Up @@ -99,7 +99,7 @@ cdef class WriteBuffer:

if self._smallbuf_inuse:
new_buf = <char*> PyMem_Malloc(sizeof(char) * <size_t> new_size)
if new_buf is NULL:
if new_buf is NULL: # pragma: nocover
self._buf = NULL
self._size = 0
self._length = 0
Expand Down Expand Up @@ -150,7 +150,7 @@ cdef class WriteBuffer:
p = mp_encode_uint(p, tarantool.IPROTO_SYNC)
p = mp_encode_uint(p, sync)

if schema_id > 0:
if schema_id > 0: # pragma: nocover # asynctnt does not send schema_id
p = mp_encode_uint(p, tarantool.IPROTO_SCHEMA_VERSION)
p = mp_store_u8(p, 0xce)
p = mp_store_u32(p, schema_id)
Expand Down Expand Up @@ -283,7 +283,7 @@ cdef class WriteBuffer:

if arr is not None:
arr_len = <uint32_t> cpython.list.PyList_GET_SIZE(arr)
else:
else: # pragma: nocover
arr_len = 0
p = self.mp_encode_array(p, arr_len)

Expand All @@ -302,7 +302,7 @@ cdef class WriteBuffer:

if t is not None:
t_len = <uint32_t> cpython.tuple.PyTuple_GET_SIZE(t)
else:
else: # pragma: nocover
t_len = 0
p = self.mp_encode_array(p, t_len)

Expand All @@ -323,7 +323,7 @@ cdef class WriteBuffer:

if d is not None:
d_len = <uint32_t> cpython.dict.PyDict_Size(d)
else:
else: # pragma: nocover
d_len = 0
p = self.mp_encode_map(p, d_len)

Expand Down
98 changes: 66 additions & 32 deletions asynctnt/iproto/protocol.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -138,38 +138,72 @@ class Db:

def set_stream_id(self, stream_id: int): ...

def ping(self, timeout=-1): ...

def call16(self, func_name, args=None, timeout=-1, push_subscribe=False): ...

def call(self, func_name, args=None, timeout=-1, push_subscribe=False): ...

def eval(self, expression, args=None, timeout=-1, push_subscribe=False): ...

def select(self, space, key=None,
offset=0, limit=0xffffffff, index=0, iterator=0,
timeout=-1, check_schema_change=True): ...

def insert(self, space, t, replace=False,
timeout=-1): ...

def replace(self, space, t, timeout=-1): ...

def delete(self, space, key, index=0, timeout=-1): ...

def update(self, space, key, operations, index=0, timeout=-1): ...

def upsert(self, space, t, operations, timeout=-1): ...

def execute(self, query, args, parse_metadata=True, timeout=-1): ...

def prepare(self, query, parse_metadata=True, timeout=-1): ...

def begin(self, isolation: int, tx_timeout: float, timeout=-1): ...

def commit(self, timeout=-1): ...

def rollback(self, timeout=-1): ...
def ping(self, timeout: float = -1): ...

def call16(self,
func_name: str,
args=None,
timeout: float = -1,
push_subscribe: bool = False): ...

def call(self,
func_name: str,
args=None,
timeout: float = -1,
push_subscribe: bool = False): ...

def eval(self,
expression: str,
args=None,
timeout: float = -1,
push_subscribe: bool = False): ...

def select(self,
space, key=None,
offset: int = 0,
limit: int = 0xffffffff,
index=0,
iterator=0,
timeout: float = -1,
check_schema_change: bool = True): ...

def insert(self,
space, t,
replace: bool = False,
timeout: float = -1): ...

def replace(self, space, t,
timeout: float = -1): ...

def delete(self, space, key, index=0,
timeout: float = -1): ...

def update(self,
space, key, operations, index=0,
timeout: float = -1): ...

def upsert(self,
space, t, operations,
timeout: float = -1): ...

def execute(self,
query, args,
parse_metadata: bool = True,
timeout: float = -1): ...

def prepare(self,
query,
parse_metadata: bool = True,
timeout: float = -1): ...

def begin(self,
isolation: int,
tx_timeout: float,
timeout: float = -1): ...

def commit(self, timeout: float = -1): ...

def rollback(self, timeout: float = -1): ...


class Protocol:
Expand Down
21 changes: 13 additions & 8 deletions asynctnt/iproto/response.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ from asynctnt.log import logger

@cython.final
cdef class IProtoErrorStackFrame:
pass
def __repr__(self):
return "<Frame type={} code={} message={}>".format(
self.error_type,
self.code,
self.message,
)

@cython.final
cdef class IProtoError:
Expand Down Expand Up @@ -268,7 +273,7 @@ cdef object _decode_obj(const char ** p, bytes encoding):
return uuid_decode(p, s_len)
elif ext_type == tarantool.MP_ERROR:
return parse_iproto_error(p, encoding)
else:
else: # pragma: nocover
logger.warning('Unexpected ext type: %d', ext_type)
return None
else: # pragma: nocover
Expand Down Expand Up @@ -376,7 +381,7 @@ cdef Metadata response_parse_metadata(const char ** b, bytes encoding):
arr_size = mp_decode_array(b)
for i in range(arr_size):
field_map_size = mp_decode_map(b)
if field_map_size == 0:
if field_map_size == 0: # pragma: nocover
raise RuntimeError('Field map must contain at least '
'1 element - field_name')

Expand Down Expand Up @@ -427,12 +432,12 @@ cdef Metadata response_parse_metadata(const char ** b, bytes encoding):
raise TypeError(
"IPROTO_FIELD_SPAN must be either STR or NIL"
)
else:
else: # pragma: nocover
logger.debug(
'unknown key in metadata decoding: %d', key)
mp_next(b)

if field.name is None:
if field.name is None: # pragma: nocover
raise RuntimeError('field.name must not be None')

metadata.add(<int> field_id, field)
Expand Down Expand Up @@ -490,7 +495,7 @@ cdef inline IProtoErrorStackFrame parse_iproto_error_stack_frame(const char ** b

frame.fields = _decode_obj(b, encoding)

else:
else: # pragma: nocover
logger.debug(f"unknown iproto_error stack element with key {key}")
mp_next(b)

Expand Down Expand Up @@ -521,7 +526,7 @@ cdef inline IProtoError parse_iproto_error(const char ** b, bytes encoding):
el = parse_iproto_error_stack_frame(b, encoding)
cpython.Py_INCREF(el)
cpython.list.PyList_SET_ITEM(error.trace, i, el)
else:
else: # pragma: nocover
logger.debug(f"unknown iproto_error map field with key {key}")
mp_next(b)

Expand Down Expand Up @@ -632,7 +637,7 @@ cdef ssize_t response_parse_body(const char *buf, uint32_t buf_len,
elif key == tarantool.IPROTO_FEATURES:
logger.debug("IProto features available: %s", _decode_obj(&b, resp.encoding))

else:
else: # pragma: nocover
logger.debug('unknown key in body map: %d', int(key))
mp_next(&b)

Expand Down
10 changes: 5 additions & 5 deletions asynctnt/iproto/schema.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cdef class Field:
self.is_autoincrement = None
self.span = None

def __repr__(self):
def __repr__(self): # pragma: nocover
return "<Field name={} type={} is_nullable={}>".format(
self.name, self.type, self.is_nullable
)
Expand Down Expand Up @@ -53,7 +53,7 @@ cdef class Metadata:
cdef inline int len(self):
return <int> cpython.list.PyList_GET_SIZE(self.fields)

def __repr__(self):
def __repr__(self): # pragma: nocover
return '<Metadata [fields_count={}]>'.format(self.len())

@cython.final
Expand All @@ -66,7 +66,7 @@ cdef class SchemaIndex:
self.unique = None
self.metadata = None

def __repr__(self):
def __repr__(self): # pragma: nocover
return \
'<{} sid={}, id={}, name={}, ' \
'type={}, unique={}>'.format(
Expand Down Expand Up @@ -125,7 +125,7 @@ cdef class SchemaSpace:
)
)

def __repr__(self):
def __repr__(self): # pragma: nocover
return '<{} id={} name={} engine={}>'.format(
self.__class__.__name__,
self.sid, self.name, self.engine
Expand Down Expand Up @@ -320,7 +320,7 @@ cdef class Schema:

return s

def __repr__(self):
def __repr__(self): # pragma: nocover
return '<Schema spaces={}>'.format(len(self.spaces))

cdef list dict_to_list_fields(dict d, Metadata metadata, bint default_none):
Expand Down
2 changes: 1 addition & 1 deletion asynctnt/prepared.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .iproto import protocol

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: nocover
from .api import Api


Expand Down
Loading

0 comments on commit fb03019

Please sign in to comment.