Skip to content

Commit 0c79d45

Browse files
authored
Merge pull request #21 from dapper91/python3.12
- python 3.12 support added.
2 parents 9b12a32 + ebb9ae9 commit 0c79d45

File tree

8 files changed

+155
-152
lines changed

8 files changed

+155
-152
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
python-version: ['3.9', '3.10', '3.11']
17+
python-version: ['3.9', '3.10', '3.11', '3.12']
1818
steps:
1919
- uses: actions/checkout@v2
2020
- name: Set up Python ${{ matrix.python-version }}

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ repos:
2525
args:
2626
- --fix=no
2727
- repo: https://github.com/asottile/add-trailing-comma
28-
rev: v2.4.0
28+
rev: v3.1.0
2929
hooks:
3030
- id: add-trailing-comma
3131
stages:
3232
- commit
3333
- repo: https://github.com/pre-commit/mirrors-autopep8
34-
rev: v2.0.2
34+
rev: v2.0.4
3535
hooks:
3636
- id: autopep8
3737
stages:
3838
- commit
3939
args:
4040
- --diff
4141
- repo: https://github.com/pycqa/flake8
42-
rev: 6.0.0
42+
rev: 6.1.0
4343
hooks:
4444
- id: flake8
4545
- repo: https://github.com/pycqa/isort
@@ -63,7 +63,7 @@ repos:
6363
- --multi-line=9
6464
- --project=generic_connection_pool
6565
- repo: https://github.com/pre-commit/mirrors-mypy
66-
rev: v1.1.1
66+
rev: v1.5.1
6767
hooks:
6868
- id: mypy
6969
stages:

generic_connection_pool/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import Dict, Generic, Hashable, Optional, Tuple, TypeVar
77

88
from . import exceptions
9-
from .heap import ExtHeap
9+
from .rankmap import RankMap
1010

1111
logger = logging.getLogger(__package__)
1212

@@ -279,7 +279,7 @@ class BaseEventQueue(Generic[KeyType]):
279279
"""
280280

281281
def __init__(self) -> None:
282-
self._queue: ExtHeap[Event[KeyType]] = ExtHeap()
282+
self._queue: RankMap[Event[KeyType]] = RankMap()
283283

284284
def _insert(self, timestamp: float, key: KeyType) -> None:
285285
"""

generic_connection_pool/contrib/unix.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ class CheckSocketAlivenessMixin(Generic[EndpointT]):
2727

2828
def check_aliveness(self, endpoint: EndpointT, conn: socket.socket, timeout: Optional[float] = None) -> bool:
2929
try:
30-
with socket_timeout(conn, timeout):
31-
resp = conn.recv(1, socket.MSG_PEEK | socket.MSG_DONTWAIT)
32-
if resp == b'':
30+
if conn.recv(1, socket.MSG_PEEK | socket.MSG_DONTWAIT) == b'':
3331
return False
3432
except BlockingIOError as exc:
3533
if exc.errno != errno.EAGAIN:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ComparableAndHashable(ComparableP, Protocol, Hashable):
1313
Item = TypeVar('Item', bound=ComparableAndHashable)
1414

1515

