Skip to content
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
31 changes: 31 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@ updates:
commit-message:
prefix: ci

# The versions of the tools that build the module, in requirements-build.txt. pybind11 stays at 2.x. One pull request for all of them.
- package-ecosystem: pip
directory: /
schedule:
interval: weekly
cooldown:
default-days: 7
commit-message:
prefix: build
ignore:
- dependency-name: pybind11
update-types: ["version-update:semver-major"]
groups:
build:
patterns:
- "*"

# The versions of the tools that run the tests, in tests/requirements.txt. One pull request for all of them.
- package-ecosystem: pip
directory: /tests
schedule:
interval: weekly
cooldown:
default-days: 7
commit-message:
prefix: test
groups:
tests:
patterns:
- "*"

# The versions of the tools that build the site, in docs/mkdocs/requirements.in. One pull request for the tools that
# have to move together (mkdocstrings needs matching versions of autorefs, griffe and pymdown-extensions) and one
# for the rest. The Docs workflow builds the site with --strict and fails on an update that does not work.
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'CMakeLists.txt'
- 'bin/check_macho_hardening.sh'
- 'bin/install_unbound_macos.sh'
- 'requirements-build.txt'
workflow_dispatch:
workflow_call:

Expand Down Expand Up @@ -57,20 +58,16 @@ jobs:
# monero-project and monero-cpp take brew's openssl unless they are given another one, so
# they get it on the command line, and the module finds it in the environment
echo "OPENSSL_ROOT_DIR=$(brew --prefix openssl@3)" >> "$GITHUB_ENV"
pip3 install pytest pytest-cov setuptools wheel scikit-build-core --break-system-packages
# a virtual environment: the python of brew has packages that pip can not replace, such as wheel and typing_extensions on the
# Intel runner (they have no RECORD file), and the versions of the requirements files are pinned. The next steps find it first in the PATH
python3 -m venv "$RUNNER_TEMP/venv"
echo "$RUNNER_TEMP/venv/bin" >> "$GITHUB_PATH"
"$RUNNER_TEMP/venv/bin/pip" install -r requirements-build.txt

# static, against openssl@3: the unbound of brew is built with OpenSSL 4
- name: Install unbound
run: bin/install_unbound_macos.sh

- name: Install pybind11 v2.13.6
run: |
pip3 install pybind11==2.13.6 pybind11-stubgen --break-system-packages

- name: Install delocate
run: |
pip3 install delocate --break-system-packages

- name: Restore ccache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- '.github/workflows/build-windows.yml'
- 'CMakeLists.txt'
- 'bin/check_pe_hardening.sh'
- 'requirements-build.txt'
workflow_dispatch:
workflow_call:

Expand Down Expand Up @@ -51,7 +52,7 @@ jobs:
- name: Install Python build dependencies
shell: bash
run: |
python -m pip install scikit-build-core delvewheel
python -m pip install -r requirements-build.txt

- name: Setup MSYS2 MINGW64
uses: msys2/setup-msys2@ec48f7c5447b3140e2b088413ae3a55687bccb6e # v2.33.0
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install -y build-essential cmake pkg-config libssl-dev libzmq3-dev libunbound-dev libsodium-dev libunwind8-dev liblzma-dev libreadline6-dev libexpat1-dev libpgm-dev qttools5-dev-tools libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler libudev-dev libboost-chrono-dev libboost-date-time-dev libboost-filesystem-dev libboost-locale-dev libboost-program-options-dev libboost-regex-dev libboost-serialization-dev libboost-system-dev libboost-thread-dev python3 ccache doxygen graphviz git curl autoconf libtool gperf nettle-dev libevent-dev debhelper python3-all python3-pip python3-pybind11 lcov python3-scikit-build-core
pip3 install pybind11-stubgen==2.5.5 pytest pytest-rerunfailures pytest-cov pytest-timeout pyproject-metadata --break-system-packages
sudo apt install -y build-essential cmake pkg-config libssl-dev libzmq3-dev libunbound-dev libsodium-dev libunwind8-dev liblzma-dev libreadline6-dev libexpat1-dev libpgm-dev qttools5-dev-tools libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler libudev-dev libboost-chrono-dev libboost-date-time-dev libboost-filesystem-dev libboost-locale-dev libboost-program-options-dev libboost-regex-dev libboost-serialization-dev libboost-system-dev libboost-thread-dev python3 ccache doxygen graphviz git curl autoconf libtool gperf nettle-dev libevent-dev debhelper python3-all python3-pip lcov
pip3 install -r tests/requirements.txt -r requirements-build.txt --break-system-packages

