def test16(self): print "Testing add_interface_parameter" class TestModule(BaseTestModule): pass o = TestModule() parameters_handler = HandleParameters(o) parameters_handler.add_vector_parameter( "mesh_length", "length of the model in the x, y and z directions", ("length_x", "length_y", "length_z") ) for i,par_name in enumerate(["length_x", "length_y", "length_z"]): parameters_handler.add_interface_parameter( par_name, "a test parameter", default_value = i*10.0 | generic_unit_system.length, ) x = parameters_handler.get_attribute(None, None) self.assertTrue("mesh_length" in str(x)) self.assertTrue("[0.0, 10.0, 20.0] length" in str(x)) converter = generic_unit_converter.ConvertBetweenGenericAndSiUnits(2.0 | units.m, 4.0 | units.kg, 6.0 | units.s) y = parameters.ParametersWithUnitsConverted( x, converter.as_converter_from_si_to_generic() ) self.assertTrue("mesh_length" in str(y)) self.assertTrue("[0.0, 20.0, 40.0] m" in str(y))
def test16(self): print "Testing add_interface_parameter" class TestModule(BaseTestModule): pass o = TestModule() parameters_handler = HandleParameters(o) parameters_handler.add_vector_parameter( "mesh_length", "length of the model in the x, y and z directions", ("length_x", "length_y", "length_z") ) for i,par_name in enumerate(["length_x", "length_y", "length_z"]): parameters_handler.add_interface_parameter( par_name, "a test parameter", default_value = i*10.0 | generic_unit_system.length, ) x = parameters_handler.get_attribute(None, None) self.assertTrue("mesh_length" in str(x)) self.assertTrue("[0.0, 10.0, 20.0] length" in str(x)) converter = generic_unit_converter.ConvertBetweenGenericAndSiUnits(2.0 | units.m, 4.0 | units.kg, 6.0 | units.s) y = parameters.ParametersWithUnitsConverted( x, converter.as_converter_from_si_to_generic() ) self.assertTrue("mesh_length" in str(y)) self.assertTrue("[0.0, 20.0, 40.0] m" in str(y))
def test11(self): print( "Testing ParametersWithUnitsConverted on vector parameters, using add_vector_parameter" ) class TestModule(BaseTestModule): x = 123.0 | generic_unit_system.length y = 456.0 | generic_unit_system.length z = 789.0 | generic_unit_system.length def get_length_x(self): return self.x def set_length_x(self, value): self.x = value def get_length_y(self): return self.y def set_length_y(self, value): self.y = value def get_length_z(self): return self.z def set_length_z(self, value): self.z = value o = TestModule() parameters_handler = HandleParameters(o) parameters_handler.add_vector_parameter( "mesh_length", "length of the model in the x, y and z directions", ("length_x", "length_y", "length_z")) for par_name in ["length_x", "length_y", "length_z"]: parameters_handler.add_method_parameter( "get_" + par_name, "set_" + par_name, par_name, "a test parameter", default_value=10.0 | generic_unit_system.length, ) x = parameters_handler.get_attribute(None, None) self.assertTrue("mesh_length" in str(x)) self.assertTrue("[123.0, 456.0, 789.0] length" in str(x)) converter = generic_unit_converter.ConvertBetweenGenericAndSiUnits( 2.0 | units.m, 4.0 | units.kg, 6.0 | units.s) y = parameters.ParametersWithUnitsConverted( x, converter.as_converter_from_si_to_generic()) self.assertTrue("mesh_length" in str(y)) self.assertTrue("[246.0, 912.0, 1578.0] m" in str(y))
def test11(self): print "Testing ParametersWithUnitsConverted on vector parameters, using add_vector_parameter" class TestModule(BaseTestModule): x = 123.0 | generic_unit_system.length y = 456.0 | generic_unit_system.length z = 789.0 | generic_unit_system.length def get_length_x(self): return self.x def set_length_x(self, value): self.x = value def get_length_y(self): return self.y def set_length_y(self, value): self.y = value def get_length_z(self): return self.z def set_length_z(self, value): self.z = value o = TestModule() parameters_handler = HandleParameters(o) parameters_handler.add_vector_parameter( "mesh_length", "length of the model in the x, y and z directions", ("length_x", "length_y", "length_z") ) for par_name in ["length_x", "length_y", "length_z"]: parameters_handler.add_method_parameter( "get_"+par_name, "set_"+par_name, par_name, "a test parameter", default_value = 10.0 | generic_unit_system.length, ) x = parameters_handler.get_attribute(None, None) self.assertTrue("mesh_length" in str(x)) self.assertTrue("[123.0, 456.0, 789.0] length" in str(x)) converter = generic_unit_converter.ConvertBetweenGenericAndSiUnits(2.0 | units.m, 4.0 | units.kg, 6.0 | units.s) y = parameters.ParametersWithUnitsConverted( x, converter.as_converter_from_si_to_generic() ) self.assertTrue("mesh_length" in str(y)) self.assertTrue("[246.0, 912.0, 1578.0] m" in str(y))