Skip to content
Snippets Groups Projects
Commit 81727892 authored by Stefano Borini's avatar Stefano Borini
Browse files

Polished input_slot_map and added local trait for identifiers

parent 060518ac
No related branches found
No related tags found
1 merge request!69Introduce slots and resolution of named variables
from traits.api import HasStrictTraits, Enum, String
from traits.api import HasStrictTraits, Enum
from ..local_traits import Identifier
class InputSlotMap(HasStrictTraits):
"""Class that specifies the origin of data for the slots of a data source.
"""
#: If MCO, the source is the MCO parameter with name specified at
#: value_name. If Fixed, the value specified in "value" will be used
#: instead.
source = Enum('MCO', 'Fixed')
name = String()
value = String()
Class that specifies the origin of data for the slots of a data source.
This entity will go in the model object, and associates the order
it is in the containing tlist with the variable name the value
should be taken from.
"""
#: Where the value will come from.
#: At the moment, only MCO is supported: the source is the MCO parameter
#: with name specified at ``name``.
source = Enum('MCO')
#: The user defined name of the variable containing the value.
name = Identifier()
import unittest
from traits.api import TraitError
from force_bdss.core.input_slot_map import InputSlotMap
class TestDataValue(unittest.TestCase):
def test_initialization(self):
slotmap = InputSlotMap()
self.assertEqual(slotmap.source, "MCO")
self.assertEqual(slotmap.name, "")
with self.assertRaises(TraitError):
slotmap.name = "000"
from traits.api import Regex
#: Used for variable names, but allow also empty string as it's the default
#: case and it will be present if the workflow is saved before actually
#: specifying the value.
Identifier = Regex(regex="(^[^\d\W]\w*\Z|^\Z)")
import unittest
from traits.api import HasStrictTraits, TraitError
from force_bdss.local_traits import Identifier
class Traited(HasStrictTraits):
val = Identifier()
class TestLocalTraits(unittest.TestCase):
def test_identifier(self):
c = Traited()
for working in ["hello", "_hello", "_0", "_hello_123", "_", ""]:
c.val = working
self.assertEqual(c.val, working)
for broken in ["0", None, 123, "0hello", "hi$", "hi%"]:
with self.assertRaises(TraitError):
c.val = broken
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment