def test_driver(self): # Ensure we can't add a Driver to a component that is not an Assembly. comp = Component() try: comp.add('driver', Driver()) except Exception as err: self.assertEqual(str(err), "A Driver may only be added to an Assembly") pass
def test_driver(self): # Ensure we can't add a Driver to a component that is not an Assembly. comp = Component() try: comp.add('driver', Driver()) except Exception as err: self.assertEqual(str(err), "A Driver may only be added to an Assembly") pass
def test_replace(self): # Ensure we can replace a child component. c0 = Component() c1 = Component() c2 = Component() c0.add('c', c1) self.assertEqual(id(c0.c), id(c1)) c0.replace('c', c2) self.assertEqual(id(c0.c), id(c2))
class ArrayTestCase(unittest.TestCase): def setUp(self): """this setup function will be called before each test in this class""" self.hobj = Component() self.hobj.add('arr1',Array(array([98.9]), iotype='in', units='ft')) self.hobj.add('arr2', Array(array([13.2]), iotype='out', units='inch')) self.hobj.add('arr3', Array(iotype='in', units='kg', desc='stuff')) self.hobj.add('arr98', Array(iotype='in')) self.hobj.add('arr99', Array(iotype='in')) self.hobj.arr1 = [1.0, 2.0, 3.0] self.hobj.arr2 = [[1.,2.],[3.,4.]] self.hobj.arr3 = [1.1] self.hobj.arr98 = [[0., 1., 0.1944, 0.1944], [0., 33., 1., 0.]]; self.hobj.arr99 = [[0, 1, 0.1944, 0.1944], [0, 0, 1, 0]] def tearDown(self): """this teardown function will be called after each test""" self.hobj = None def test_set_to_default(self): self.hobj.add('arr4', Array(iotype='in', units='kg')) self.assertTrue(all(array([]) == self.hobj.arr4)) self.hobj.arr4 = [6.5] self.assertEqual(6.5, self.hobj.arr4[0]) self.hobj.revert_to_defaults() self.assertTrue(all(array([98.9]) == self.hobj.arr1)) self.assertTrue(all(array([]) == self.hobj.arr4)) def test_assignment(self): # check starting value self.assertTrue(all(array([1.,2.,3.]) == self.hobj.arr1)) # check default value self.assertEqual([98.9], self.hobj.get_trait('arr1').trait_type.default_value) # use convert_units to perform unit conversion self.hobj.arr2 = convert_units(self.hobj.arr1, self.hobj.get_trait('arr1').units, 'inch') self.assertAlmostEqual(12., self.hobj.arr2[0], 5) self.assertAlmostEqual(24., self.hobj.arr2[1], 5) self.assertAlmostEqual(36., self.hobj.arr2[2], 5) def test_bogus_units(self): try: uf = Array([0.], iotype='in', units='bogus') except ValueError, err: self.assertEqual(str(err), "Units of 'bogus' are invalid") else:
class ArrayTestCase(unittest.TestCase): def setUp(self): """this setup function will be called before each test in this class""" self.hobj = Component() self.hobj.add('arr1', Array(array([98.9]), iotype='in', units='ft')) self.hobj.add('arr2', Array(array([13.2]), iotype='out', units='inch')) self.hobj.add('arr3', Array(iotype='in', units='kg', desc='stuff')) self.hobj.add('arr98', Array(iotype='in')) self.hobj.add('arr99', Array(iotype='in')) self.hobj.arr1 = [1.0, 2.0, 3.0] self.hobj.arr2 = [[1., 2.], [3., 4.]] self.hobj.arr3 = [1.1] self.hobj.arr98 = [[0., 1., 0.1944, 0.1944], [0., 33., 1., 0.]] self.hobj.arr99 = [[0, 1, 0.1944, 0.1944], [0, 0, 1, 0]] def tearDown(self): """this teardown function will be called after each test""" self.hobj = None def test_set_to_default(self): self.hobj.add('arr4', Array(iotype='in', units='kg')) self.assertTrue(all(array([]) == self.hobj.arr4)) self.hobj.arr4 = [6.5] self.assertEqual(6.5, self.hobj.arr4[0]) self.hobj.revert_to_defaults() self.assertTrue(all(array([98.9]) == self.hobj.arr1)) self.assertTrue(all(array([]) == self.hobj.arr4)) def test_assignment(self): # check starting value self.assertTrue(all(array([1., 2., 3.]) == self.hobj.arr1)) # check default value self.assertEqual([98.9], self.hobj.get_trait('arr1').trait_type.default_value) # use convert_units to perform unit conversion self.hobj.arr2 = convert_units(self.hobj.arr1, self.hobj.get_trait('arr1').units, 'inch') self.assertAlmostEqual(12., self.hobj.arr2[0], 5) self.assertAlmostEqual(24., self.hobj.arr2[1], 5) self.assertAlmostEqual(36., self.hobj.arr2[2], 5) def test_bogus_units(self): try: uf = Array([0.], iotype='in', units='bogus') except ValueError, err: self.assertEqual(str(err), "Units of 'bogus' are invalid") else:
def test_save_bad_child(self): logging.debug('') logging.debug('test_save_bad_child') # Create orphan component. orphan = Component() code = 'self.model.save_to_egg(self.model.name, next_egg(),' \ ' py_dir=PY_DIR, child_objs=[orphan])' assert_raises(self, code, globals(), locals(), RuntimeError, 'Entry point object has no parent!') # Create non-orphan component that is not part of model. badboy = orphan.add('badboy', Component()) code = 'self.model.save_to_egg(self.model.name, next_egg(),' \ ' py_dir=PY_DIR, child_objs=[badboy])' assert_raises(self, code, globals(), locals(), RuntimeError, 'Egg_TestModel: badboy is not a child of Egg_TestModel.')
def test_save_bad_child(self): logging.debug('') logging.debug('test_save_bad_child') # Create orphan component. orphan = Component() code = 'self.model.save_to_egg(self.model.name, next_egg(),' \ ' py_dir=PY_DIR, child_objs=[orphan])' assert_raises(self, code, globals(), locals(), RuntimeError, 'Entry point object has no parent!') # Create non-orphan component that is not part of model. badboy = orphan.add('badboy', Component()) code = 'self.model.save_to_egg(self.model.name, next_egg(),' \ ' py_dir=PY_DIR, child_objs=[badboy])' assert_raises(self, code, globals(), locals(), RuntimeError, 'Egg_TestModel: badboy is not a child of Egg_TestModel.')