-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export the UnitFactory to the new Python API. Refs #5624
- Loading branch information
1 parent
d9eb9e1
commit cce51cb
Showing
5 changed files
with
55 additions
and
3 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
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
25 changes: 25 additions & 0 deletions
25
Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/UnitFactory.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,25 @@ | ||
#include "MantidKernel/UnitFactory.h" | ||
|
||
#include "MantidPythonInterface/kernel/Policies/VectorToNumpy.h" | ||
|
||
#include <boost/python/class.hpp> | ||
#include <boost/python/return_value_policy.hpp> | ||
|
||
using Mantid::Kernel::UnitFactory; | ||
using Mantid::Kernel::UnitFactoryImpl; | ||
namespace Policies = Mantid::PythonInterface::Policies; | ||
namespace Converters = Mantid::PythonInterface::Converters; | ||
using namespace boost::python; | ||
|
||
void export_UnitFactory() | ||
{ | ||
class_<UnitFactoryImpl, boost::noncopyable>("UnitFactoryImpl", no_init) | ||
.def("getKeys", &UnitFactoryImpl::getKeys, return_value_policy<Policies::VectorToNumpy>(), | ||
"Returns a list of units available from the factory") | ||
|
||
.def("Instance", &UnitFactory::Instance, return_value_policy<reference_existing_object>(), | ||
"Returns a reference to the UnitFactory singleton") | ||
.staticmethod("Instance") | ||
; | ||
} | ||
|
24 changes: 24 additions & 0 deletions
24
Code/Mantid/Framework/PythonInterface/test/python/UnitFactoryTest.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 import UnitFactory, UnitFactoryImpl | ||
|
||
class UnitFactoryTest(unittest.TestCase): | ||
|
||
def test_alias_is_of_type_UnitFactoryImpl(self): | ||
self.assertTrue(isinstance(UnitFactory, UnitFactoryImpl)) | ||
|
||
def test_keys_returns_a_non_empty_python_list_of_unit_keys(self): | ||
known_units = UnitFactory.getKeys() | ||
|
||
self.assertEquals(type(known_units), list) | ||
# Check length is at least the known core units | ||
# but allow for others to be added | ||
core_units = ['Empty', 'Label', 'TOF', 'Wavelength','Energy', | ||
'Energy_inWavenumber', 'dSpacing', 'MomentumTransfer', | ||
'QSquared', 'DeltaE', 'DeltaE_inWavenumber', 'Momentum'] | ||
self.assertTrue(len(core_units) <= len(known_units)) | ||
|
||
for unit in core_units: | ||
self.assertTrue(unit in known_units, "%s unit not found in UnitFactory keys" % unit) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |