예제 #1
0
파일: test_gvm.py 프로젝트: DLR-RM/RAFCON
def test_references(caplog):
    gvm = GlobalVariableManager.instance()
    d = {'a': 1, 'b': 2}

    # Test access by reference
    gvm.set_variable('d', d, per_reference=True)
    _d = gvm.get_variable('d', per_reference=True)
    d['a'] = 3
    assert d['a'] == _d['a'] == 3
    __d = gvm.get_variable('d', per_reference=True)
    assert d['a'] == __d['a'] == 3
    ___d = gvm.get_variable('d')
    d['a'] = 4
    assert d['a'] == __d['a'] == ___d['a'] == 4

    # Test set by reference, get by copy
    gvm.set_variable('x', d, per_reference=True)
    cd = gvm.get_variable('x', per_reference=False)
    d['a'] = 5
    assert d['a'] == 5 and cd['a'] == 4

    # Test access by copy
    dc = gvm.get_variable('d', per_reference=False)
    d['b'] = 5
    assert d['a'] == dc['a']
    assert d['b'] != dc['b']

    gvm.set_variable('c', d)
    cc = gvm.get_variable('c')
    d['a'] = 10
    assert d['a'] != cc['a']

    with raises(RuntimeError):
        gvm.get_variable('c', per_reference=True)
    testing_utils.assert_logger_warnings_and_errors(caplog)
예제 #2
0
파일: test_gvm.py 프로젝트: DLR-RM/RAFCON
def test_locks(caplog):
    gvm = GlobalVariableManager.instance()
    gvm.set_variable('a', 1)
    a = gvm.get_variable('a')
    assert a == 1

    assert (not gvm.is_locked("a"))

    access_key = gvm.lock_variable('a')
    gvm.lock_variable('a')
    assert (gvm.is_locked("a"))
    a = gvm.get_variable('a', access_key=access_key)
    assert a == 1
    gvm.set_variable('a', 2, access_key=access_key)
    assert gvm.get_variable('a', access_key=access_key) == 2

    gvm.set_locked_variable('a', access_key=access_key, value=4)
    assert gvm.get_locked_variable('a', access_key=access_key) == 4

    gvm.unlock_variable('a', access_key)
    gvm.unlock_variable('a', access_key)
    assert (not gvm.is_locked("a"))
    testing_utils.assert_logger_warnings_and_errors(caplog,
                                                    expected_warnings=1,
                                                    expected_errors=1)
예제 #3
0
파일: test_gvm.py 프로젝트: DLR-RM/RAFCON
def test_keys(caplog):
    gvm = GlobalVariableManager.instance()
    gvm.set_variable('a', 1)
    gvm.set_variable('ab', 2)
    gvm.set_variable('abc', 3)
    gvm.set_variable('def', 4)

    key_start_a = gvm.get_all_keys_starting_with('a')
    assert (len(gvm.get_all_keys()) == 33)
    assert (len(key_start_a) == 20)

    testing_utils.assert_logger_warnings_and_errors(caplog)
예제 #4
0
"""

import argparse
import threading

from rafcon.core.global_variable_manager import GlobalVariableManager
from rafcon.core.library_manager import LibraryManager
from rafcon.core.execution.execution_engine import ExecutionEngine
from rafcon.core.state_machine_manager import StateMachineManager

# thread id of the thread which created the core singletons
thread_identifier = threading.currentThread().ident

# This variable holds the global variable manager singleton
global_variable_manager = GlobalVariableManager.instance()

# This variable holds the library manager singleton
library_manager = LibraryManager.instance()

# This variable holds the global state machine manager object
state_machine_manager = StateMachineManager.instance()

# This variable holds the execution engine singleton
state_machine_execution_engine = ExecutionEngine.instance(
    state_machine_manager)

# signal that cause shut down
shut_down_signal = None

argument_parser = argparse.ArgumentParser(description='Start RAFCON',
예제 #5
0
파일: test_gvm.py 프로젝트: uservinu/RAFCON
def test_type_check(caplog):
    # valid
    gvm = GlobalVariableManager()
    gvm.set_variable("a", 1, data_type=int)
    a = gvm.get_variable("a")
    assert a == 1

    gvm.set_variable("b", "test", data_type=str)
    b = gvm.get_variable("b")
    assert b == "test"

    gvm.set_variable("c", 12.0, data_type=float)
    c = gvm.get_variable("c")
    assert c == 12.0

    gvm.set_variable("d", True, data_type=bool)
    d = gvm.get_variable("d")
    assert d

    e_list = [1, 2, 3]
    gvm.set_variable("e", e_list, data_type=list)
    e = gvm.get_variable("e")
    assert e == e_list

    f_dict = {'a': 1, 'b': 2}
    gvm.set_variable("f", f_dict, data_type=dict)
    f = gvm.get_variable("f")
    assert f == f_dict

    # invalid
    with raises(TypeError):
        gvm.set_variable("g", "test", data_type=int)
    testing_utils.assert_logger_warnings_and_errors(caplog)

    with raises(TypeError):
        gvm.set_variable("g", "test", data_type=float)
    testing_utils.assert_logger_warnings_and_errors(caplog)

    # overwriting
    gvm.set_variable("a", 3, data_type=int)
    a = gvm.get_variable("a")
    assert a == 3

    # invalid overwriting
    with raises(TypeError):
        gvm.set_variable("a", "string", data_type=int)
    a = gvm.get_variable("a")
    assert a == 3

    # invalid overwriting
    with raises(TypeError):
        gvm.set_variable("a", "any_string")
    a = gvm.get_variable("a")
    assert a == 3

    # backward compatibility
    gvm.delete_variable("a")
    gvm.set_variable("a", "test")
    a = gvm.get_variable("a")
    assert a == "test"

    gvm.set_variable("a", 123)
    a = gvm.get_variable("a")
    assert a == 123
예제 #6
0
파일: test_gvm.py 프로젝트: uservinu/RAFCON
def test_locks(caplog):
    gvm = GlobalVariableManager()
    gvm.set_variable('a', 1)
    a = gvm.get_variable('a')
    assert a == 1

    access_key = gvm.lock_variable('a')
    gvm.lock_variable('a')
    a = gvm.get_variable('a', access_key=access_key)
    assert a == 1
    gvm.set_variable('a', 2, access_key=access_key)
    assert gvm.get_variable('a', access_key=access_key) == 2
    gvm.unlock_variable('a', access_key)
    gvm.unlock_variable('a', access_key)
    testing_utils.assert_logger_warnings_and_errors(caplog, expected_errors=2)
예제 #7
0
"""

import argparse
import threading

from rafcon.core.global_variable_manager import GlobalVariableManager
from rafcon.core.library_manager import LibraryManager
from rafcon.core.execution.execution_engine import ExecutionEngine
from rafcon.core.state_machine_manager import StateMachineManager

# thread id of the thread which created the core singletons
thread_identifier = threading.currentThread().ident

# This variable holds the global variable manager singleton
global_variable_manager = GlobalVariableManager()

# This variable holds the library manager singleton
library_manager = LibraryManager()

# This variable holds the global state machine manager object
state_machine_manager = StateMachineManager()

# This variable holds the execution engine singleton
state_machine_execution_engine = ExecutionEngine(state_machine_manager)

# signal that cause shut down
shut_down_signal = None

argument_parser = argparse.ArgumentParser(description='Start RAFCON', fromfile_prefix_chars='@')