Ejemplo n.º 1
0
def make_graph(nodes=(), connections=()):
    scope = set_as_top(Assembly())
    sub = scope.add('sub', Assembly())
    dep = ExprMapper(sub)
    for name in nodes:
        if name.startswith('parent.'):
            scope.add(name.split('.', 1)[1], Simple())
        else:
            sub.add(name, Simple())
            #dep.add(name)
    for src, dest in connections:
        if '.' not in src and not sub.contains(src):
            if dest.startswith('parent.'):
                iotype = 'out'
            else:
                iotype = 'in'
            sub.add(src, Int(1, iotype=iotype))
        if '.' not in dest and not sub.contains(dest):
            if src.startswith('parent.'):
                iotype = 'in'
            else:
                iotype = 'out'
            sub.add(dest, Int(1, iotype=iotype))
        dep.connect(ExprEvaluator(src, sub), ExprEvaluator(dest, sub), sub)
    return dep, sub
Ejemplo n.º 2
0
    def test_constructor_defaults(self):

        self.hobj.add('int_nodefault1', Int(low=3, high=4, iotype='in'))
        self.assertEqual(3, self.hobj.int_nodefault1)

        self.hobj.add('int_nodefault2', Int(high=4, iotype='in'))
        self.assertEqual(4, self.hobj.int_nodefault2)

        self.hobj.add('int_nodefault3', Int(iotype='in'))
        self.assertEqual(0, self.hobj.int_nodefault3)
Ejemplo n.º 3
0
    def setUp(self):
        """this setup function will be called before each test in this class"""
        self.hobj = Container()
        self.hobj.add('int1', Int(98, low=0, high=99, iotype='in'))
        self.hobj.add('int2', Int(13, iotype='out'))
        self.hobj.add('int3', Int(low=0, high=99, iotype='in'))

        self.hobj.int1 = 3
        self.hobj.int2 = 42
        self.hobj.int3 = 1
Ejemplo n.º 4
0
    def test_attributes(self):

        try:
            self.hobj.add('inta', Int(98.0, low=0, high=99, iotype='in'))
        except ValueError, err:
            errstring = "Default value for an Int must be an integer."
            self.assertEqual(str(err), errstring)
Ejemplo n.º 5
0
class Simple(Component):
    a = Int(iotype='in')
    b = Int(iotype='in')
    c = Int(iotype='out')
    d = Int(iotype='out')

    def __init__(self):
        super(Simple, self).__init__()
        self.a = 1
        self.b = 2
        self.c = 3
        self.d = -1

    def execute(self):
        self.c = self.a + self.b
        self.d = self.a - self.b
Ejemplo n.º 6
0
    def test_set_to_default(self):
        self.assertEqual(3, self.hobj.int1)
        self.hobj.add('int4', Int(iotype='in'))
        self.assertEqual(0, self.hobj.int4)
        self.hobj.int4 = 6
        self.assertEqual(6, self.hobj.int4)

        self.hobj.revert_to_defaults()

        self.assertEqual(98, self.hobj.int1)
        self.assertEqual(0, self.hobj.int4)
Ejemplo n.º 7
0
    def test_exclusions(self):

        self.hobj.add('int4', Int(low=3, high=4, \
                                  exclude_low=True, exclude_high=True, \
                                  iotype='in'))
        try:
            self.hobj.int4 = 3
        except ValueError, err:
            errstring = ": Variable 'int4' must be" + \
                      " 3 < an integer < 4, but a value of 3" + \
                      " <type 'int'> was specified."
            self.assertEqual(str(err), errstring)
Ejemplo n.º 8
0
 def test_default_value(self):
     try:
         self.hobj.add('out_of_bounds', Int(5, low=3, high=4))
     except ValueError, err:
         self.assertEqual(str(err),
                          "Default value is outside of bounds [3, 4].")
Ejemplo n.º 9
0
        self.assertEqual(98, self.hobj.int1)
        self.assertEqual(0, self.hobj.int4)

    def test_attributes(self):

        try:
            self.hobj.add('inta', Int(98.0, low=0, high=99, iotype='in'))
        except ValueError, err:
            errstring = "Default value for an Int must be an integer."
            self.assertEqual(str(err), errstring)
        else:
            self.fail("Exception expected")

        try:
            self.hobj.add('inta', Int(98, low=0.01, high=99, iotype='in'))
        except ValueError, err:
            errstring = "Lower bound for an Int must be an integer."
            self.assertEqual(str(err), errstring)
        else:
            self.fail("Exception expected")

        try:
            self.hobj.add('inta', Int(98, low=0, high=99.9, iotype='in'))
        except ValueError, err:
            errstring = "Upper bound for an Int must be an integer."
            self.assertEqual(str(err), errstring)
        else:
            self.fail("Exception expected")

        try: