diff --git a/aiochclient/types.py b/aiochclient/types.py index 1bafd8d..94db868 100755 --- a/aiochclient/types.py +++ b/aiochclient/types.py @@ -1,5 +1,6 @@ import datetime as dt import re +from abc import ABC, abstractmethod from typing import Any, Callable, Generator, Optional from uuid import UUID @@ -8,7 +9,7 @@ __all__ = ["what_py_converter", "rows2ch"] -class BaseType: +class BaseType(ABC): __slots__ = ("name", "container") @@ -31,9 +32,9 @@ def __init__(self, name: str, container: bool = False): self.name = name self.container = container + @abstractmethod def p_type(self, string): """ Function for implementing specific actions for each type """ - return string @classmethod def decode(cls, val: bytes) -> str: diff --git a/tests.py b/tests.py index d63d1cd..92b5a67 100644 --- a/tests.py +++ b/tests.py @@ -404,6 +404,11 @@ async def test_fetchrow_with_empties(self): : ] == self.rows[1] + async def test_fetchrow_none_result(self): + assert ( + await self.ch.fetchrow("SELECT * FROM all_types WHERE uint8=42") + ) is None + async def test_fetchone_full(self): assert (await self.ch.fetchone("SELECT * FROM all_types WHERE uint8=1"))[ : @@ -414,6 +419,16 @@ async def test_fetchone_with_empties(self): : ] == self.rows[1] + async def test_fetchone_none_result(self): + assert ( + await self.ch.fetchone("SELECT * FROM all_types WHERE uint8=42") + ) is None + + async def test_fetchval_none_result(self): + assert ( + await self.ch.fetchval("SELECT uint8 FROM all_types WHERE uint8=42") + ) is None + async def test_fetch(self): rows = await self.ch.fetch("SELECT * FROM all_types") assert [row[:] for row in rows] == self.rows @@ -428,6 +443,9 @@ async def test_iterate(self): row[:] async for row in self.ch.iterate("SELECT * FROM all_types") ] == self.rows + async def test_select_with_execute(self): + assert (await self.ch.execute("SELECT * FROM all_types WHERE uint8=1")) is None + @pytest.mark.record @pytest.mark.usefixtures("class_chclient") @@ -439,8 +457,9 @@ async def test_common_objects(self): async def test_lazy_decoding(self): record = await self.ch.fetchrow("SELECT * FROM all_types WHERE uint8=2") - assert type(record._row[0]) == bytes + assert type(record._row) == bytes record[0] + assert type(record._row) == tuple assert type(record._row[0]) == int async def test_mapping(self):