def test_add_parameter_param_target(self):
        p = Parameter('comp.x', low=0, high=1e99, scope=self.top)
        p2 = Parameter('comp.y', low=0, high=1e99, scope=self.top)

        self.top.run()
        self.assertEqual(self.top.driver.is_valid(), True)
        self.assertEqual(self.top.driver._exec_state, 'VALID')
        self.top.driver.add_parameter(p)
        self.assertEqual(self.top.driver.is_valid(), False)
        self.assertEqual(self.top.driver._exec_state, 'INVALID')
        self.assertEqual({'comp.x': p}, self.top.driver.get_parameters())

        self.top.run()
        self.assertEqual(self.top.driver.is_valid(), True)
        self.assertEqual(self.top.driver._exec_state, 'VALID')
        self.top.driver.remove_parameter('comp.x')
        self.assertEqual(self.top.driver.is_valid(), False)
        self.assertEqual(self.top.driver._exec_state, 'INVALID')

        self.top.driver.add_parameter(p, low=10.0)
        self.assertEqual({'comp.x': p}, self.top.driver.get_parameters())
        self.assertEqual(10.0, self.top.driver.get_parameters()['comp.x'].low)
        self.top.driver.remove_parameter('comp.x')

        pg = ParameterGroup([p, p2])
        self.top.driver.add_parameter(pg)
        self.assertEqual({'comp.x': pg},
                         dict(self.top.driver.get_parameters()))

        self.top.driver.remove_parameter('comp.x')

        pg = ParameterGroup([p, p2])
        self.top.driver.add_parameter(pg, low=10.0)
        self.assertEqual(10.0, self.top.driver.get_parameters()['comp.x'].low)
Example #2
0
    def test_get_metadata(self):
        p = Parameter('comp.x', low=0, high=1e99, scope=self.top)

        p.get_metadata()
        self.assertEqual(p.get_metadata(), ('comp.x', {
            'high': None,
            'iotype': 'in',
            'type': 'trait',
            'low': None,
            'vartypename': 'Float',
            'assumed_default': False
        }))

        p2 = Parameter('comp.y', low=0, high=1e99, scope=self.top)
        pg = ParameterGroup([p, p2])
        self.assertEqual(pg.get_metadata(),
                         [('comp.x', {
                             'fd_step': None,
                             'name': 'comp.x',
                             'scaler': 1.0,
                             'high': 9.9999999999999997e+98,
                             'start': None,
                             'low': 0,
                             'adder': 0.0
                         }),
                          ('comp.y', {
                              'fd_step': None,
                              'name': 'comp.x',
                              'scaler': 1.0,
                              'high': 9.9999999999999997e+98,
                              'start': None,
                              'low': 0,
                              'adder': 0.0
                          })])
 def test_param_output(self):
     try:
         p = Parameter('comp.c', low=0, high=1e99, scope=self.top)
     except Exception as err:
         self.assertEqual(
             str(err),
             "Can't add parameter 'comp.c' because 'comp.c' is an output.")
     else:
         self.fail("Exception expected")
    def test_add_parameter_param_target(self):
        p = Parameter('comp.x', self.top, low=0, high=1e99, scope=self.top)
        p2 = Parameter('comp.y', self.top, low=0, high=1e99, scope=self.top)

        self.top.driver.add_parameter(p)
        self.assertEqual({'comp.x': p}, self.top.driver.get_parameters())

        self.top.driver.remove_parameter('comp.x')

        self.top.driver.add_parameter(p, low=10.0)
        self.assertEqual({'comp.x': p}, self.top.driver.get_parameters())
        self.assertEqual(10.0, self.top.driver.get_parameters()['comp.x'].low)
        self.top.driver.remove_parameter('comp.x')

        pg = ParameterGroup([p, p2])
        self.top.driver.add_parameter(pg)
        self.assertEqual({'comp.x': pg},
                         dict(self.top.driver.get_parameters()))

        self.top.driver.remove_parameter('comp.x')

        pg = ParameterGroup([p, p2])
        self.top.driver.add_parameter(pg, low=10.0)
        self.assertEqual(10.0, self.top.driver.get_parameters()['comp.x'].low)