Skip to content
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

Switch in singular the names for the Enums classes with non-simultaneously-coexisting-values #119

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions asynch/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from asynch.errors import NotSupportedError
from asynch.proto import constants
from asynch.proto.connection import Connection as ProtoConnection
from asynch.proto.models.enums import ConnectionStatuses
from asynch.proto.models.enums import ConnectionStatus
from asynch.proto.utils.dsn import parse_dsn


Expand Down Expand Up @@ -134,15 +134,15 @@ def status(self) -> str:

:raise ConnectionError: an unresolved connection state
:return: the Connection object status
:rtype: str (ConnectionStatuses StrEnum)
:rtype: str (ConnectionStatus StrEnum)
"""

if self._opened is None and self._closed is None:
return ConnectionStatuses.created
return ConnectionStatus.created
if self._opened:
return ConnectionStatuses.opened
return ConnectionStatus.opened
if self._closed:
return ConnectionStatuses.closed
return ConnectionStatus.closed
raise ConnectionError(f"{self} is in an unknown state")

@property
Expand Down
22 changes: 11 additions & 11 deletions asynch/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from warnings import warn

from asynch.errors import InterfaceError, ProgrammingError
from asynch.proto.models.enums import CursorStatuses
from asynch.proto.models.enums import CursorStatus

Column = namedtuple("Column", "name type_code display_size internal_size precision scale null_ok")

Expand All @@ -15,7 +15,7 @@ class States:
warn(
(
"Should not be used in the version 0.2.6 or later."
"Should be replaced with the reconsidered `CursorStatuses` enum "
"Should be replaced with the reconsidered `CursorStatus` enum "
"from the `asynch.proto.models.enums` module."
),
DeprecationWarning,
Expand Down Expand Up @@ -59,7 +59,7 @@ def status(self) -> str:
"""Return the status of the cursor.

:return: the Cursor object status
:rtype: str (CursorStatuses StrEnum)
:rtype: str (CursorStatus StrEnum)
"""

return self._state
Expand All @@ -71,7 +71,7 @@ def setoutputsizes(self, *args):
"""Does nothing, required by DB API."""

async def close(self):
self._state = CursorStatuses.closed
self._state = CursorStatus.closed

async def execute(
self,
Expand Down Expand Up @@ -141,7 +141,7 @@ async def fetchone(self):
if self._stream_results:
try:
return await self._rows.next()
except: # noqa: E722
except Exception:
Copy link
Contributor Author

@stankudrow stankudrow Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@llchan, brought from #118 as well.

return None

if not self._rows:
Expand Down Expand Up @@ -188,7 +188,7 @@ def _reset_state(self):
Prepares a cursor object to handle another query.
"""

self._state = CursorStatuses.ready
self._state = CursorStatus.ready

self._columns = None
self._types = None
Expand Down Expand Up @@ -281,7 +281,7 @@ async def __aenter__(self):

@property
def description(self):
if self._state == CursorStatuses.ready:
if self._state == CursorStatus.ready:
return None

columns = self._columns or []
Expand All @@ -293,7 +293,7 @@ def description(self):
]

def _check_query_started(self):
if self._state == CursorStatuses.ready:
if self._state == CursorStatus.ready:
raise ProgrammingError(f"no results to fetch from the {self}")

def _check_query_executing(self):
Expand All @@ -303,14 +303,14 @@ def _check_query_executing(self):
)

def _check_cursor_closed(self):
if self._state == CursorStatuses.closed:
if self._state == CursorStatus.closed:
raise InterfaceError(f"the {self} is already closed")

def _begin_query(self):
self._state = CursorStatuses.running
self._state = CursorStatus.running

def _end_query(self):
self._state = CursorStatuses.finished
self._state = CursorStatus.finished

def set_stream_results(self, stream_results, max_row_buffer):
"""
Expand Down
10 changes: 5 additions & 5 deletions asynch/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from asynch.connection import Connection, connect
from asynch.errors import ClickHouseException
from asynch.proto import constants
from asynch.proto.models.enums import PoolStatuses
from asynch.proto.models.enums import PoolStatus

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -164,15 +164,15 @@ def status(self) -> str:

:raise AsynchPoolError: an unresolved pool state.
:return: the Pool object status
:rtype: str (PoolStatuses StrEnum)
:rtype: str (PoolStatus StrEnum)
"""