- name: Install expat
run: |
Expand Down Expand Up @@ -118,7 +118,7 @@ jobs:
- name: Install monero-python
run: |
mkdir -p build
cmake -B build -DENABLE_COVERAGE=ON
cmake -B build -DENABLE_COVERAGE=ON -Dpybind11_DIR="$(python3 -m pybind11 --cmakedir)"
cmake --build build
cp build/monero.cpython-312-x86_64-linux-gnu.so ~/.local/lib/python3.12/site-packages/

Expand Down Expand Up @@ -247,7 +247,7 @@ jobs:
- name: Install pytest and dependencies
shell: bash
run: |
python -m pip install pytest pytest-rerunfailures pytest-timeout pytest-cov typing_extensions scikit-build-core
python -m pip install -r tests/requirements.txt -r requirements-build.txt

- name: Setup MSYS2 MINGW64
uses: msys2/setup-msys2@ec48f7c5447b3140e2b088413ae3a55687bccb6e # v2.33.0
Expand Down Expand Up @@ -454,16 +454,16 @@ jobs:
# monero-project and monero-cpp take brew's openssl unless they are given another one, so
# they get it on the command line, and the module finds it in the environment
echo "OPENSSL_ROOT_DIR=$(brew --prefix openssl@3)" >> "$GITHUB_ENV"
pip3 install pytest pytest-rerunfailures pytest-timeout pytest-cov setuptools wheel scikit-build-core --break-system-packages
# a virtual environment: the python of brew has packages that pip can not replace, such as wheel and typing_extensions on the
# Intel runner (they have no RECORD file), and the versions of the requirements files are pinned. The next steps find it first in the PATH
python3 -m venv "$RUNNER_TEMP/venv"
echo "$RUNNER_TEMP/venv/bin" >> "$GITHUB_PATH"
"$RUNNER_TEMP/venv/bin/pip" install -r tests/requirements.txt -r requirements-build.txt

# static, against openssl@3: the unbound of brew is built with OpenSSL 4
- name: Install unbound
run: bin/install_unbound_macos.sh

- name: Install pybind11 v2.13.6
run: |
pip3 install pybind11==2.13.6 pybind11-stubgen --break-system-packages

- name: Restore ccache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
Expand Down Expand Up @@ -501,7 +501,7 @@ jobs:
- name: Install monero-python
run: |
mkdir -p build
pip3 install --no-build-isolation -vvv . --break-system-packages
pip3 install --no-build-isolation -vvv .

