Skip to content

Commit

Permalink
Export ArrayBoundedValidator. Refs #4399
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Apr 16, 2012
1 parent 233e406 commit 49edeef
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 73 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/Kernel/src/ArrayBoundedValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ void ArrayBoundedValidator<TYPE>::clearUpper()
// Required explicit instantiations
template class ArrayBoundedValidator<double>;
template class ArrayBoundedValidator<int>;
template class ArrayBoundedValidator<long>;

} // Kernel
} // Mantid
1 change: 1 addition & 0 deletions Code/Mantid/Framework/Kernel/src/ArrayLengthValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ namespace Kernel
// Required explicit instantiations
template class ArrayLengthValidator<double>;
template class ArrayLengthValidator<int>;
template class ArrayLengthValidator<long>;
template class ArrayLengthValidator<std::string>;
} // namespace Mantid
} // namespace Kernel
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/PythonInterface/mantid/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
###############################################################################
import mantid.kernel.plugins as _plugins
# Algorithms
from mantid.kernel import config as _cfg
from mantid.kernel import config as _config
# Disabled for the time being as all algorithms are of the old kind
#_plugins.load(_cfg['pythonalgorithm.directories'])
#_plugins.load(_config['pythonalgorithm.directories'])
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ set ( PY_FILES
dlopen.py
funcreturns.py
plugins.py
validators.py
)

#############################################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
dlopen.restore_flags(flags)
###############################################################################

from validators import *
from _aliases import *
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ namespace
void export_ArrayBoundedValidator()
{
EXPORT_ARRAYBOUNDEDVALIDATOR(double, Float);
EXPORT_ARRAYBOUNDEDVALIDATOR(int, Int);
EXPORT_ARRAYBOUNDEDVALIDATOR(long, Int);
}

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace
void export_ArrayLengthValidator()
{
EXPORT_LENGTHVALIDATOR(double, Float);
EXPORT_LENGTHVALIDATOR(int, Int);
EXPORT_LENGTHVALIDATOR(long, Int);
EXPORT_LENGTHVALIDATOR(std::string, String);
}

Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,14 @@ namespace

void export_ArrayProperty()
{
// Match the python names to their C types
EXPORT_ARRAY_PROP(double,Float);
EXPORT_ARRAY_PROP(int,Int);
EXPORT_ARRAY_PROP(size_t,UnsignedInt);
EXPORT_ARRAY_PROP(long, Int);
EXPORT_ARRAY_PROP(std::string, String);

// Needs these declarations also to ensure that properties not created in
// Python can be seen also. Users shouldn't need this
EXPORT_ARRAY_PROP(int, CInt);
EXPORT_ARRAY_PROP(size_t,UnsignedInt);
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ using namespace boost::python;
namespace
{
/// A macro for generating exports for each type
#define EXPORT_BOUNDEDVALIDATOR(ElementType) \
#define EXPORT_BOUNDEDVALIDATOR(ElementType, prefix) \
class_<BoundedValidator<ElementType>, bases<IValidator>, \
boost::noncopyable>("BoundedValidator_"#ElementType) \
boost::noncopyable>(#prefix"BoundedValidator") \
.def(init<ElementType,ElementType>()) \
.def("setLower", &BoundedValidator<ElementType>::setLower, "Set the lower bound") \
.def("setUpper", &BoundedValidator<ElementType>::setUpper, "Set the upper bound" ) \
Expand All @@ -28,8 +28,7 @@ namespace

void export_BoundedValidator()
{
EXPORT_BOUNDEDVALIDATOR(double);
EXPORT_BOUNDEDVALIDATOR(int);
EXPORT_BOUNDEDVALIDATOR(long);
EXPORT_BOUNDEDVALIDATOR(double, Float);
EXPORT_BOUNDEDVALIDATOR(long, Int);
}

44 changes: 0 additions & 44 deletions Code/Mantid/Framework/PythonInterface/mantid/kernel/validators.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ def test_setMinMaxLength_alters_accepted_range(self):
validator.clearLengthMax()
self.assertFalse(validator.hasMinLength())
self.assertFalse(validator.hasMaxLength())



def test_Validator_on_ArrayProperty_accepts_array_of_specified_length(self):
fixedlength = 6
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import unittest
import testhelpers
from mantid import BoundedValidator
from mantid import FloatBoundedValidator, IntBoundedValidator

class BoundedValidatorTest(object):

def test_construction_does_not_raise_error_when_both_are_floats(self):
testhelpers.assertRaisesNothing(self, BoundedValidator, 1.0, 2.0)
testhelpers.assertRaisesNothing(self, FloatBoundedValidator, 1.0, 2.0)

def test_construction_does_not_raise_error_when_both_are_ints(self):
testhelpers.assertRaisesNothing(self, BoundedValidator, 1, 20)

def test_construction_raises_error_when_called_with_no_params(self):
self.assertRaises(TypeError, BoundedValidator())
testhelpers.assertRaisesNothing(self, IntBoundedValidator, 1, 20)

def test_construction_with_lower_sets_only_lower(self):
validator = BoundedValidator(lower=1)
validator = FloatBoundedValidator()
lower = 1.4
validator.setLower(lower)
self.assertEquals(validator.hasLower(), True)
self.assertEquals(validator.hasUpper(), False)
self.assertEquals(validator.lower(), 1)
self.assertEquals(validator.lower(), lower)

def test_construction_with_upper_sets_only_upper(self):
validator = BoundedValidator(upper=5.0)
validator = FloatBoundedValidator()
upper = 5.4
validator.setUpper(upper)
self.assertEquals(validator.hasUpper(), True)
self.assertEquals(validator.hasLower(), False)
self.assertEquals(validator.upper(), 5.0)

self.assertEquals(validator.upper(), upper)

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import testhelpers

from mantid import PythonAlgorithm, Direction
from mantid import BoundedValidator, FileProperty, FileAction
from mantid import IntBoundedValidator, FileProperty, FileAction


# ======================================================================
Expand Down Expand Up @@ -67,8 +67,10 @@ def test_properties_obey_attached_validators(self):
class PropertiesWithValidation(PythonAlgorithm):

def PyInit(self):
self.declareProperty('NumPropWithDefaultDir', -1, BoundedValidator(lower=0))
self.declareProperty('NumPropWithInOutDir', -1, BoundedValidator(lower=0),"doc string", Direction.InOut)
only_positive = IntBoundedValidator()
only_positive.setLower(0)
self.declareProperty('NumPropWithDefaultDir', -1, only_positive)
self.declareProperty('NumPropWithInOutDir', -1, only_positive,"doc string", Direction.InOut)

def PyExec(self):
pass
Expand Down

0 comments on commit 49edeef

Please sign in to comment.