Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
## [Unreleased]

### Added
- Added unit tests for `SubscriptionHandle` class covering cancellation state, thread management, and join operations.
- Modularized `transfer_transaction_fungible` example by introducing `account_balance_query()` & `transfer_transaction()`.Renamed `transfer_tokens()` → `main()`
- Phase 2 of the inactivity-unassign bot:Automatically detects stale open pull requests (no commit activity for 21+ days), comments with a helpful InactivityBot message, closes the stale PR, and unassigns the contributor from the linked issue.
- Added **str**() to CustomFixedFee and updated examples and tests accordingly.
Expand Down
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.
5 changes: 5 additions & 0 deletions tests/_shims/hiero_sdk_python/hapi/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Test shims for generated `hapi` modules.
These are minimal stand-ins used during unit testing when the real
generated protobuf/grpc modules are not present.
"""
1 change: 1 addition & 0 deletions tests/_shims/hiero_sdk_python/hapi/mirror/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Shim for `hiero_sdk_python.hapi.mirror` used in tests."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Minimal stub of generated gRPC module used by `client.Client` for tests."""

class ConsensusServiceStub:
"""A tiny stub of the real gRPC stub. Methods are intentionally omitted."""

def __init__(self, channel):
self._channel = channel
1 change: 1 addition & 0 deletions tests/_shims/hiero_sdk_python/hapi/services/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Shim for `hiero_sdk_python.hapi.services` providing minimal protobuf stubs for tests."""
13 changes: 13 additions & 0 deletions tests/_shims/hiero_sdk_python/hapi/services/basic_types_pb2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Minimal shim for basic_types_pb2 used in tests."""

class _ProtoMessage:
def CopyFrom(self, other):
for k, v in getattr(other, "__dict__", {}).items():
setattr(self, k, v)


class TransactionID(_ProtoMessage):
def __init__(self):
self.accountID = _ProtoMessage()
self.transactionValidStart = _ProtoMessage()
self.scheduled = False
6 changes: 6 additions & 0 deletions tests/_shims/hiero_sdk_python/hapi/services/timestamp_pb2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Minimal shim for timestamp_pb2.Timestamp used in tests."""

class Timestamp:
def __init__(self, seconds: int = 0, nanos: int = 0):
self.seconds = int(seconds)
self.nanos = int(nanos)
28 changes: 28 additions & 0 deletions tests/unit/test_subscription_handle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from unittest.mock import Mock

from hiero_sdk_python.utils.subscription_handle import 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()
2 changes: 2 additions & 0 deletions tools/_mypy_minimal.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy]
ignore_missing_imports = True