Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test-subscription-handle:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install test deps
run: |
python -m pip install --upgrade pip
python -m pip install pytest
- name: Run subscription_handle tests
run: |
python -m pytest -q tests/test_subscription_handle.py
23 changes: 22 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,25 @@ Thank you for contributing to the Hiero Python SDK! 🎉
- **Need help or want to connect?** Join our community on Discord! See the **[Discord Joining Guide](docs/discord.md)** for detailed steps on how to join the LFDT server
- **Quick Links:**
- Join the main [Linux Foundation Decentralized Trust (LFDT) Discord Server](https://discord.gg/hyperledger).
- Go directly to the [#hiero-python-sdk channel](https://discord.com/channels/905194001349627914/1336494517544681563)
- Go directly to the [#hiero-python-sdk channel](https://discord.com/channels/905194001349627914/1336494517544681563)

---

## Running tests locally

During development you may want to run a single test file in isolation to avoid importing the project's package-level `__init__` (which imports generated protobuf modules). To run a single test file without loading project-wide fixtures, use the project's virtualenv Python and run pytest on the path:

PowerShell example:
```powershell
# activate virtualenv (if not already active)
C:/Users/Giannis/OneDrive/Programming/hiero-sdk-python/.venv/Scripts/Activate.ps1

# install test deps if needed
python -m pip install -U pip
python -m pip install pytest

# run a single test file
python -m pytest -q tests/test_subscription_handle.py
```

If you want to run a subset of tests, use `-k` with a keyword expression or provide a directory/file path. This helps avoid heavy `conftest.py` imports during quick iteration.
38 changes: 38 additions & 0 deletions tests/test_subscription_handle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from unittest.mock import Mock
import importlib.util
from pathlib import Path

# Load the module directly from the source file to avoid importing the
# package `hiero_sdk_python` (its top-level __init__ triggers imports of
# many modules that require generated protobufs during test collection).
repo_root = Path(__file__).resolve().parent.parent
module_path = repo_root / "src" / "hiero_sdk_python" / "utils" / "subscription_handle.py"
spec = importlib.util.spec_from_file_location("subscription_handle", str(module_path))
subscription_handle = importlib.util.module_from_spec(spec)
spec.loader.exec_module(subscription_handle)
SubscriptionHandle = subscription_handle.SubscriptionHandle


def test_not_cancelled_by_default():
handle = SubscriptionHandle()
assert not handle.is_cancelled()


def test_cancel_marks_as_cancelled():
handle = SubscriptionHandle()
handle.cancel()
assert handle.is_cancelled()


def test_set_thread_and_join_calls_thread_join_with_timeout():
handle = SubscriptionHandle()
mock_thread = Mock()
handle.set_thread(mock_thread)
handle.join(timeout=0.25)
mock_thread.join.assert_called_once_with(0.25)


def test_join_without_thread_raises_nothing():
handle = SubscriptionHandle()
# should not raise
handle.join()
Loading