Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ostasse/dynamic-graph-python
  • gsaurel/dynamic-graph-python
  • stack-of-tasks/dynamic-graph-python
3 results
Show changes
File moved
import unittest
import dynamic_graph as dg
from custom_entity import CustomEntity
ERR = "dynamic_graph.plug(a, b): Argument '%s' must be of type 'dynamic_graph.Signal', but got dynamic_graph.Entity"
ERR = (
"""Python argument types in
dynamic_graph.wrap.plug(%s, %s)
did not match C++ signature:
plug("""
"dynamicgraph::SignalBase<int>* signalOut, "
"dynamicgraph::SignalBase<int>* signalIn)"
)
class BindingsTests(unittest.TestCase):
def test_bindings(self):
with self.assertRaises(dg.dgpyError) as cm:
dg.error_out()
self.assertEqual(str(cm.exception), "something bad happened")
def test_type_check(self):
"""
test the type checking in signal plugs
"""
first = CustomEntity('first_entity')
second = CustomEntity('second_entity')
first = CustomEntity("first_entity")
second = CustomEntity("second_entity")
# Check that we can connect first.out to second.in
dg.plug(first.signal('out_double'), second.signal('in_double'))
dg.plug(first.signal("out_double"), second.signal("in_double"))
# Check that we can't connect first.out to second
with self.assertRaises(TypeError) as cm_in:
dg.plug(first.signal('out_double'), second)
self.assertEqual(str(cm_in.exception), ERR % 'b')
dg.plug(first.signal("out_double"), second)
self.assertEqual(
str(cm_in.exception), ERR % ("SignalTimeDependentDouble", "CustomEntity")
)
# Check that we can't connect first to second.in
with self.assertRaises(TypeError) as cm_out:
dg.plug(first, second.signal('in_double'))
self.assertEqual(str(cm_out.exception), ERR % 'a')
dg.plug(first, second.signal("in_double"))
self.assertEqual(
str(cm_out.exception), ERR % ("CustomEntity", "SignalPtrDouble")
)
def test_dg_exc(self):
"""
test that exceptions from dynamic graph are correctly raised
"""
ent = CustomEntity('test_dg_exc')
ent = CustomEntity("test_dg_exc")
# check that accessing a non initialized signal raises
with self.assertRaises(dg.dgpyError) as cm:
with self.assertRaises(RuntimeError) as cm:
ent.act()
self.assertEqual(
str(cm.exception),
'In SignalPtr: SIN ptr not set. (in signal <CustomEntity(test_dg_exc)::input(double)::in_double>)')
"In SignalPtr: SIN ptr not set. "
"(in signal <CustomEntity(test_dg_exc)::input(double)::in_double>)",
)
# check that accessing an initialized signal doesn't raise
ent_2 = CustomEntity('another_entity')
dg.plug(ent_2.signal('out_double'), ent.signal('in_double'))
ent_2 = CustomEntity("another_entity")
dg.plug(ent_2.signal("out_double"), ent.signal("in_double"))
ent.act()
if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
......@@ -5,8 +5,13 @@ import os
import time
from custom_entity import CustomEntity
from dynamic_graph import (addLoggerCoutOutputStream, addLoggerFileOutputStream, closeLoggerFileOutputStream,
real_time_logger_destroy, real_time_logger_spin_once)
from dynamic_graph import (
addLoggerCoutOutputStream,
addLoggerFileOutputStream,
closeLoggerFileOutputStream,
real_time_logger_destroy,
real_time_logger_spin_once,
)
from dynamic_graph.entity import VerbosityLevel
print(os.getcwd())
......
......@@ -3,7 +3,7 @@ import os
pkgConfigPath = os.environ.get("PKG_CONFIG_PATH")
if pkgConfigPath is None:
pkgConfigPath = ''
pathList = re.split(':', pkgConfigPath) # noqa
pkgConfigPath = ""
pathList = re.split(":", pkgConfigPath) # noqa
print(pathList)
......@@ -3,7 +3,7 @@ import re
pkgConfigPath = os.environ.get("PKG_CONFIG_PATH")
if pkgConfigPath is None:
pkgConfigPath = ''
pathList = re.split(':', pkgConfigPath)
pkgConfigPath = ""
pathList = re.split(":", pkgConfigPath)
print(pathList)
......@@ -3,6 +3,6 @@ import numpy # noqa
# Make sure the variable is deleted.
if "var" in locals() or "var" in globals():
raise ValueError('Not cleaned')
raise ValueError("Not cleaned")
var = "This string should have been deleted."
# Copyright 2010-2020, Florent Lamiraux, Thomas Moulard, Olivier Stasse, Guilhem Saurel, JRL, CNRS/AIST, LAAS-CNRS
# Test the interpreter
SET(EXECUTABLE_NAME interpreter-test)
ADD_EXECUTABLE(${EXECUTABLE_NAME} interpreter-test.cc)
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} dynamic-graph-python)
ADD_TEST(${EXECUTABLE_NAME} ${EXECUTABLE_NAME})
# Test runfile
SET(EXECUTABLE_NAME interpreter-test-runfile)
ADD_EXECUTABLE(${EXECUTABLE_NAME} interpreter-test-runfile.cc)
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} dynamic-graph-python)
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} ${PYTHON_LIBRARY})
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} ${Boost_LIBRARIES})
ADD_TEST(${EXECUTABLE_NAME} ${EXECUTABLE_NAME})
ADD_CUSTOM_COMMAND(TARGET interpreter-test-runfile POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/unitTesting/test_python-ok.py
${CMAKE_BINARY_DIR}/unitTesting
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/unitTesting/test_python-name_error.py
${CMAKE_BINARY_DIR}/unitTesting
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/unitTesting/test_python-syntax_error.py
${CMAKE_BINARY_DIR}/unitTesting
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/unitTesting/test_python-restart_interpreter.py
${CMAKE_BINARY_DIR}/unitTesting
)
# Test the module generation
## Create an entity
SET(LIBRARY_NAME "custom_entity")
ADD_LIBRARY(${LIBRARY_NAME} SHARED ${LIBRARY_NAME}.cpp)
SET_TARGET_PROPERTIES(${LIBRARY_NAME}
PROPERTIES
PREFIX ""
SOVERSION ${PROJECT_VERSION}
INSTALL_RPATH ${DYNAMIC_GRAPH_PLUGINDIR})
target_link_libraries(${LIBRARY_NAME} dynamic-graph::dynamic-graph)
## Create its bindings
## This mimics DYNAMIC_GRAPH_PYTHON_MODULE(${LIBRARY_NAME} ${LIBRARY_NAME} "${LIBRARY_NAME}-wrap")
CONFIGURE_FILE(
${PROJECT_SOURCE_DIR}/cmake/dynamic_graph/submodule/__init__.py.cmake
${PROJECT_BINARY_DIR}/unitTesting/${LIBRARY_NAME}/__init__.py
)
SET(PYTHON_MODULE "${LIBRARY_NAME}-wrap")
SET(SOURCE_PYTHON_MODULE "cmake/dynamic_graph/python-module-py.cc")
ADD_LIBRARY(${PYTHON_MODULE} MODULE ${PROJECT_SOURCE_DIR}/${SOURCE_PYTHON_MODULE})
SET_TARGET_PROPERTIES(${PYTHON_MODULE}
PROPERTIES PREFIX ""
OUTPUT_NAME ${LIBRARY_NAME}/wrap
)
TARGET_LINK_LIBRARIES(${PYTHON_MODULE} ${PUBLIC_KEYWORD} "-Wl,--no-as-needed")
TARGET_LINK_LIBRARIES(${PYTHON_MODULE} ${PUBLIC_KEYWORD} ${LIBRARY_NAME} ${PYTHON_LIBRARY})
## Test it
ADD_PYTHON_UNIT_TEST("test-custom-entity" "unitTesting/test_custom_entity.py" src unitTesting)
# also test other bindings, using this custom entity
ADD_PYTHON_UNIT_TEST("test-bindings" "unitTesting/test_bindings.py" src unitTesting)
/* Copyright 2010-2019 LAAS, CNRS
* Thomas Moulard.
*
*/
#define ENABLE_RT_LOG
#include <sstream>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/exception-factory.h>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/real-time-logger.h>
#include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h>
#include <dynamic-graph/command-bind.h>
namespace dynamicgraph {
class CustomEntity : public Entity {
public:
dynamicgraph::SignalPtr<double, int> m_sigdSIN;
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT;
static const std::string CLASS_NAME;
virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n)
: Entity(n),
m_sigdSIN(NULL, "CustomEntity(" + name + ")::input(double)::in_double"),
m_sigdTimeDepSOUT(boost::bind(&CustomEntity::update, this, _1, _2), m_sigdSIN,
"CustomEntity(" + name + ")::input(double)::out_double")
{
addSignal();
using namespace dynamicgraph::command;
this->addCommand("act", makeCommandVoid0( *this, &CustomEntity::act,
docCommandVoid0( "act on input signal")));
}
void addSignal() { signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT); }
void rmValidSignal() {
signalDeregistration("in_double");
signalDeregistration("out_double");
}
double &update(double &res, const int &inTime) {
const double &aDouble = m_sigdSIN(inTime);
res = aDouble;
std::ostringstream oss;
oss << "start update " << res;
sendMsg(oss.str().c_str(), MSG_TYPE_ERROR);
sendMsg("This is a message of level MSG_TYPE_DEBUG", MSG_TYPE_DEBUG, __FILE__, __LINE__);
sendMsg("This is a message of level MSG_TYPE_INFO", MSG_TYPE_INFO, __FILE__, __LINE__);
sendMsg("This is a message of level MSG_TYPE_WARNING", MSG_TYPE_WARNING, __FILE__, __LINE__);
sendMsg("This is a message of level MSG_TYPE_ERROR", MSG_TYPE_ERROR, __FILE__, __LINE__);
sendMsg("This is a message of level MSG_TYPE_DEBUG_STREAM", MSG_TYPE_DEBUG_STREAM, __FILE__, __LINE__);
sendMsg("This is a message of level MSG_TYPE_INFO_STREAM", MSG_TYPE_INFO_STREAM, __FILE__, __LINE__);
sendMsg("This is a message of level MSG_TYPE_WARNING_STREAM", MSG_TYPE_WARNING_STREAM, __FILE__, __LINE__);
sendMsg("This is a message of level MSG_TYPE_ERROR_STREAM", MSG_TYPE_ERROR_STREAM, __FILE__, __LINE__);
sendMsg("end update", MSG_TYPE_ERROR, __FILE__, __LINE__);
return res;
}
void act() {
m_sigdSIN.accessCopy();
}
};
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity");
} // namespace dynamicgraph