From 679bd66db2fd13c1541762f05de8c20a1b12ea32 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Tue, 14 Dec 2021 12:18:35 -0800 Subject: [PATCH 01/12] add names to some of the core tests in case the brokers haven't been completely cleared by the start of the next test --- tests/test_filters.py | 2 +- tests/test_python_api.py | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/test_filters.py b/tests/test_filters.py index 560c9dcb..e41dd354 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -112,7 +112,7 @@ def test_filter_type_tests_info(): destroyBroker(broker) -def test_filter_types_tests_core_fitler_registration(): +def test_filter_types_tests_core_filter_registration(): core1 = h.helicsCreateCore("inproc", "core1", "--autobroker") diff --git a/tests/test_python_api.py b/tests/test_python_api.py index 85e9249a..48616b4d 100644 --- a/tests/test_python_api.py +++ b/tests/test_python_api.py @@ -13,12 +13,12 @@ def test_python_api0(): - broker = h.helicsCreateBroker("zmq", "", "-f 1 --name=mainbroker") + broker = h.helicsCreateBroker("zmq", "", "-f 1 --name=mainbroker0") fedinfo = h.helicsCreateFederateInfo() assert "HelicsFederateInfo()" in repr(fedinfo) fedinfo.core_name = "TestFederate" fedinfo.core_type = "zmq" - fedinfo.core_init = "-f 1 --broker=mainbroker" + fedinfo.core_init = "-f 1 --broker=mainbroker0 --name=core0" mFed = h.helicsCreateCombinationFederate("TestFederate", fedinfo) assert ( @@ -64,12 +64,12 @@ def test_python_api0(): def test_python_api1(): - broker = h.helicsCreateBroker("zmq", "", "-f 1 --name=mainbroker") + broker = h.helicsCreateBroker("zmq", "", "-f 1 --name=mainbroker1") fedinfo = h.helicsCreateFederateInfo() assert "HelicsFederateInfo()" in repr(fedinfo) fedinfo.core_name = "TestFederate" fedinfo.core_type = "zmq" - fedinfo.core_init = "-f 1 --broker=mainbroker" + fedinfo.core_init = "-f 1 --broker=mainbroker1 --name=core0" mFed = h.helicsCreateCombinationFederate("TestFederate", fedinfo) assert ( @@ -261,7 +261,7 @@ def test_python_api1(): def test_python_api2(): - broker = h.helicsCreateBroker("zmq", "broker", "--federates 1 --loglevel=warning") + broker = h.helicsCreateBroker("zmq", "broker", "--federates 1 --loglevel=warning --name=mainbroker2") assert broker.is_connected() broker.set_global("hello", "world") @@ -275,7 +275,7 @@ def test_python_api2(): assert broker.query("hello", "world") == {"error": {"code": 404, "message": "query not valid"}} fi = h.helicsCreateFederateInfo() - fi.core_init = "--federates 1" + fi.core_init = "--federates 1 --brokername=mainbroker2 --name=core2" fi.property[h.HELICS_PROPERTY_INT_LOG_LEVEL] = 2 fed = h.helicsCreateCombinationFederate("test1", fi) @@ -431,15 +431,15 @@ def test_python_api2(): def test_python_api3(): - core1 = h.helicsCreateCore("inproc", "core1", "--autobroker") + core1 = h.helicsCreateCore("inproc", "core3", "--autobroker") - assert """HelicsCore(identifier = "core1", address = "core1")""" in repr(core1) + assert """HelicsCore(identifier = "core3", address = "core1")""" in repr(core1) core2 = core1.clone() - assert core1.identifier == "core1" + assert core1.identifier == "core3" - source_filter1 = core1.register_filter(h.HELICS_FILTER_TYPE_DELAY, "core1SourceFilter") + source_filter1 = core1.register_filter(h.HELICS_FILTER_TYPE_DELAY, "core3SourceFilter") source_filter1.add_source_target("ep1") @@ -499,7 +499,7 @@ def test_python_api4(): def test_python_api5(): - broker = h.helicsCreateBroker("zmq", "broker", "--federates 1") + broker = h.helicsCreateBroker("zmq", "broker", "--federates 1 --name=mainbroker5") fi = h.helicsCreateFederateInfo() fed = h.helicsCreateCombinationFederate("test1", fi) @@ -522,7 +522,7 @@ def test_python_api5(): def test_python_api6(): - broker = h.helicsCreateBroker("zmq", "broker", "--federates 1") + broker = h.helicsCreateBroker("zmq", "broker", "--federates 1 --name=mainbroker6") fi = h.helicsCreateFederateInfo() fed = h.helicsCreateCombinationFederate("test1", fi) @@ -544,7 +544,7 @@ def test_python_api6(): @pt.mark.skip(reason="Fails to pass on windows and linux") def test_python_api7(): - broker = h.helicsCreateBroker("zmq", "broker", "--federates 1") + broker = h.helicsCreateBroker("zmq", "broker", "--federates 1 --name=mainbroker7") fi = h.helicsCreateFederateInfo() fed = h.helicsCreateCombinationFederate("test1", fi) @@ -607,7 +607,7 @@ def test_python_api7(): def test_python_api8(): - broker = h.helicsCreateBroker("zmq", "", "-f 1 --name=mainbroker") + broker = h.helicsCreateBroker("zmq", "", "-f 1 --name=mainbroker8") cfed = h.helicsCreateCombinationFederateFromConfig(os.path.join(CURRENT_DIRECTORY, "combinationfederate.json")) From 66a258f4491f42dbe4d608b4e23b16ccd8d11931 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Tue, 14 Dec 2021 12:23:20 -0800 Subject: [PATCH 02/12] fix test3 --- tests/test_python_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_python_api.py b/tests/test_python_api.py index 48616b4d..cd07ad73 100644 --- a/tests/test_python_api.py +++ b/tests/test_python_api.py @@ -433,7 +433,7 @@ def test_python_api2(): def test_python_api3(): core1 = h.helicsCreateCore("inproc", "core3", "--autobroker") - assert """HelicsCore(identifier = "core3", address = "core1")""" in repr(core1) + assert """HelicsCore(identifier = "core3", address = "core3")""" in repr(core1) core2 = core1.clone() From 9de07082ae5481d36aa002f6689d3c9db28ebaf5 Mon Sep 17 00:00:00 2001 From: trevorhardy Date: Thu, 24 Aug 2023 12:33:15 -0700 Subject: [PATCH 03/12] Correct copy-paste error for helicsTranslatorGetName --- helics/capi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helics/capi.py b/helics/capi.py index 84c50cdd..844d816b 100644 --- a/helics/capi.py +++ b/helics/capi.py @@ -7269,7 +7269,7 @@ def helicsTranslatorGetName(translator: HelicsTranslator) -> str: **Returns**: A string with the name of the translator. """ - f = loadSym("helicsPublicationGetName") + f = loadSym("helicsTranslatorGetName") result = f(translator.handle) return ffi.string(result).decode() From 6c95a5ca319558b88b2ba6aa3c7b2d4f2bace964 Mon Sep 17 00:00:00 2001 From: trevorhardy Date: Fri, 2 Feb 2024 09:55:51 -0800 Subject: [PATCH 04/12] Add super __init__() for select classes Several classes that were inheriting from "_HelicsCHandle" had no proper init and thus were not able to be used. Theses now have the same init as their superclass ("_HelicsCHandle") and will be more useful. --- helics/capi.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/helics/capi.py b/helics/capi.py index 844d816b..ddf3d0a9 100644 --- a/helics/capi.py +++ b/helics/capi.py @@ -1392,11 +1392,13 @@ def message_id(self, v): class HelicsQuery(_HelicsCHandle): - pass + def __init__(self, handle, cleanup=False): + super(HelicsQueryBuffer, self).__init__(handle, cleanup class HelicsQueryBuffer(_HelicsCHandle): - pass + def __init__(self, handle, cleanup=False): + super(HelicsQueryBuffer, self).__init__(handle, cleanup) class HelicsEndpoint(_HelicsCHandle): @@ -2823,7 +2825,8 @@ class HelicsCallbackFederate(HelicsCombinationFederate): pass class HelicsDataBuffer(_HelicsCHandle): - pass + def __init__(self, handle, cleanup=False): + super(HelicsQueryBuffer, self).__init__(handle, cleanup class HelicsException(Exception): From 4172f01c92d5f35b62c56ca9bb0580beb22d4180 Mon Sep 17 00:00:00 2001 From: trevorhardy Date: Fri, 2 Feb 2024 12:28:00 -0800 Subject: [PATCH 05/12] Add missing ")" Because Trevor can't copy-and-paste reliably. --- helics/capi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helics/capi.py b/helics/capi.py index ddf3d0a9..768f4924 100644 --- a/helics/capi.py +++ b/helics/capi.py @@ -1393,7 +1393,7 @@ def message_id(self, v): class HelicsQuery(_HelicsCHandle): def __init__(self, handle, cleanup=False): - super(HelicsQueryBuffer, self).__init__(handle, cleanup + super(HelicsQueryBuffer, self).__init__(handle, cleanup) class HelicsQueryBuffer(_HelicsCHandle): @@ -2826,7 +2826,7 @@ class HelicsCallbackFederate(HelicsCombinationFederate): class HelicsDataBuffer(_HelicsCHandle): def __init__(self, handle, cleanup=False): - super(HelicsQueryBuffer, self).__init__(handle, cleanup + super(HelicsQueryBuffer, self).__init__(handle, cleanup) class HelicsException(Exception): From bb8f737ff8b07fdccba52753f790ae66fa0ff460 Mon Sep 17 00:00:00 2001 From: trevorhardy Date: Fri, 2 Feb 2024 12:51:09 -0800 Subject: [PATCH 06/12] Add additional fix for `helicsQueryBufferFill()` Gotta handle strings and pointers properly. --- helics/capi.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/helics/capi.py b/helics/capi.py index 768f4924..0e151c85 100644 --- a/helics/capi.py +++ b/helics/capi.py @@ -9367,7 +9367,8 @@ def helicsQueryBufferFill(buffer: HelicsQueryBuffer, string: str): """ f = loadSym("helicsQueryBufferFill") err = helicsErrorInitialize() - f(buffer.handle, string, len(string), err) + str_ptr = ffi.new('char[]', string.encode('utf-8')) + f(buffer.handle, str_ptr, len(string), err) if err.error_code != 0: raise HelicsException("[" + str(err.error_code) + "] " + ffi.string(err.message).decode()) From 14c1e77f8b19b58bdebd6bf014e1cec9e88c806c Mon Sep 17 00:00:00 2001 From: trevorhardy Date: Fri, 2 Feb 2024 13:03:46 -0800 Subject: [PATCH 07/12] Test change to Python3 version of `super()` --- helics/capi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helics/capi.py b/helics/capi.py index 0e151c85..ac19669a 100644 --- a/helics/capi.py +++ b/helics/capi.py @@ -1398,7 +1398,7 @@ def __init__(self, handle, cleanup=False): class HelicsQueryBuffer(_HelicsCHandle): def __init__(self, handle, cleanup=False): - super(HelicsQueryBuffer, self).__init__(handle, cleanup) + super().__init__(handle, cleanup) class HelicsEndpoint(_HelicsCHandle): From 8c0e63906042648d996e8f5e72001a0af806e234 Mon Sep 17 00:00:00 2001 From: trevorhardy Date: Fri, 2 Feb 2024 13:10:24 -0800 Subject: [PATCH 08/12] Fix copy-paste error for inits --- helics/capi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helics/capi.py b/helics/capi.py index ac19669a..cd3c64db 100644 --- a/helics/capi.py +++ b/helics/capi.py @@ -1398,7 +1398,7 @@ def __init__(self, handle, cleanup=False): class HelicsQueryBuffer(_HelicsCHandle): def __init__(self, handle, cleanup=False): - super().__init__(handle, cleanup) + super(HelicsQueryBuffer, self).__init__(handle, cleanup) class HelicsEndpoint(_HelicsCHandle): @@ -2826,7 +2826,7 @@ class HelicsCallbackFederate(HelicsCombinationFederate): class HelicsDataBuffer(_HelicsCHandle): def __init__(self, handle, cleanup=False): - super(HelicsQueryBuffer, self).__init__(handle, cleanup) + super(HelicsDataBuffer, self).__init__(handle, cleanup) class HelicsException(Exception): From 5fa9f766d8ef09caba708cc29e392673a3a4bba9 Mon Sep 17 00:00:00 2001 From: trevorhardy Date: Fri, 2 Feb 2024 13:15:36 -0800 Subject: [PATCH 09/12] Fix another copy-paste error --- helics/capi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helics/capi.py b/helics/capi.py index cd3c64db..66711d6f 100644 --- a/helics/capi.py +++ b/helics/capi.py @@ -1393,7 +1393,7 @@ def message_id(self, v): class HelicsQuery(_HelicsCHandle): def __init__(self, handle, cleanup=False): - super(HelicsQueryBuffer, self).__init__(handle, cleanup) + super(HelicsQuery, self).__init__(handle, cleanup) class HelicsQueryBuffer(_HelicsCHandle): From 7f30f42f35375232933aa5054657e348a5633573 Mon Sep 17 00:00:00 2001 From: Trevor Hardy Date: Fri, 9 Feb 2024 11:26:29 -0800 Subject: [PATCH 10/12] Update helics/capi.py to use Py v3 super() Co-authored-by: Ryan Mast <3969255+nightlark@users.noreply.github.com> --- helics/capi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helics/capi.py b/helics/capi.py index 66711d6f..95441b1e 100644 --- a/helics/capi.py +++ b/helics/capi.py @@ -1398,7 +1398,7 @@ def __init__(self, handle, cleanup=False): class HelicsQueryBuffer(_HelicsCHandle): def __init__(self, handle, cleanup=False): - super(HelicsQueryBuffer, self).__init__(handle, cleanup) + super().__init__(handle, cleanup) class HelicsEndpoint(_HelicsCHandle): From ce8cf156021710d5e1731a11bd62461a296ea8f8 Mon Sep 17 00:00:00 2001 From: Trevor Hardy Date: Fri, 9 Feb 2024 11:26:45 -0800 Subject: [PATCH 11/12] Update helics/capi.py to use Py v3 super() Co-authored-by: Ryan Mast <3969255+nightlark@users.noreply.github.com> --- helics/capi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helics/capi.py b/helics/capi.py index 95441b1e..fe270bf3 100644 --- a/helics/capi.py +++ b/helics/capi.py @@ -2826,7 +2826,7 @@ class HelicsCallbackFederate(HelicsCombinationFederate): class HelicsDataBuffer(_HelicsCHandle): def __init__(self, handle, cleanup=False): - super(HelicsDataBuffer, self).__init__(handle, cleanup) + super().__init__(handle, cleanup) class HelicsException(Exception): From 3f77ed49e25056f3f803752cc41002f6fae87708 Mon Sep 17 00:00:00 2001 From: Trevor Hardy Date: Fri, 9 Feb 2024 11:26:57 -0800 Subject: [PATCH 12/12] Update helics/capi.py to use Py v3 super() Co-authored-by: Ryan Mast <3969255+nightlark@users.noreply.github.com> --- helics/capi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helics/capi.py b/helics/capi.py index fe270bf3..79251005 100644 --- a/helics/capi.py +++ b/helics/capi.py @@ -1393,7 +1393,7 @@ def message_id(self, v): class HelicsQuery(_HelicsCHandle): def __init__(self, handle, cleanup=False): - super(HelicsQuery, self).__init__(handle, cleanup) + super().__init__(handle, cleanup) class HelicsQueryBuffer(_HelicsCHandle):