Skip to content

Commit b8f7724

Browse files
committed
Closes #266
1 parent 48b7a36 commit b8f7724

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

src/Dataflow/Engine/Python/Tests/NetworkEditorPythonAPITests.cc

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,20 @@
3131
#include <Dataflow/Engine/Controller/NetworkEditorController.h>
3232
#include <Dataflow/Network/ConnectionId.h>
3333
#include <Core/Python/PythonInterpreter.h>
34+
#include <Modules/Legacy/Fields/CreateLatVol.h>
35+
#include <Dataflow/State/SimpleMapModuleState.h>
36+
#include <Dataflow/Engine/Scheduler/DesktopExecutionStrategyFactory.h>
3437

3538
using namespace SCIRun;
3639
using namespace Core;
3740
using namespace Testing;
3841
using namespace Modules::Factory;
42+
using namespace Modules::Fields;
3943
using namespace Dataflow::Networks;
44+
using namespace Dataflow::Engine;
4045
using namespace ReplacementImpl;
4146
using namespace Dataflow::Engine;
47+
using namespace Dataflow::State;
4248
using namespace Algorithms;
4349

4450
class PythonControllerFunctionalTests : public ModuleTest
@@ -51,7 +57,6 @@ class PythonControllerFunctionalTests : public ModuleTest
5157
}
5258
};
5359

54-
5560
TEST_F(PythonControllerFunctionalTests, CanAddModule)
5661
{
5762
ModuleFactoryHandle mf(new HardCodedModuleFactory);
@@ -62,7 +67,82 @@ TEST_F(PythonControllerFunctionalTests, CanAddModule)
6267

6368
std::string command = "addModule(\"CreateLatVol\")";
6469
PythonInterpreter::Instance().run_string(command);
70+
//TODO: expose API directly on NEC?
6571
//controller.runPython("addModule(\"CreateLatVol\")");
6672

6773
ASSERT_EQ(1, controller.getNetwork()->nmodules());
74+
}
75+
76+
TEST_F(PythonControllerFunctionalTests, CanAddMultipleModule)
77+
{
78+
ModuleFactoryHandle mf(new HardCodedModuleFactory);
79+
NetworkEditorController controller(mf, nullptr, nullptr, nullptr, nullptr);
80+
initModuleParameters(false);
81+
82+
ASSERT_EQ(0, controller.getNetwork()->nmodules());
83+
84+
std::string command = "addModule(\"CreateLatVol\")";
85+
PythonInterpreter::Instance().run_string(command);
86+
PythonInterpreter::Instance().run_string(command);
87+
88+
ASSERT_EQ(2, controller.getNetwork()->nmodules());
89+
}
90+
91+
TEST_F(PythonControllerFunctionalTests, CanChangeModuleState)
92+
{
93+
ModuleFactoryHandle mf(new HardCodedModuleFactory);
94+
ModuleStateFactoryHandle sf(new SimpleMapModuleStateFactory);
95+
NetworkEditorController controller(mf, sf, nullptr, nullptr, nullptr);
96+
initModuleParameters(false);
97+
98+
ASSERT_EQ(0, controller.getNetwork()->nmodules());
99+
100+
std::string command = "m = addModule(\"CreateLatVol\")";
101+
PythonInterpreter::Instance().run_string(command);
102+
103+
ASSERT_EQ(1, controller.getNetwork()->nmodules());
104+
auto mod = controller.getNetwork()->module(0);
105+
ASSERT_TRUE(mod != nullptr);
106+
EXPECT_EQ(16, mod->get_state()->getValue(CreateLatVol::XSize).toInt());
107+
command = "m.XSize = 14";
108+
PythonInterpreter::Instance().run_string(command);
109+
EXPECT_EQ(14, mod->get_state()->getValue(CreateLatVol::XSize).toInt());
110+
}
111+
112+
TEST_F(PythonControllerFunctionalTests, CanConnectModules)
113+
{
114+
ModuleFactoryHandle mf(new HardCodedModuleFactory);
115+
NetworkEditorController controller(mf, nullptr, nullptr, nullptr, nullptr);
116+
initModuleParameters(false);
117+
118+
ASSERT_EQ(0, controller.getNetwork()->nmodules());
119+
120+
PythonInterpreter::Instance().run_string("m1 = addModule(\"CreateLatVol\")");
121+
PythonInterpreter::Instance().run_string("m2 = addModule(\"CreateLatVol\")");
122+
123+
ASSERT_EQ(2, controller.getNetwork()->nmodules());
124+
125+
ASSERT_EQ(0, controller.getNetwork()->nconnections());
126+
127+
PythonInterpreter::Instance().run_string("m1.output[0] >> m2.input[0]");
128+
ASSERT_EQ(1, controller.getNetwork()->nconnections());
129+
}
130+
131+
//TODO: this test is unstable
132+
TEST_F(PythonControllerFunctionalTests, DISABLED_CanExecuteNetwork)
133+
{
134+
ModuleFactoryHandle mf(new HardCodedModuleFactory);
135+
ModuleStateFactoryHandle sf(new SimpleMapModuleStateFactory);
136+
ExecutionStrategyFactoryHandle exe(new DesktopExecutionStrategyFactory(boost::none));
137+
NetworkEditorController controller(mf, sf, exe, nullptr, nullptr);
138+
initModuleParameters(false);
139+
140+
PythonInterpreter::Instance().run_string("m1 = addModule(\"CreateLatVol\")");
141+
ASSERT_TRUE(controller.getNetwork()->module(0)->executionState().currentState() == ModuleExecutionState::NotExecuted);
142+
PythonInterpreter::Instance().run_string("m2 = addModule(\"CreateLatVol\")");
143+
PythonInterpreter::Instance().run_string("m1.output[0] >> m2.input[0]");
144+
PythonInterpreter::Instance().run_string("executeAll()");
145+
// boost::this_thread::sleep(boost::posix_time::milliseconds(500));
146+
ASSERT_TRUE(controller.getNetwork()->module(0)->executionState().currentState() == ModuleExecutionState::Completed);
147+
//TODO: how do i assert on
68148
}

0 commit comments

Comments
 (0)