Skip to content

Commit

Permalink
More tests and abc in types
Browse files Browse the repository at this point in the history
  • Loading branch information
maximdanilchenko committed May 23, 2019
1 parent 96ab772 commit ddce9d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions aiochclient/types.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -8,7 +9,7 @@
__all__ = ["what_py_converter", "rows2ch"]


class BaseType:
class BaseType(ABC):

__slots__ = ("name", "container")

Expand All @@ -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:
Expand Down
21 changes: 20 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))[
:
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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):
Expand Down

0 comments on commit ddce9d9

Please sign in to comment.