Skip to content

Commit

Permalink
Standardize python property vs function on Property class. Refs #6677
Browse files Browse the repository at this point in the history
Now behaves more consistently and like the original.
  • Loading branch information
martyngigg committed Mar 14, 2013
1 parent 62cc500 commit b701fc7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,35 @@ void export_Property()
.value("None", Direction::None)
;

// Add properties as that's what old version had
class_<Property, boost::noncopyable>("Property", no_init)
.add_property("name", make_function(&Mantid::Kernel::Property::name, return_value_policy<copy_const_reference>()),
"The name of the property")
.add_property("documentation", make_function(&Mantid::Kernel::Property::documentation, return_value_policy<copy_const_reference>()),
"The property's doc string")

.add_property("isValid", make_function(&Mantid::Kernel::Property::isValid),
"An empty string if the property is valid, otherwise it contains an error message.")

.add_property("isDefault", make_function(&Mantid::Kernel::Property::isDefault), "Is the property set at the default value")

.add_property("getDefault", make_function(&Mantid::Kernel::Property::getDefault), "Get the default value as a string")

.add_property("direction", &Mantid::Kernel::Property::direction,
"Input, Output, InOut or Unknown. See the Direction class")

.add_property("documentation", make_function(&Mantid::Kernel::Property::documentation, return_value_policy<copy_const_reference>()),
"The property's doc string")

.add_property("type", make_function(&Mantid::Kernel::Property::type), "Returns a string identifier for the type")

.add_property("units", make_function(&Mantid::Kernel::Property::units, return_value_policy<copy_const_reference>()),
"The units attached to this property")

.add_property("valueAsStr", &Mantid::Kernel::Property::value, "The value of the property as a string. "
"For some property types, e.g. Workspaces, it is useful to be able to refer to the string value directly")

.add_property("allowedValues", &Mantid::Kernel::Property::allowedValues, "A list of allowed values")
.def("isValid", &Mantid::Kernel::Property::isValid, "An empty string if the property is valid, otherwise it contains an error message.")
.def("isDefault", &Mantid::Kernel::Property::isDefault, "Is the property set at the default value")
.def("getGroup", &Mantid::Kernel::Property::getGroup, return_value_policy<copy_const_reference>(),

.add_property("getGroup", make_function(&Mantid::Kernel::Property::getGroup, return_value_policy<copy_const_reference>()),
"Return the 'group' of the property, that is, the header in the algorithm's list of properties.")
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ class FilePropertyTest(unittest.TestCase):

def test_constructor_with_name_and_default_and_action(self):
prop = FileProperty("LoadProperty", "", FileAction.Load)
self.assertNotEquals("", prop.isValid())
self.assertNotEquals("", prop.isValid)
self.assertEquals(Direction.Input, prop.direction)

def test_constructor_with_name_and_default_and_action_and_exts_list(self):
prop = FileProperty("LoadProperty", "", FileAction.Load, ['.nxs', '.raw'])
self.assertNotEquals("", prop.isValid())
self.assertNotEquals("", prop.isValid)
self.assertEquals(Direction.Input, prop.direction)
allowed = prop.allowedValues
self.assertTrue('.nxs' in allowed)
self.assertTrue('.raw' in allowed)

def test_constructor_with_name_and_default_and_action_and_single_ext(self):
prop = FileProperty("LoadProperty", "", FileAction.Load, '.nxs')
self.assertNotEquals("", prop.isValid())
self.assertNotEquals("", prop.isValid)
self.assertEquals(Direction.Input, prop.direction)
allowed = prop.allowedValues
self.assertTrue('.nxs' in allowed)

def test_constructor_with_name_and_default_and_action_and_single_ext_and_direction(self):
prop = FileProperty("LoadProperty", "", FileAction.Load, ['.nxs'], Direction.InOut)
self.assertNotEquals("", prop.isValid())
self.assertNotEquals("", prop.isValid)
self.assertEquals(Direction.InOut, prop.direction)

def test_alg_get_property_converts_to_this(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def PyExec(self):

def_dir = alg.getProperty("NumPropWithDefaultDir")
self.assertEquals(def_dir.direction, Direction.Input)
self.assertNotEquals("", def_dir.isValid())
self.assertNotEquals("", def_dir.isValid)
self.assertRaises(ValueError, alg.setProperty, "NumPropWithDefaultDir", -10)
testhelpers.assertRaisesNothing(self, alg.setProperty, "NumPropWithDefaultDir", 11)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_name_validator_direction_constructor_gives_correct_object(self):
validator = NullValidator()
arr = FloatArrayProperty(name, validator, direc)
self._check_object_attributes(arr, name, direc)
self.assertEquals(arr.isValid(), "")
self.assertEquals(arr.isValid, "")

def test_name_string_values_validator_direction_constructor_gives_correct_object(self):
"""
Expand All @@ -55,7 +55,7 @@ def test_name_string_values_validator_direction_constructor_gives_correct_object
values_str = "1.345,34.2,5345.3,4,5.3948"
arr = FloatArrayProperty(name, values_str, validator, direc)
self._check_object_attributes(arr, name, direc, length = 5)
self.assertEquals(arr.isValid(), "")
self.assertEquals(arr.isValid, "")
values = arr.value
self.assertTrue(isinstance(values, np.ndarray))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def _do_validation_test(self, validation):
"""Run the validator tests"""
test_alg = self._create_test_algorithm(validation)
prop = test_alg.getProperty("Input")
self.assertNotEquals(prop.isValid(), "")
self.assertNotEquals(prop.isValid, "")
test_alg.setProperty("Input", 6.8)
self.assertEquals(prop.isValid(), "")
self.assertEquals(prop.isValid, "")
self.assertRaises(ValueError, test_alg.setProperty, "Input", 15)

def _create_test_algorithm(self, validator):
Expand Down

0 comments on commit b701fc7

Please sign in to comment.