Example #1
0
    def args(operator):
        positional = []
        optionals = []

        positional = list(operator.input)

        for s in operator.parameters.values():
            assert isinstance(s, Slot)
            if s.required:
                positional.append(s.name)
            else:
                value = conversion(str, s.sort)(s.default) if s.default else None
                optionals.append("%s = %s", s.name, repr(value))

        return ", ".join(positional + optionals)
Example #2
0
    def __init__(self, name, physical=None, logical=None, value=None, role=None):
        """creates a variable with the given ``name``, ``logical`` and ``physical`` type and ``value``

        The value gets automatic transformed into the physical type.

        If no physical type is given, it will determined by the value.

        :param name:
        :type name: str
        :param physical:
        :type physical: str or type
        :param logical:
        :param value:
        :type value: object
        :return:
        """
        self.name = name
        self.physical_type = physical
        self.logical_type = logical
        self.value = value
        self.role = role

        if not self.physical_type and self.value is not None:
            self.physical_type = type(self.value)

        if not self.physical_type and self.value is None:
            s = 'Try to initialize a variable without physical type and value'
            log.fatal(s)
            raise MSMLError(s)

        self.sort = sorts.get_sort(self.physical_type, self.logical_type)
        if not isinstance(self.value, self.sort.physical) and self.value is not None:
            log.info("Need convert value of %s" % self)
            from_type = type(self.value)
            converter = sorts.conversion(from_type, self.sort)
            self.value = converter(self.value)
Example #3
0
 def get_default_args(self):
     defaults = dict()
     for x in self.parameters.values():
         if x.default is not None:
             defaults[x.name] = sorts.conversion(str, x.sort)(x.default)
     return defaults
 def test_MSMLString_float(self):
     cvt = S.conversion(S.MSMLString, S.MSMLFloat)
     self.assertEqual(3.5, cvt("3.5"))
 def test_str_MSMLString(self):
     cvt = S.conversion(str, S.MSMLString)
     self.assertEqual(S.MSMLString("abc"), cvt("abc"))