Пример #1
0
    def test_dg_exc(self):
        """
        test that exceptions from dynamic graph are correctly raised
        """
        ent = CustomEntity('test_dg_exc')
        # check that accessing a non initialized signal raises
        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>)')

        # 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.act()
Пример #2
0
    def test_type_check(self):
        """
        test the type checking in signal plugs
        """
        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'))

        # 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 % ("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 % ("CustomEntity", "SignalPtrDouble"))
Пример #3
0
def get_custom_entities(pipeline):
    custom_entities = []
    if 'custom_entities' in pipeline:
        for config in pipeline['custom_entities']:
            messenger = Messenger(pipeline['messaging'])
            messenger.set_incoming(config['alias'])
            messenger.set_outgoing(config['outputs'])

            module = import_from_file(
                config['classname'],
                os.path.join(os.getcwd(), config['filename']))
            constructor = getattr(module, config['classname'])
            instance = constructor()

            custom_entities.append(CustomEntity(config, instance, messenger))

    return custom_entities
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)