Skip to content

Commit

Permalink
Merged in NRRPLT-7700-tf-execution-order (pull request #81)
Browse files Browse the repository at this point in the history
[NRRPLT-7700] Added order attribute to transfer functions

Approved-by: Michael Zechmair <[email protected]>
Approved-by: Ugo Albanese <[email protected]>
  • Loading branch information
Eloy Retamino authored and poupa29 committed Dec 2, 2019
1 parent ec63f39 commit 4bf3ea2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def __load_tfs(self):
continue

try:
tfm.set_transfer_function(tf.code, new_code, tf.name, tf.active)
tfm.set_transfer_function(tf.code, new_code, tf.name, tf.active, tf.priority)
except tfm.TFLoadingException as loading_e:
logger.error(loading_e)
tfm.set_flawed_transfer_function(tf.code, tf.name, loading_e)
Expand Down
12 changes: 10 additions & 2 deletions hbp_nrp_commons/hbp_nrp_commons/sim_config/SimConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,25 @@ class _TF(object): # pragma: no cover
"""
Model to store TF information
"""
def __init__(self, name, code, src=None, active=False):
def __init__(self, name, code, src=None, active=False, priority=0):
"""
Initialize a transfer function object
:param name: name of the transfer function
:param code: compiled (restricted) source code of transfer function
:param src: source code (plain text) of transfer function
:param active: active state of the transfer function
:param priority: specifies execution order of the transfer function. Transfer functions with
higher priority are executed first.
"""
self.name = name
self.code = code
self.src = src
self.active = active
try:
self.priority = int(priority)
except (ValueError, TypeError):
self.priority = 0


class SimConfig(object):
Expand Down Expand Up @@ -331,8 +338,9 @@ def _read_dom_data(self):
code = generate_tf(_tf, self.sim_dir)
name = get_tf_name(code)
src = _tf.src if _tf.src else None # must be not None and not ""
priority = _tf.priority if _tf.priority else 0
active = bool(_tf.active) if _tf.active else False
self._tfs.append(_TF(name, code, src, active))
self._tfs.append(_TF(name, code, src, active, priority))

def _read_robot_models(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from mock import patch, Mock, MagicMock, ANY, mock_open
from hbp_nrp_commons.MockUtil import MockUtil

from hbp_nrp_commons.sim_config.SimConfig import SimConfig
from hbp_nrp_commons.sim_config.SimConfig import SimConfig, _TF

__author__ = 'Hossain Mahmud'

Expand Down Expand Up @@ -116,6 +116,19 @@ def test_read_data(self):
def test_properties(self):
pass

def test_priority_is_int(self):
# test _TF priority value is always initialized to an integer
tf_1 = _TF("dummy_name", "dummy_code",priority=None)
tf_2 = _TF("dummy_name", "dummy_code", priority="string_value")
tf_3 = _TF("dummy_name", "dummy_code", priority=False)
tf_4 = _TF("dummy_name", "dummy_code", priority=3.1416)

self.assertTrue(type(tf_1.priority) == int)
self.assertTrue(type(tf_2.priority) == int)
self.assertTrue(type(tf_3.priority) == int)
self.assertTrue(type(tf_4.priority) == int)



if __name__ == '__main__':
unittest.main()

0 comments on commit 4bf3ea2

Please sign in to comment.