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
# Olivier Stasse
# 2019 CNRS
#
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.entity import VerbosityLevel
print(os.getcwd())
# Starts the real time logger instance
aCustomEntity = CustomEntity("a_custom_entity")
addLoggerFileOutputStream("/tmp/output.dat")
aCustomEntity.signals()
aCustomEntity.setTimeSample(0.001)
print(aCustomEntity.getTimeSample())
aCustomEntity.setStreamPrintPeriod(0.002)
print(aCustomEntity.getStreamPrintPeriod())
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_INFO_WARNING_ERROR)
print(aCustomEntity.getLoggerVerbosityLevel())
for i in range(0, 5):
aCustomEntity.in_double.value = i
aCustomEntity.out_double.recompute(i)
real_time_logger_spin_once()
print(i)
time.sleep(1)
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_WARNING_ERROR)
print(aCustomEntity.getLoggerVerbosityLevel())
for i in range(5, 10):
aCustomEntity.in_double.value = i
aCustomEntity.out_double.recompute(i)
real_time_logger_spin_once()
time.sleep(1)
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_ERROR)
print(aCustomEntity.getLoggerVerbosityLevel())
for i in range(10, 15):
aCustomEntity.in_double.value = i
aCustomEntity.out_double.recompute(i)
real_time_logger_spin_once()
time.sleep(1)
addLoggerCoutOutputStream()
time.sleep(1)
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_NONE)
print(aCustomEntity.getLoggerVerbosityLevel())
for i in range(15, 20):
aCustomEntity.in_double.value = i
aCustomEntity.out_double.recompute(i)
real_time_logger_spin_once()
time.sleep(1)
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_ALL)
print(aCustomEntity.getLoggerVerbosityLevel())
for i in range(20, 25):
aCustomEntity.in_double.value = i
aCustomEntity.out_double.recompute(i)
real_time_logger_spin_once()
# End the real time logger
real_time_logger_destroy()
# Close all the output stream
closeLoggerFileOutputStream()
# flake8: noqa
import os
pkgConfigPath = os.environ.get("PKG_CONFIG_PATH")
if pkgConfigPath is None:
pkgConfigPath = ""
pathList = re.split(":", pkgConfigPath) # noqa
print(pathList)
import sys, os import os
import re import re
pkgConfigPath = os.environ.get("PKG_CONFIG_PATH") pkgConfigPath = os.environ.get("PKG_CONFIG_PATH")
if pkgConfigPath == None: if pkgConfigPath is None:
pkgConfigPath = '' pkgConfigPath = ""
pathList = re.split(':', pkgConfigPath) pathList = re.split(":", pkgConfigPath)
print pathList
print(pathList)
# numpy causes troubles when Py_Finalize is called in Interpreter destructor.
import numpy # noqa
# Make sure the variable is deleted.
if "var" in locals() or "var" in globals():
raise ValueError("Not cleaned")
var = "This string should have been deleted."
# flake8: noqa
hello world
#
# Copyright
#
INCLUDE(CTest)
set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
INCLUDE(../cmake/python.cmake)
FINDPYTHON()
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS} ${PYTHON_LIBRARY_DIRS})
ADD_DEFINITIONS(-DDEBUG=2)
# provide path to library libdynamic-graph.so
LINK_DIRECTORIES(${DYNAMIC_GRAPH_LIBRARY_DIRS})
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
LINK_DIRECTORIES(${${PROJECT_NAME}_BINARY_DIR}/src)
# Add dynamic-graph compilation flags and link to library libdynamic-graph.so
ADD_DEFINITIONS(${DYNAMIC_GRAPH_CFLAGS})
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)
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_error.py
${CMAKE_BINARY_DIR}/unitTesting
)
// The purpose of this unit test is to check the interpreter::runPythonFile method
#include <cstring>
#include <iostream>
#include "dynamic-graph/python/interpreter.hh"
int main(int argc, char ** argv)
{
// execute numerous time the same file.
// While running 1025, we can notice a change in the error.
// unfortunately, it can not be shown using a redirection of the streams
int numTest = 1025;
if (argc > 1)
numTest = atoi(argv[1]);
std::string empty_err = "";
dynamicgraph::python::Interpreter interp;
for (int i=0; i<numTest; ++i)
{
interp.runPythonFile("test_python_ok.py", empty_err);
if (empty_err != "")
{
std::cerr << "At iteration " << i << ", the error was not empty:" << std::endl;
std::cerr << " err " << empty_err << std::endl;
return -1;
}
}
// check that the error remains the same, despite of the number of executions
std::string old_err;
interp.runPythonFile("test_python_error.py", old_err);
std::string new_err = old_err;
for (int i=0; i<numTest; ++i)
{
interp.runPythonFile("test_python_error.py", new_err);
if (old_err != new_err)
{
std::cerr << "At iteration " << i << ", the error changed:" << std::endl;
std::cerr << " old " << old_err << std::endl;
std::cerr << " new " << new_err << std::endl;
return -1;
}
}
return 0;
}
/*
* Copyright
*/
#include "dynamic-graph-python-test.hh"
int main (int argc, char** argv)
{
GraphTest testGraph();
}
import sys, os
pkgConfigPath = os.environ.get("PKG_CONFIG_PATH")
if pkgConfigPath == None:
pkgConfigPath = ''
pathList = re.split(':', pkgConfigPath)
print pathList