Skip to content

Commit d56cfa5

Browse files
author
Bakytgerey Ashirbekov
committed
add tests
1 parent 53ceaed commit d56cfa5

File tree

13 files changed

+188
-25
lines changed

13 files changed

+188
-25
lines changed

.github/workflows/python.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
- uses: actions/setup-python@v5
3030
with:
3131
python-version: '3.10'
32+
- name: Install dependencies
33+
run: pip install ".[testing]"
3234
- name: Build wheels
3335
uses: PyO3/maturin-action@v1
3436
with:
@@ -37,6 +39,8 @@ jobs:
3739
manylinux: '2_28'
3840
args: --release --out dist --find-interpreter
3941
sccache: 'true'
42+
- name: Run tests
43+
run: pytest
4044
- name: Upload wheels
4145
uses: actions/upload-artifact@v4
4246
with:
@@ -54,6 +58,8 @@ jobs:
5458
with:
5559
python-version: '3.10'
5660
architecture: ${{ matrix.target }}
61+
- name: Install dependencies
62+
run: pip install ".[testing]"
5763
- name: Set up NASM
5864
uses: ilammy/setup-nasm@v1
5965
- name: Build wheels
@@ -62,14 +68,16 @@ jobs:
6268
target: ${{ matrix.target }}
6369
args: --release --out dist --find-interpreter
6470
sccache: 'true'
71+
- name: Run tests
72+
run: pytest
6573
- name: Upload wheels
6674
uses: actions/upload-artifact@v4
6775
with:
6876
name: wheels-windows-${{ matrix.target }}
6977
path: dist
7078

7179
macos:
72-
runs-on: macos-latest
80+
runs-on: macos-13
7381
strategy:
7482
matrix:
7583
target: [x86_64, aarch64]
@@ -78,12 +86,38 @@ jobs:
7886
- uses: actions/setup-python@v5
7987
with:
8088
python-version: '3.10'
89+
- name: Install dependencies
90+
run: pip install ".[testing]"
91+
- name: Install and start Colima
92+
run: |
93+
brew install colima docker
94+
colima start --network-address --network-host-addresses
95+
echo "DOCKER_HOST=unix://$HOME/.colima/default/docker.sock" >> $GITHUB_ENV
96+
docker network ls
97+
- name: Ensure Colima is running and Docker is accessible
98+
run: |
99+
colima status || (echo "Colima is not running!" && exit 1)
100+
docker ps || (echo "Docker is not running inside Colima!" && exit 1)
101+
- name: Debug Running Containers
102+
run: |
103+
docker ps -a
104+
docker port $(docker ps -q) || echo "No running containers yet"
105+
- name: Manually Forward Port 8090
106+
run: |
107+
limactl shell colima sudo iptables -t nat -A PREROUTING -p tcp --dport 8090 -j REDIRECT --to-port 8090
108+
limactl shell colima sudo iptables -L -t nat
81109
- name: Build wheels
82110
uses: PyO3/maturin-action@v1
83111
with:
84112
target: ${{ matrix.target }}
85113
args: --release --out dist --find-interpreter
86114
sccache: 'true'
115+
- name: Wait for Container to Start & Check Port
116+
run: |
117+
sleep 5
118+
netstat -an | grep 8090 || echo "Port 8090 is not open"
119+
- name: Run tests
120+
run: pytest
87121
- name: Upload wheels
88122
uses: actions/upload-artifact@v4
89123
with:
@@ -94,11 +128,15 @@ jobs:
94128
runs-on: ubuntu-latest
95129
steps:
96130
- uses: actions/checkout@v4
131+
- name: Install dependencies
132+
run: pip install ".[testing]"
97133
- name: Build sdist
98134
uses: PyO3/maturin-action@v1
99135
with:
100136
command: sdist
101137
args: --out dist
138+
- name: Run tests
139+
run: pytest
102140
- name: Upload sdist
103141
uses: actions/upload-artifact@v4
104142
with:

Cargo.lock

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ name = "iggy_py"
1414
crate-type = ["cdylib", "rlib"]
1515

1616
[dependencies]
17-
pyo3 = "0.23.0"
17+
pyo3 = "0.22.0"
1818
iggy = "0.6.201"
1919
tokio = { version = "1.43.0", features = ["full"] }
2020
bytes = "1.10.0"
2121
openssl = { version = "0.10.*", features = ["vendored"] }
22-
pyo3-async-runtimes = { version = "0.23.0", features = ["attributes", "tokio-runtime"] }
22+
pyo3-async-runtimes = { version = "0.22.0", features = ["attributes", "tokio-runtime"] }
2323
pyo3-stub-gen = "0.7.0"
2424

2525
[[bin]]

