Skip to content

Commit 3815368

Browse files
Improve tests code
* Refactory interface tests * Setup test fixtures for wallets and daemon * Setup marker `not_supported` in `conftest.py` * Setup `unit` and `integration` test markers * Fix `py_monero_wallet` bindings
1 parent b3ee7b6 commit 3815368

17 files changed

Lines changed: 1436 additions & 1799 deletions

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,11 @@ jobs:
235235
done
236236
cd ..
237237
238-
- name: Run tests
238+
- name: Run unit tests
239239
shell: bash
240240
env:
241241
IN_CONTAINER: "true"
242242
PYTHONPATH: ${{ github.workspace }}/dist
243243
PATH: "${{ github.workspace }}/dist:/usr/bin:$PATH"
244244
run: |
245-
python -m pytest
245+
python -m pytest -m unit

conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
3+
from monero import MoneroError
4+
5+
def pytest_runtest_call(item: pytest.Item):
6+
# get not_supported marked
7+
marker = item.get_closest_marker("not_supported")
8+
if marker is None:
9+
# marked not found
10+
return
11+
12+
try:
13+
# run test
14+
item.runtest()
15+
except MoneroError as e:
16+
e_str = str(e).lower()
17+
if "not supported" in e_str or "does not support" in e_str:
18+
# Ok
19+
pytest.xfail(str(e))
20+
raise
21+
else:
22+
# fail test
23+
pytest.fail("Expected test to fail")

pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ log_cli_level = INFO
77
console_output_style = progress
88
testpaths =
99
tests
10+
markers =
11+
unit: fast unit tests, no external dependencies
12+
integration: slow integration tests, requires external services
13+
not_supported: expects not supported error

src/cpp/py_monero.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,19 +1538,7 @@ PYBIND11_MODULE(monero, m) {
15381538
MONERO_CATCH_AND_RETHROW(self.remove_listener(listener));
15391539
}, py::arg("listener"))
15401540
.def("get_listeners", [](PyMoneroWallet& self) {
1541-
try {
1542-
std::set<monero::monero_wallet_listener*> listeners = self.get_listeners();
1543-
std::vector<std::shared_ptr<monero::monero_wallet_listener>> result(listeners.size());
1544-
1545-
for(auto listener : listeners) {
1546-
result.emplace_back(listener);
1547-
}
1548-
1549-
return result;
1550-
}
1551-
catch (const std::exception& e) {
1552-
throw py::value_error(e.what());
1553-
}
1541+
MONERO_CATCH_AND_RETHROW(self.get_listeners());
15541542
})
15551543
.def("sync", [](PyMoneroWallet& self) {
15561544
MONERO_CATCH_AND_RETHROW(self.sync());
@@ -1800,9 +1788,13 @@ PYBIND11_MODULE(monero, m) {
18001788
MONERO_CATCH_AND_RETHROW(self.parse_payment_uri(uri));
18011789
}, py::arg("uri"))
18021790
.def("get_attribute", [](PyMoneroWallet& self, const std::string& key) {
1803-
std::string val;
1804-
self.get_attribute(key, val);
1805-
return val;
1791+
try {
1792+
std::string val;
1793+
self.get_attribute(key, val);
1794+
return val;
1795+
} catch (const std::exception& ex) {
1796+
throw PyMoneroError(ex.what());
1797+
}
18061798
}, py::arg("key"))
18071799
.def("set_attribute", [](PyMoneroWallet& self, const std::string& key, const std::string& val) {
18081800
MONERO_CATCH_AND_RETHROW(self.set_attribute(key, val));
@@ -1856,7 +1848,7 @@ PYBIND11_MODULE(monero, m) {
18561848
MONERO_CATCH_AND_RETHROW(self.save());
18571849
})
18581850
.def("close", [](monero::monero_wallet& self, bool save) {
1859-
self.close(save);
1851+
MONERO_CATCH_AND_RETHROW(self.close(save));
18601852
}, py::arg("save") = false);
18611853

18621854
// monero_wallet_keys

src/cpp/wallet/py_monero_wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class PyMoneroWallet : public monero::monero_wallet {
179179
void remove_listener(monero_wallet_listener& listener) override {
180180
m_listeners.erase(&listener);
181181
}
182-
182+
183183
std::set<monero_wallet_listener*> get_listeners() override {
184184
return m_listeners;
185185
}

tests/test_monero_connection_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
logger: logging.Logger = logging.getLogger("TestMoneroConnectionManager")
1111

1212
# TODO enable connection manager tests
13-
@pytest.mark.skipif(True, reason="TODO")
13+
@pytest.mark.skip(reason="TODO")
14+
@pytest.mark.integration
1415
class TestMoneroConnectionManager:
16+
"""Connection manager integration tests"""
1517

1618
@pytest.fixture(autouse=True)
1719
def setup_and_teardown(self, request: pytest.FixtureRequest):

0 commit comments

Comments
 (0)