16-
class ExtHeap(Generic[Item]):
16+
class RankMap(Generic[Item]):
1717
"""
1818
Extended heap data structure implementation.
1919
Similar to `heapq` but supports remove and replace operations.

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ classifiers = [
1414
"Intended Audience :: Developers",
1515
"Natural Language :: English",
1616
"License :: Public Domain",
17+
"Operating System :: OS Independent",
18+
"Topic :: Database",
19+
"Topic :: Internet :: WWW/HTTP",
1720
"Topic :: Software Development :: Libraries",
1821
"Topic :: System :: Networking",
1922
"Programming Language :: Python :: 3",
2023
"Programming Language :: Python :: 3.9",
2124
"Programming Language :: Python :: 3.10",
2225
"Programming Language :: Python :: 3.11",
26+
"Programming Language :: Python :: 3.12",
27+
"Typing :: Typed",
2328
]
2429

2530
[tool.poetry.dependencies]

tests/test_heap.py

Lines changed: 0 additions & 141 deletions
This file was deleted.

tests/test_rankmap.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import pytest
2+
3+
from generic_connection_pool.rankmap import RankMap
4+
5+
6+
def test_heap_top():
7+
rm = RankMap()
8+
9+
rm.insert(3)
10+
rm.insert(1)
11+
rm.insert(2)
12+
13+
assert rm.top() == 1
14+
rm.pop()
15+
16+
assert rm.top() == 2
17+
rm.pop()
18+
19+
assert rm.top() == 3
20+
rm.pop()
21+
22+
assert rm.top() is None
23+
24+
25+
def test_heap_push_pop():
26+
rm = RankMap()
27+
28+
items = [0, 2, 1, 4, 3, 5, 6, 7, 8, 12, 11, 10, 9]
29+
for item in items:
30+
rm.insert(item)
31+
32+
actual_result = []
33+
while rm:
34+
actual_result.append(rm.pop())
35+
36+
expected_result = sorted(items)
37+
assert actual_result == expected_result
38+
assert rm.pop() is None
39+
assert len(rm) == 0
40+
41+
42+
def test_heap_multiple_push_pop():
43+
rm = RankMap()
44+
45+
rm.insert(0)
46+
rm.insert(1)
47+
rm.pop()
48+
rm.insert(0)
49+
50+
51+
def test_heap_replace():
52+
rm = RankMap()
53+
54+
rm.insert(0)
55+
rm.replace(0, 1)
56+
assert len(rm) == 1
57+
58+
items = [3, 4, 6, 7, 8]
59+
for item in items:
60+
rm.insert(item)
61+
62+
rm.replace(1, 2)
63+
rm.replace(4, 5)
64+
rm.replace(6, 0)
65+
rm.replace(7, 9)
66+
rm.replace(8, 1)
67+
rm.replace(9, 4)
68+
69+
actual_result = []
70+
while rm:
71+
actual_result.append(rm.pop())
72+
73+
expected_result = [0, 1, 2, 3, 4, 5]
74+
assert actual_result == expected_result
75+
76+
77+
def test_heap_replace_by_copy():
78+
rm = RankMap()
79+
80+
rm.insert(1)
81+
rm.insert_or_replace(1)
82+
rm.insert(2)
83+
rm.insert_or_replace(2)
84+
85+
actual_result = []
86+
while rm:
87+
actual_result.append(rm.pop())
88+
89+
expected_result = [1, 2]
90+
assert actual_result == expected_result
91+
92+
93+
def test_heap_remove():
94+
rm = RankMap()
95+
96+
rm.insert(1)
97+
rm.remove(1)
98+
99+
assert len(rm) == 0
100+
101+
rm.insert(1)
102+
rm.insert(2)
103+
rm.insert(3)
104+
rm.insert(4)
105+
106+
rm.remove(2)
107+
assert rm.pop() == 1
108+
assert rm.pop() == 3
109+
110+
rm.remove(4)
111+
assert len(rm) == 0
112+
113+
114+
def test_heap_duplicate_error():
115+
rm = RankMap()
116+
117+
rm.insert(1)
118+
with pytest.raises(KeyError):
119+
rm.insert(1)
120+
121+
rm.insert(2)
122+
with pytest.raises(KeyError):
123+
rm.replace(2, 1)
124+
125+
126+
def test_heap_clear():
127+
rm = RankMap()
128+
129+
items = [0, 1, 2]
130+
for item in items:
131+
rm.insert(item)
132+
133+
rm.clear()
134+
assert len(rm) == 0
135+
136+
137+
def test_heap_not_found_error():
138+
rm = RankMap()
139+
140+
with pytest.raises(KeyError):
141+
rm.replace(1, 2)

0 commit comments

Comments
 (0)