iggy_py.pyi

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ class IggyClient:
1111
It wraps the RustIggyClient and provides asynchronous functionality
1212
through the contained runtime.
1313
"""
14-
def __new__(cls,conn:typing.Optional[builtins.str]=None): ...
14+
def new(self, conn:typing.Optional[builtins.str]) -> IggyClient:
15+
r"""
16+
Constructs a new IggyClient.
17+
18+
This initializes a new runtime for asynchronous operations.
19+
Future versions might utilize asyncio for more Pythonic async.
20+
"""
21+
...
22+
1523
def login_user(self, username:builtins.str, password:builtins.str) -> typing.Any:
1624
r"""
1725
Logs in the user with the given credentials.
@@ -28,7 +36,7 @@ class IggyClient:
2836
"""
2937
...
3038

31-
def create_stream(self, name:builtins.str, stream_id:typing.Optional[builtins.int]=None) -> typing.Any:
39+
def create_stream(self, name:builtins.str, stream_id:typing.Optional[builtins.int]) -> typing.Any:
3240
r"""
3341
Creates a new stream with the provided ID and name.
3442
@@ -44,7 +52,7 @@ class IggyClient:
4452
"""
4553
...
4654

47-
def create_topic(self, stream:PyIdentifier, name:builtins.str, partitions_count:builtins.int, compression_algorithm:typing.Optional[builtins.str]=None, topic_id:typing.Optional[builtins.int]=None, replication_factor:typing.Optional[builtins.int]=None) -> typing.Any:
55+
def create_topic(self, stream:PyIdentifier, name:builtins.str, partitions_count:builtins.int, compression_algorithm:typing.Optional[builtins.str], topic_id:typing.Optional[builtins.int], replication_factor:typing.Optional[builtins.int]) -> typing.Any:
4856
r"""
4957
Creates a new topic with the given parameters.
5058
@@ -140,6 +148,28 @@ class ReceiveMessage:
140148
...
141149

142150

151+
class SendMessage:
152+
r"""
153+
A Python class representing a message to be sent.
154+
155+
This class wraps a Rust message meant for sending, facilitating
156+
the creation of such messages from Python and their subsequent use in Rust.
157+
"""
158+
def __new__(cls,data:builtins.str): ...
159+
...
160+
161+
class StreamDetails:
162+
id: builtins.int
163+
name: builtins.str
164+
messages_count: builtins.int
165+
topics_count: builtins.int
166+
167+
class TopicDetails:
168+
id: builtins.int
169+
name: builtins.str
170+
messages_count: builtins.int
171+
topics_count: builtins.int
172+
143173
class MessageState(Enum):
144174
Available = auto()
145175
Unavailable = auto()

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ description= "Apache Iggy is the persistent message streaming platform written i
1515

1616
[tool.maturin]
1717
features = ["pyo3/extension-module"]
18+
19+
[project.optional-dependencies]
20+
testing = [
21+
"pytest",
22+
"pytest-asyncio",
23+
"testcontainers[docker]",
24+
"maturin"
25+
]
26+
27+
[tool.pytest.ini_options]
28+
asyncio_mode = "auto"

src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ impl From<PyIdentifier> for Identifier {
5050
}
5151
}
5252

53-
#[gen_stub_pymethods]
5453
#[pymethods]
54+
#[gen_stub_pymethods]
5555
impl IggyClient {
5656
/// Constructs a new IggyClient.
5757
///

src/receive_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl ReceiveMessage {
4040
///
4141
/// The payload is returned as a Python bytes object.
4242
pub fn payload(&self, py: Python) -> PyObject {
43-
PyBytes::new(py, &self.inner.payload).into()
43+
PyBytes::new_bound(py, &self.inner.payload).into()
4444
}
4545

4646
/// Retrieves the offset of the received message.

src/send_message.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
use iggy::messages::send_messages::Message as RustSendMessage;
22
use pyo3::prelude::*;
3+
use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods};
34
use std::str::FromStr;
45

56
/// A Python class representing a message to be sent.
67
///
78
/// This class wraps a Rust message meant for sending, facilitating
89
/// the creation of such messages from Python and their subsequent use in Rust.
910
#[pyclass]
11+
#[gen_stub_pyclass]
1012
pub struct SendMessage {
1113
pub(crate) inner: RustSendMessage,
1214
}
@@ -23,6 +25,7 @@ impl Clone for SendMessage {
2325
}
2426
}
2527

28+
#[gen_stub_pymethods]
2629
#[pymethods]
2730
impl SendMessage {
2831
/// Constructs a new `SendMessage` instance from a string.

src/stream.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use iggy::models::stream::StreamDetails as RustStreamDetails;
22
use pyo3::prelude::*;
3+
use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods};
34

45
#[pyclass]
6+
#[gen_stub_pyclass]
57
pub struct StreamDetails {
68
pub(crate) inner: RustStreamDetails,
79
}
@@ -14,6 +16,7 @@ impl From<RustStreamDetails> for StreamDetails {
1416
}
1517
}
1618

19+
#[gen_stub_pymethods]
1720
#[pymethods]
1821
impl StreamDetails {
1922
#[getter]

src/topic.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use iggy::models::topic::TopicDetails as RustTopicDetails;
22
use pyo3::prelude::*;
3+
use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods};
34

5+
#[gen_stub_pyclass]
46
#[pyclass]
57
pub struct TopicDetails {
68
pub(crate) inner: RustTopicDetails,
@@ -14,6 +16,7 @@ impl From<RustTopicDetails> for TopicDetails {
1416
}
1517
}
1618

19+
#[gen_stub_pymethods]
1720
#[pymethods]
1821
impl TopicDetails {
1922
#[getter]

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)