Skip to content

Commit

Permalink
Export more parts of AlgorithmManager to Python
Browse files Browse the repository at this point in the history
Refs #8971
  • Loading branch information
martyngigg committed Mar 10, 2014
1 parent d156bdf commit ea59a55
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
@@ -1,17 +1,29 @@
#include "MantidAPI/AlgorithmManager.h"
#include "MantidPythonInterface/api/AlgorithmIDProxy.h"

#include <boost/python/class.hpp>
#include <boost/python/def.hpp>
#include <boost/python/overloads.hpp>
#include <boost/python/return_value_policy.hpp>
#include <boost/python/reference_existing_object.hpp>

using Mantid::API::AlgorithmManagerImpl;
using Mantid::API::AlgorithmManager;
using namespace Mantid::API;
using Mantid::PythonInterface::AlgorithmIDProxy;
using namespace boost::python;

namespace
{
/**
* Return the algorithm identified by the given ID. A wrapper version that takes a
* AlgorithmIDProxy that wraps a AlgorithmID
* @param self The calling object
* @param id An algorithm ID
*/
IAlgorithm_sptr getAlgorithm(AlgorithmManagerImpl &self, AlgorithmIDProxy idHolder)
{
return self.getAlgorithm(idHolder.id);
}

///@cond
//------------------------------------------------------------------------------------------------------
/// Define overload generators
Expand All @@ -26,6 +38,16 @@ void export_AlgorithmManager()
.def("create", &AlgorithmManagerImpl::create, create_overloads((arg("name"), arg("version")), "Creates a managed algorithm."))
.def("createUnmanaged", &AlgorithmManagerImpl::createUnmanaged,
createUnmanaged_overloads((arg("name"), arg("version")), "Creates an unmanaged algorithm."))
.def("size", &AlgorithmManagerImpl::size, "Returns the number of managed algorithms")
.def("setMaxAlgorithms", &AlgorithmManagerImpl::setMaxAlgorithms,
"Set the maximum number of allowed managed algorithms")
.def("getAlgorithm", &getAlgorithm,
"Return the algorithm instance identified by the given id.")

.def("clear", &AlgorithmManagerImpl::clear, "Clears the current list of managed algorithms")
.def("cancelAll", &AlgorithmManagerImpl::cancelAll,
"Requests that all currently running algorithms be cancelled")

.def("Instance", &AlgorithmManager::Instance, return_value_policy<reference_existing_object>(),
"Returns a reference to the AlgorithmManager singleton")
.staticmethod("Instance")
Expand Down
Expand Up @@ -29,6 +29,23 @@ def test_unmanaged_cppalg_isinstance_of_Algorithm(self):
alg = AlgorithmManager.createUnmanaged("ConvertUnits")
self.assertTrue(isinstance(alg, Algorithm))

def test_size_reports_number_of_managed_algorithms(self):
old_size = AlgorithmManager.size()
new_alg = AlgorithmManager.create("ConvertUnits")
new_size = AlgorithmManager.size()
self.assertTrue(new_size == old_size + 1)

def test_getAlgorithm_returns_correct_instance(self):
returned_instance = AlgorithmManager.create("ConvertUnits")
id = returned_instance.getAlgorithmID()
mgr_instance = AlgorithmManager.getAlgorithm(id)
self.assertEquals(id, mgr_instance.getAlgorithmID())

def test_clear_removes_all_managed_algorithms(self):
AlgorithmManager.clear()
new_size = AlgorithmManager.size()
self.assertEquals(0, new_size)


if __name__ == '__main__':
unittest.main()

0 comments on commit ea59a55

Please sign in to comment.