if self._opened is None and self._closed is None:
return PoolStatuses.created
return PoolStatus.created
if self._opened:
return PoolStatuses.opened
return PoolStatus.opened
if self._closed:
return PoolStatuses.closed
return PoolStatus.closed
raise AsynchPoolError(f"{self} is in an unknown state")

@property
Expand Down
6 changes: 3 additions & 3 deletions asynch/proto/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from asynch.proto.compression import get_compressor_cls
from asynch.proto.context import Context, ExecuteContext
from asynch.proto.cs import ClientInfo, QueryKind, ServerInfo
from asynch.proto.models.enums import CompressionAlgorithms, Schemes
from asynch.proto.models.enums import ClickhouseScheme, CompressionAlgorithm
from asynch.proto.progress import Progress
from asynch.proto.protocol import ClientPacket, Compression, ServerPacket
from asynch.proto.result import (
Expand Down Expand Up @@ -103,7 +103,7 @@ def __init__( # nosec:B107
self.hosts = [(host, port or default_port)]
if alt_hosts:
for host in alt_hosts.split(","):
url = urlparse(f"{Schemes.clickhouse}://" + host)
url = urlparse(f"{ClickhouseScheme.clickhouse}://" + host)
self.hosts.append((url.hostname, url.port or default_port))
self.database = database
self.host = None
Expand All @@ -129,7 +129,7 @@ def __init__( # nosec:B107
self.ssl_options = ssl_options
# Use LZ4 compression by default.
if compression is True:
compression = CompressionAlgorithms.lz4
compression = CompressionAlgorithm.lz4

if compression is False:
self.compression = Compression.DISABLED
Expand Down
10 changes: 5 additions & 5 deletions asynch/proto/models/enums.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
from enum import Enum


class CompressionAlgorithms(str, Enum):
class CompressionAlgorithm(str, Enum):
lz4 = "lz4"
lz4hc = "lz4hc"
zstd = "zstd"


class ConnectionStatuses(str, Enum):
class ConnectionStatus(str, Enum):
created = "created"
opened = "opened"
closed = "closed"


class CursorStatuses(str, Enum):
class CursorStatus(str, Enum):
ready = "ready"
running = "running"
finished = "finished"
closed = "closed"


class PoolStatuses(str, Enum):
class PoolStatus(str, Enum):
created = "created"
opened = "opened"
closed = "closed"


class Schemes(str, Enum):
class ClickhouseScheme(str, Enum):
clickhouse = "clickhouse"
clickhouses = "clickhouses"
12 changes: 6 additions & 6 deletions asynch/proto/utils/dsn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
from typing import Any
from urllib.parse import ParseResult, parse_qs, unquote, urlparse

from asynch.proto.models.enums import CompressionAlgorithms, Schemes
from asynch.proto.models.enums import ClickhouseScheme, CompressionAlgorithm
from asynch.proto.utils.compat import asbool

_SCHEME_SEPARATOR = "://"

_COMPRESSION_ALGORITHMS: set[str] = {
CompressionAlgorithms.lz4,
CompressionAlgorithms.lz4hc,
CompressionAlgorithms.zstd,
CompressionAlgorithm.lz4,
CompressionAlgorithm.lz4hc,
CompressionAlgorithm.zstd,
}
_SUPPORTED_SCHEMES: set[str] = {Schemes.clickhouse, Schemes.clickhouses}
_SUPPORTED_SCHEMES: set[str] = {ClickhouseScheme.clickhouse, ClickhouseScheme.clickhouses}
_TIMEOUTS: set[str] = {"connect_timeout", "send_receive_timeout", "sync_request_timeout"}


Expand Down Expand Up @@ -68,7 +68,7 @@ def parse_dsn(dsn: str) -> dict[str, Any]:
if path:
kwargs["database"] = path

if url.scheme == Schemes.clickhouses:
if url.scheme == ClickhouseScheme.clickhouses:
kwargs["secure"] = True

for name, value in parse_qs(url.query).items():
Expand Down
8 changes: 4 additions & 4 deletions tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from asynch.connection import Connection
from asynch.pool import AsynchPoolError, Pool
from asynch.proto import constants
from asynch.proto.models.enums import PoolStatuses
from asynch.proto.models.enums import PoolStatus


@pytest.mark.asyncio
Expand All @@ -31,7 +31,7 @@ async def test_pool_repr():
pool = Pool()
repstr = (
f"<Pool(minsize={constants.POOL_MIN_SIZE}, maxsize={constants.POOL_MAX_SIZE})"
f" object at 0x{id(pool):x}; status: {PoolStatuses.created}>"
f" object at 0x{id(pool):x}; status: {PoolStatus.created}>"
)
assert repr(pool) == repstr

Expand All @@ -40,13 +40,13 @@ async def test_pool_repr():
async with pool:
repstr = (
f"<Pool(minsize={min_size}, maxsize={max_size}) "
f"object at 0x{id(pool):x}; status: {PoolStatuses.opened}>"
f"object at 0x{id(pool):x}; status: {PoolStatus.opened}>"
)
assert repr(pool) == repstr

repstr = (
f"<Pool(minsize={min_size}, maxsize={max_size}) "
f"object at 0x{id(pool):x}; status: {PoolStatuses.closed}>"
f"object at 0x{id(pool):x}; status: {PoolStatus.closed}>"
)
assert repr(pool) == repstr

Expand Down
24 changes: 12 additions & 12 deletions tests/test_proto/utils/test_dsn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from asynch.proto.models.enums import CompressionAlgorithms, Schemes
from asynch.proto.models.enums import ClickhouseScheme, CompressionAlgorithm
from asynch.proto.utils.dsn import DSNError, parse_dsn


Expand All @@ -13,18 +13,18 @@
[
("", pytest.raises(DSNError), None),
("some_scheme://", pytest.raises(DSNError), None),
(f"{Schemes.clickhouse}://", pytest.raises(DSNError), None),
(f"{Schemes.clickhouses}://", pytest.raises(DSNError), None),
(f"{ClickhouseScheme.clickhouse}://", pytest.raises(DSNError), None),
(f"{ClickhouseScheme.clickhouses}://", pytest.raises(DSNError), None),
(
f"{Schemes.clickhouse}://ch@lochost/",
f"{ClickhouseScheme.clickhouse}://ch@lochost/",
does_not_raise(),
{
"user": "ch",
"host": "lochost",
},
),
(
f"{Schemes.clickhouse}://ch:pwd@lochost/",
f"{ClickhouseScheme.clickhouse}://ch:pwd@lochost/",
does_not_raise(),
{
"user": "ch",
Expand All @@ -33,7 +33,7 @@
},
),
(
f"{Schemes.clickhouse}://ch@lochost:4321/",
f"{ClickhouseScheme.clickhouse}://ch@lochost:4321/",
does_not_raise(),
{
"user": "ch",
Expand All @@ -42,7 +42,7 @@
},
),
(
f"{Schemes.clickhouse}://ch:pwd@lochost:1234/db",
f"{ClickhouseScheme.clickhouse}://ch:pwd@lochost:1234/db",
does_not_raise(),
{
"user": "ch",
Expand All @@ -58,12 +58,12 @@
None,
),
(
f"{Schemes.clickhouse}://lochost:1234/test",
f"{ClickhouseScheme.clickhouse}://lochost:1234/test",
does_not_raise(),
{"host": "lochost", "port": 1234, "database": "test"},
),
(
f"{Schemes.clickhouse} :// lochost : 1234 / test",
f"{ClickhouseScheme.clickhouse} :// lochost : 1234 / test",
pytest.raises(DSNError),
None,
),
Expand All @@ -82,7 +82,7 @@ def test_dsn_basic_credentials(
("dsn", "query", "answer"),
[
(
f"{Schemes.clickhouses}://ch:pwd@loc:1029/def",
f"{ClickhouseScheme.clickhouses}://ch:pwd@loc:1029/def",
"verify=true&ssl_version=PROTOCOL_TLSv1&ca_certs=path/to/CA.crt&ciphers=AES&client_name",
{
"verify": True,
Expand All @@ -92,7 +92,7 @@ def test_dsn_basic_credentials(
},
),
(
f"{Schemes.clickhouse}://ch:pwd@loc:2938/ault",
f"{ClickhouseScheme.clickhouse}://ch:pwd@loc:2938/ault",
(
"verify=true"
"&secure=yes"
Expand All @@ -108,7 +108,7 @@ def test_dsn_basic_credentials(
{
"verify": True,
"secure": True,
"compression": CompressionAlgorithms.zstd,
"compression": CompressionAlgorithm.zstd,
"client_name": "my_ch_client",
"compress_block_size": 21,
"ssl_version": ssl.PROTOCOL_TLSv1,
Expand Down
Loading