From 523802c08c9353e8f0add872fd1f7dcb7aea82eb Mon Sep 17 00:00:00 2001 From: Matthieu Dorier Date: Mon, 10 Jun 2024 13:30:09 +0100 Subject: [PATCH] added python tests for provider --- python/mochi/flock/server.py | 2 +- python/mochi/flock/test_client.py | 1 + python/mochi/flock/test_provider.py | 26 ++++++++++++++++++++++++++ python/src/py-flock-server.cpp | 2 +- 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 python/mochi/flock/test_provider.py diff --git a/python/mochi/flock/server.py b/python/mochi/flock/server.py index 5eac9d6..0d60f39 100644 --- a/python/mochi/flock/server.py +++ b/python/mochi/flock/server.py @@ -23,4 +23,4 @@ class Provider: def __init__(self, engine: pymargo.core.Engine, provider_id: int, config: str, initial_view: GroupView): self._internal = pyflock_server.Provider( - self._engine.get_internal_mid(), provider_id, config, initial_view) + engine.get_internal_mid(), provider_id, config, initial_view) diff --git a/python/mochi/flock/test_client.py b/python/mochi/flock/test_client.py index 4535fb5..6f316cf 100644 --- a/python/mochi/flock/test_client.py +++ b/python/mochi/flock/test_client.py @@ -2,6 +2,7 @@ import mochi.flock.client as mfc from pymargo.core import Engine + class TestClient(unittest.TestCase): def test_init_client_from_address(self): diff --git a/python/mochi/flock/test_provider.py b/python/mochi/flock/test_provider.py new file mode 100644 index 0000000..d6316bb --- /dev/null +++ b/python/mochi/flock/test_provider.py @@ -0,0 +1,26 @@ +import unittest +import json +import mochi.flock.server as mfs +import mochi.flock.view as view +import pymargo.core + +class TestClient(unittest.TestCase): + + def test_init_provider(self): + with pymargo.core.Engine("na+sm", pymargo.core.server) as engine: + address = str(engine.address) + config = { + "group": { + "type": "static", + "config": {} + } + } + initial_view = view.GroupView() + initial_view.members.add(address, 42) + provider = mfs.Provider(engine, 42, json.dumps(config), initial_view) + del provider + engine.finalize() + + +if __name__ == '__main__': + unittest.main() diff --git a/python/src/py-flock-server.cpp b/python/src/py-flock-server.cpp index d02b111..d518cb6 100644 --- a/python/src/py-flock-server.cpp +++ b/python/src/py-flock-server.cpp @@ -19,7 +19,7 @@ typedef py11::capsule pyhg_addr_t; #define MID2CAPSULE(__mid) py11::capsule((void*)(__mid), "margo_instance_id") #define CAPSULE2MID(__caps) (margo_instance_id)(__caps) -PYBIND11_MODULE(pybedrock_server, m) { +PYBIND11_MODULE(pyflock_server, m) { m.doc() = "Flock server python extension"; py11::class_(m, "Provider")