def test_filter_types_tests_core_fitler_registration(): core1 = h.helicsCreateCore("inproc", "core1", "--autobroker") core2 = h.helicsCoreClone(core1) core1IdentifierString = h.helicsCoreGetIdentifier(core1) assert core1IdentifierString == "core1" sourceFilter1 = h.helicsCoreRegisterFilter(core1, h.HELICS_FILTER_TYPE_DELAY, "core1SourceFilter") h.helicsFilterAddSourceTarget(sourceFilter1, "ep1") destinationFilter1 = h.helicsCoreRegisterFilter(core1, h.HELICS_FILTER_TYPE_DELAY, "core1DestinationFilter") h.helicsFilterAddDestinationTarget(destinationFilter1, "ep2") cloningFilter1 = h.helicsCoreRegisterCloningFilter(core1, "ep3") h.helicsFilterRemoveDeliveryEndpoint(cloningFilter1, "ep3") core1IsConnected = h.helicsCoreIsConnected(core1) assert core1IsConnected != 0 h.helicsCoreSetReadyToInit(core1) h.helicsCoreDisconnect(core1) h.helicsCoreDisconnect(core2) h.helicsCoreFree(core1) h.helicsCoreFree(core2) h.helicsCloseLibrary()
def test_federate_tests_federateGeneratedGlobalError(): brk = h.helicsCreateBroker("inproc", "gbrokerc", "--root") cr = h.helicsCreateCore("inproc", "gcore", "--broker=gbrokerc") argv = ["", "--corename=gcore"] fi = h.helicsCreateFederateInfo() h.helicsFederateInfoLoadFromArgs(fi, argv) fed1 = h.helicsCreateValueFederate("fed0", fi) h.helicsFederateInfoFree(fi) h.helicsFederateEnterExecutingMode(fed1) h.helicsFederateRequestTime(fed1, 2.0) h.helicsFederateGlobalError(fed1, 9827, "user generated global error") with pt.raises(h.HelicsException): h.helicsFederateRequestTime(fed1, 3.0) h.helicsFederateDestroy(fed1) h.helicsCoreDisconnect(cr) h.helicsBrokerDisconnect(brk) h.helicsCloseLibrary()
def test_core_api(): core1 = h.helicsCreateCore("inproc", "core1", "--autobroker") assert h.helicsCoreIsValid(core1) is True core2 = h.helicsCoreClone(core1) assert "core1" in h.helicsCoreGetIdentifier(core1) assert h.helicsCoreIsConnected(core1) == 0 sourceFilter1 = h.helicsCoreRegisterFilter(core1, h.HELICS_FILTER_TYPE_DELAY, "core1SourceFilter") h.helicsFilterAddSourceTarget(sourceFilter1, "ep1") destinationFilter1 = h.helicsCoreRegisterFilter(core1, h.HELICS_FILTER_TYPE_DELAY, "core1DestinationFilter") h.helicsFilterAddDestinationTarget(destinationFilter1, "ep2") cloningFilter1 = h.helicsCoreRegisterCloningFilter(core1, "ep3") h.helicsFilterRemoveDeliveryEndpoint(cloningFilter1, "ep3") h.helicsCoreSetReadyToInit(core1) h.helicsCoreDisconnect(core1) h.helicsCoreDisconnect(core2) h.helicsCoreFree(core1) h.helicsCoreFree(core2) h.helicsCloseLibrary()
def test_system_tests_federate_logging(): lfile = "log.txt" rm(lfile, force=True) core = h.helicsCreateCore("inproc", "clogf", "--autobroker --log_level=trace") fi = h.helicsCreateFederateInfo() h.helicsFederateInfoSetBrokerKey(fi, "key") h.helicsFederateInfoSetCoreName(fi, "clogf") fed = h.helicsCreateValueFederate("f1", fi) h.helicsFederateSetLogFile(fed, lfile) h.helicsFederateLogLevelMessage(fed, 7, "hello") h.helicsFederateLogErrorMessage(fed, "hello") h.helicsFederateLogDebugMessage(fed, "hello") h.helicsFederateLogWarningMessage(fed, "hello") h.helicsFederateClearMessages(fed) h.helicsCoreSetLogFile(core, lfile) h.helicsCoreDisconnect(core) h.helicsFederateFinalize(fed) h.helicsFederateInfoFree(fi) h.helicsCloseLibrary() assert isfile(lfile) rm(lfile, force=True)
def test_broker_test_make_core_connections(broker): cr = h.helicsCreateCoreFromArgs("zmq", "gcore", ["--broker=gbrokertest"]) assert h.helicsCoreGetIdentifier(cr) == "gcore" with pt.raises(h.HelicsException): h.helicsCoreMakeConnections(cr, "invalidfile.json") h.helicsCoreDisconnect(cr)
def test_system_tests_core_logging(): lfile = "log.txt" rm(lfile, force=True) core = h.helicsCreateCore("inproc", "clog", "--autobroker --log_level=trace") h.helicsCoreSetLogFile(core, lfile) h.helicsCoreDisconnect(core) h.helicsCloseLibrary() assert isfile(lfile) rm(lfile, force=True)
def test_other_tests_core_creation(broker): cr = h.helicsCreateCoreFromArgs("zmq", "gcore", ["--broker=gbrokertest"]) assert h.helicsCoreGetIdentifier(cr) == "gcore" # TODO: why is this not raising an exception? with pt.raises(h.HelicsException): cr2 = h.helicsCreateCoreFromArgs( "test", "gcore2", ["--broker=gbrokerc", "--log-level=what_logs?"]) h.helicsCoreDisconnect(cr)
def test_system_test_federate_global_value(): brk = h.helicsCreateBroker("inproc", "gbrokerc", "--root") cr = h.helicsCreateCore("inproc", "gcore", "--broker=gbrokerc") argv = ["", "--corename=gcore"] fi = h.helicsCreateFederateInfo() h.helicsFederateInfoLoadFromArgs(fi, argv) fed = h.helicsCreateValueFederate("fed0", fi) fi2 = h.helicsFederateInfoClone(fi) h.helicsFederateInfoFree(fi2) h.helicsFederateInfoFree(fi) globalVal = "this is a string constant that functions as a global" globalVal2 = "this is a second string constant that functions as a global" h.helicsFederateSetGlobal(fed, "testglobal", globalVal) q = h.helicsCreateQuery("global", "testglobal") res = h.helicsQueryExecute(q, fed) assert res == globalVal h.helicsFederateSetGlobal(fed, "testglobal2", globalVal2) h.helicsQueryFree(q) q = h.helicsCreateQuery("global", "testglobal2") h.helicsQueryExecuteAsync(q, fed) while h.helicsQueryIsCompleted(q) is False: time.sleep(0.20) res = h.helicsQueryExecuteComplete(q) assert res == globalVal2 q2 = h.helicsCreateQuery("", "isinit") h.helicsQueryExecuteAsync(q2, fed) while h.helicsQueryIsCompleted(q2) is False: time.sleep(0.20) res = h.helicsQueryExecuteComplete(q2) assert str(res).lower() == "false" h.helicsFederateFinalize(fed) h.helicsCoreDisconnect(cr) h.helicsBrokerDisconnect(brk) h.helicsQueryFree(q) h.helicsQueryFree(q2) assert h.helicsBrokerIsConnected(brk) is False h.helicsBrokerDisconnect(brk) h.helicsCoreDisconnect(cr) assert h.helicsBrokerIsConnected(brk) is False h.helicsCloseLibrary()
def test_system_test_core_global_value1(): brk = h.helicsCreateBroker("zmq", "gbrokerc", "--root") cr = h.helicsCreateCore("zmq", "gcore", "--broker=gbrokerc") globalVal = "this is a string constant that functions as a global" _ = "this is a second string constant that functions as a global" h.helicsCoreSetGlobal(cr, "testglobal", globalVal) # q = h.helicsCreateQuery("global", "testglobal") # TODO: This hangs on core execute # res = h.helicsQueryCoreExecute(q, cr) # assert res == globalVal # h.helicsQueryFree(q) # @test_broken False h.helicsCoreDisconnect(cr) h.helicsBrokerDisconnect(brk) assert h.helicsBrokerIsConnected(brk) is False h.helicsCloseLibrary()
def test_system_test_core_global_value2(): brk = h.helicsCreateBroker("zmq", "gbrokerc", "--root") cr = h.helicsCreateCore("zmq", "gcore", "--broker=gbrokerc") connected = h.helicsCoreConnect(cr) assert connected == True assert h.helicsCoreIsConnected(cr) == True globalVal = "this is a string constant that functions as a global" globalVal2 = "this is a second string constant that functions as a global" h.helicsCoreSetGlobal(cr, "testglobal", globalVal) q = h.helicsCreateQuery("global", "testglobal") res = h.helicsQueryCoreExecute(q, cr) assert res == globalVal h.helicsCoreSetGlobal(cr, "testglobal2", globalVal2) h.helicsQueryFree(q) q = h.helicsCreateQuery("global", "testglobal2") res = h.helicsQueryCoreExecute(q, cr) assert res == globalVal2 h.helicsBrokerDisconnect(brk) h.helicsCoreDisconnect(cr) h.helicsQueryFree(q) assert h.helicsBrokerIsConnected(brk) == False