- name: Show ccache statistics
if: ${{ !cancelled() }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build/*
dist
__pycache__
.pytest_cache
.venv
_CPack_Packages
*.deb
*egg-info
Expand Down
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,13 @@ For example: `export LD_PRELOAD=/path/to/libjemalloc.so.2` then run your app. It

## Running Python tests

1. Install `pytest`:
1. Install the test dependencies, with the versions that the CI runs the tests with ([tests/requirements.txt](tests/requirements.txt)), in a virtual environment:
```bash
# With PIP

pip3 install pytest pytest-rerunfailures pytest-timeout pytest-cov --break-system-packages
```
```bash
# System-wide installation Ubuntu/Debian

sudo apt install -y python3-pytest python3-pytest-rerunfailures python3-pytest-timeout python3-pytest-cov
python3 -m venv .venv
. .venv/bin/activate
pip install -r tests/requirements.txt
```
The `monero` module has to be importable in it: install it in the environment (`pip install .`), or set `PYTHONPATH` to the folder that has the built module.
2. Clone the project repository:
```bash
git clone --recurse-submodules https://github.com/libmonero/monero-python.git
Expand Down
6 changes: 6 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging

from os import environ
from os.path import splitext
from typing import TYPE_CHECKING, Generator, Optional, cast

Expand Down Expand Up @@ -31,6 +32,11 @@ def pytest_runtest_logreport(report: pytest.TestReport) -> None:


def pytest_configure(config: pytest.Config) -> None:
# a job re-run with "Enable debug logging" sets RUNNER_DEBUG=1, show the debug messages in the console too
if environ.get("RUNNER_DEBUG") == "1":
config.option.log_level = "DEBUG"
config.option.log_cli_level = "DEBUG"

# timestamp the log file so each run keeps its own
log_file: str = cast(str, config.getini("log_file"))
if not log_file:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies = []
[build-system]
requires = [
"scikit-build-core>=0.10",
"pybind11>=2.12",
"pybind11>=2.12,<3",
"cmake>=3.20",
"ninja"
]
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pytest]
minversion = 6.0
minversion = 9.0
required_plugins = pytest-rerunfailures pytest-timeout pytest-cov
addopts = -s -v --reruns 5 --reruns-delay 10 --only-rerun "Daemon is busy"
log_level = INFO
Expand Down
14 changes: 14 additions & 0 deletions requirements-build.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# The versions of the python tools that build the module, in CI and locally: pip install -r requirements-build.txt
# Dependabot proposes the updates, except pybind11 which stays at 2.x (see .github/dependabot.yml).
#
# pybind11 is 2.13.6 on every platform, the one of the MSYS2 package that Windows installs with pacman, so it is not here for Windows. The
# deb packages build with the pybind11 of their distribution, which is 2.x from jammy (2.9) to trixie (2.13).
pybind11==2.13.6; sys_platform != "win32"
# not newer, a new version can report more (see bin/lint_bindings.py)
pybind11-stubgen==2.5.5; sys_platform != "win32"
scikit-build-core==1.1.2
setuptools==84.2.1
wheel==0.48.0
# repair the wheels
delvewheel==1.13.2; sys_platform == "win32"
delocate==0.13.0; sys_platform == "darwin"
8 changes: 8 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The versions that the tests run with, in CI (.github/workflows/test.yml) and locally: pip install -r tests/requirements.txt
# Dependabot proposes the updates.
coverage==7.17.3
pytest==9.2.0
pytest-cov==7.1.0
pytest-rerunfailures==16.7
pytest-timeout==2.4.0
typing_extensions==4.16.0
3 changes: 2 additions & 1 deletion tests/test_monero_daemon_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class TestMoneroDaemonInterface(BaseTestClass):
"""Daemon interface bindings unit tests."""

@pytest.fixture(scope="class")
def daemon(self) -> MoneroDaemon:
@classmethod
def daemon(cls) -> MoneroDaemon:
"""Test daemon interface instance."""
return MoneroDaemon()

Expand Down
12 changes: 7 additions & 5 deletions tests/test_monero_daemon_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@ def before_all(self) -> None:
IntegrationTestUtils.setup(WalletType.RPC)

@pytest.fixture(scope="class")
def daemon(self) -> MoneroDaemonRpc:
@classmethod
def daemon(cls) -> MoneroDaemonRpc:
"""Test rpc daemon instance"""
return Utils.get_daemon_rpc()

@pytest.fixture(scope="class")
def wallet(self) -> MoneroWalletRpc:
@classmethod
def wallet(cls) -> MoneroWalletRpc:
"""Test rpc wallet instance"""
if self._test_wallet is None:
self._test_wallet = Utils.get_wallet_rpc()
if cls._test_wallet is None:
cls._test_wallet = Utils.get_wallet_rpc()

return self._test_wallet
return cls._test_wallet

#endregion

Expand Down
10 changes: 6 additions & 4 deletions tests/test_monero_rpc_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ class TestMoneroRpcConnection(BaseTestClass):

# Node rpc connection fixture
@pytest.fixture(scope="class")
def node_connection(self) -> MoneroRpcConnection:
@classmethod
def node_connection(cls) -> MoneroRpcConnection:
"""Rpc connection test instance."""
return MoneroRpcConnection(Utils.DAEMON_RPC_URI, Utils.DAEMON_RPC_USERNAME, Utils.DAEMON_RPC_PASSWORD, timeout_ms=self.TIMEOUT_MS)
return MoneroRpcConnection(Utils.DAEMON_RPC_URI, Utils.DAEMON_RPC_USERNAME, Utils.DAEMON_RPC_PASSWORD, timeout_ms=cls.TIMEOUT_MS)

# Wallet rpc connection fixture
@pytest.fixture(scope="class")
def wallet_connection(self) -> MoneroRpcConnection:
@classmethod
def wallet_connection(cls) -> MoneroRpcConnection:
"""Rpc connection test instance."""
return MoneroRpcConnection(Utils.WALLET_RPC_URI, Utils.WALLET_RPC_USERNAME, Utils.WALLET_RPC_PASSWORD, timeout_ms=self.TIMEOUT_MS)
return MoneroRpcConnection(Utils.WALLET_RPC_URI, Utils.WALLET_RPC_USERNAME, Utils.WALLET_RPC_PASSWORD, timeout_ms=cls.TIMEOUT_MS)

#endregion

Expand Down
3 changes: 2 additions & 1 deletion tests/test_monero_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def parse(cls, parser: ConfigParser) -> TestMoneroUtils.Config:
#region Fixtures

@pytest.fixture(scope="class")
def config(self) -> TestMoneroUtils.Config:
@classmethod
def config(cls) -> TestMoneroUtils.Config:
parser: ConfigParser = ConfigParser()
parser.read('tests/config/test_monero_utils.ini')
return TestMoneroUtils.Config.parse(parser)
Expand Down
9 changes: 6 additions & 3 deletions tests/test_monero_wallet_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,24 @@ def is_random_wallet_config(cls, config: Optional[MoneroWalletConfig]) -> bool:

# Test wallet configuration
@pytest.fixture(scope="class")
def test_config(self) -> BaseTestMoneroWallet.Config:
@classmethod
def test_config(cls) -> BaseTestMoneroWallet.Config:
"""Test configuration."""
parser: ConfigParser = ConfigParser()
parser.read('tests/config/test_monero_wallet_common.ini')
return BaseTestMoneroWallet.Config.parse(parser)

# Test daemon fixture
@pytest.fixture(scope="class")
def daemon(self) -> MoneroDaemonRpc:
@classmethod
def daemon(cls) -> MoneroDaemonRpc:
"""Test rpc daemon instance."""
return TestUtils.get_daemon_rpc()

# Test wallet fixture
@pytest.fixture(scope="class")
def wallet(self) -> MoneroWallet:
@classmethod
def wallet(cls) -> MoneroWallet:
"""Test wallet instance."""
pytest.skip("No wallet test instance setup")

Expand Down
6 changes: 4 additions & 2 deletions tests/test_monero_wallet_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def get_wallet_type(cls) -> WalletType:
return WalletType.FULL

@pytest.fixture(scope="class")
@classmethod
@override
def wallet(self) -> MoneroWalletFull:
def wallet(cls) -> MoneroWalletFull:
"""Test rpc wallet instance"""
return Utils.get_wallet_full()

Expand Down Expand Up @@ -710,7 +711,8 @@ class TestMoneroWalletFullOffline(BaseTestClass):
"""Full wallet unit tests that run against a disconnected wallet, no daemon needed."""

@pytest.fixture(scope="class")
def wallet(self) -> MoneroWalletFull:
@classmethod
def wallet(cls) -> MoneroWalletFull:
"""Shared disconnected full wallet."""
return Utils.get_wallet_full_offline()

Expand Down
3 changes: 2 additions & 1 deletion tests/test_monero_wallet_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class TestMoneroWalletInterface(BaseTestClass):
"""Wallet interface binding calls unit tests."""

@pytest.fixture(scope="class")
def wallet(self) -> MoneroWallet:
@classmethod
def wallet(cls) -> MoneroWallet:
"""Test wallet instance."""
return MoneroWallet()

Expand Down
6 changes: 4 additions & 2 deletions tests/test_monero_wallet_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ class TestMoneroWalletKeys(BaseTestMoneroWallet):
#region Fixtures

@pytest.fixture(scope="class")
@classmethod
@override
def wallet(self) -> MoneroWalletKeys:
def wallet(cls) -> MoneroWalletKeys:
"""Test keys wallet instance"""
return Utils.get_wallet_keys()

@pytest.fixture(scope="class")
@classmethod
@override
def daemon(self) -> MoneroDaemonRpc:
def daemon(cls) -> MoneroDaemonRpc:
return MoneroDaemon() # type: ignore

#endregion
Expand Down
5 changes: 3 additions & 2 deletions tests/test_monero_wallet_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ def get_wallet_type(cls) -> WalletType:
#region Overrides

@pytest.fixture(scope="class")
@classmethod
@override
def wallet(self) -> MoneroWalletRpc:
def wallet(cls) -> MoneroWalletRpc:
"""Test rpc wallet instance."""
return self.get_test_wallet()
return cls.get_test_wallet()

@classmethod
@override
Expand Down
Loading
Loading