Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feature/8947_propertysettings_to…
…_python'
- Loading branch information
Showing
11 changed files
with
205 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/EnabledWhenProperty.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "MantidKernel/EnabledWhenProperty.h" | ||
#include <boost/python/class.hpp> | ||
#include <boost/python/enum.hpp> | ||
|
||
using namespace Mantid::Kernel; | ||
using namespace boost::python; | ||
|
||
void export_EnabledWhenProperty() | ||
{ | ||
// State enumeration | ||
enum_<ePropertyCriterion>("PropertyCriterion") | ||
.value("IsDefault", IS_DEFAULT) | ||
.value("IsNotDefault", IS_NOT_DEFAULT) | ||
.value("IsEqualTo", IS_EQUAL_TO) | ||
.value("IsNotEqualTo", IS_NOT_EQUAL_TO) | ||
.value("IsMoreOrEqual", IS_MORE_OR_EQ) | ||
; | ||
|
||
class_<EnabledWhenProperty, bases<IPropertySettings>, | ||
boost::noncopyable>("EnabledWhenProperty", no_init) // no default constructor | ||
|
||
.def(init<std::string, ePropertyCriterion, std::string>( | ||
(arg("otherPropName"), arg("when"), arg("value")), | ||
"Enabled otherPropName property when value criterion meets that given by the 'when' argument") | ||
) | ||
|
||
.def(init<std::string, ePropertyCriterion>( | ||
(arg("otherPropName"), arg("when")), | ||
"Enabled otherPropName property when criterion does not require a value, i.e isDefault") | ||
) | ||
; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/IPropertySettings.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "MantidKernel/IPropertySettings.h" | ||
#include "MantidKernel/IPropertyManager.h" | ||
#include <boost/python/class.hpp> | ||
#include <boost/python/register_ptr_to_python.hpp> | ||
|
||
using Mantid::Kernel::IPropertySettings; | ||
using namespace boost::python; | ||
|
||
void export_IPropertySettings() | ||
{ | ||
register_ptr_to_python<IPropertySettings*>(); | ||
|
||
class_<IPropertySettings,boost::noncopyable>("IPropertySettings", no_init) | ||
.def("isEnabled", &IPropertySettings::isEnabled, | ||
"Is the property to be shown as enabled in the GUI. Default true.") | ||
|
||
.def("isVisible", &IPropertySettings::isVisible, | ||
"Is the property to be shown in the GUI? Default true.") | ||
; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/VisibleWhenProperty.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "MantidKernel/VisibleWhenProperty.h" | ||
#include <boost/python/class.hpp> | ||
|
||
using namespace Mantid::Kernel; | ||
using namespace boost::python; | ||
|
||
void export_VisibleWhenProperty() | ||
{ | ||
class_<VisibleWhenProperty, bases<EnabledWhenProperty>, | ||
boost::noncopyable>("VisibleWhenProperty", no_init) | ||
.def(init<std::string, ePropertyCriterion, std::string>( | ||
(arg("otherPropName"), arg("when"), arg("value")), | ||
"Enabled otherPropName property when value criterion meets that given by the 'when' argument") | ||
) | ||
|
||
.def(init<std::string, ePropertyCriterion>( | ||
(arg("otherPropName"), arg("when")), | ||
"Enabled otherPropName property when criterion does not require a value, i.e isDefault") | ||
) | ||
; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/EnabledWhenPropertyTest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import unittest | ||
from mantid.kernel import EnabledWhenProperty, PropertyCriterion | ||
|
||
class EnabledWhenPropertyTest(unittest.TestCase): | ||
|
||
def test_construction_with_name_criterion_only_succeeds(self): | ||
p = EnabledWhenProperty("OtherProperty", PropertyCriterion.IsDefault) | ||
|
||
def test_construction_with_name_criterion_value_succeeds(self): | ||
p = EnabledWhenProperty("OtherProperty", PropertyCriterion.IsEqualTo, "value") | ||
|
||
def test_Property_Criterion_Has_Expected_Attrs(self): | ||
attrs = ["IsNotDefault", "IsEqualTo", "IsNotEqualTo", "IsMoreOrEqual"] | ||
for att in attrs: | ||
self.assertTrue(hasattr(PropertyCriterion, att)) | ||
|
||
#------------ Failure cases ------------------ | ||
|
||
def test_default_construction_raises_error(self): | ||
try: | ||
EnabledWhenProperty() | ||
self.fail("Expected default constructor to raise an error") | ||
except Exception, e: | ||
# boost.python.ArgumentError are not catchable | ||
if "Python argument types in" not in str(e): | ||
raise RuntimeError("Unexpected exception type raised") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
14 changes: 14 additions & 0 deletions
14
Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/IPropertySettingsTest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import unittest | ||
from mantid.kernel import IPropertySettings | ||
|
||
class IPropertySettingsTest(unittest.TestCase): | ||
|
||
def test_construction_raises_an_exception(self): | ||
self.assertRaises(RuntimeError, IPropertySettings) | ||
|
||
def test_interface_has_expected_attrs(self): | ||
self.assertTrue(hasattr(IPropertySettings, "isEnabled")) | ||
self.assertTrue(hasattr(IPropertySettings, "isVisible")) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
24 changes: 24 additions & 0 deletions
24
Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/VisibleWhenPropertyTest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import unittest | ||
from mantid.kernel import VisibleWhenProperty, PropertyCriterion | ||
|
||
class VisibleWhenPropertyTest(unittest.TestCase): | ||
|
||
def test_construction_with_name_criterion_only_succeeds(self): | ||
p = VisibleWhenProperty("OtherProperty", PropertyCriterion.IsDefault) | ||
|
||
def test_construction_with_name_criterion_value_succeeds(self): | ||
p = VisibleWhenProperty("OtherProperty", PropertyCriterion.IsEqualTo, "value") | ||
|
||
#------------ Failure cases ------------------ | ||
|
||
def test_default_construction_raises_error(self): | ||
try: | ||
VisibleWhenProperty() | ||
self.fail("Expected default constructor to raise an error") | ||
except Exception, e: | ||
# boost.python.ArgumentError are not catchable | ||
if "Python argument types in" not in str(e): | ||
raise RuntimeError("Unexpected exception type raised") | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |