Skip to content

Commit

Permalink
Export exists method on python AlgorithmFactory.
Browse files Browse the repository at this point in the history
Refs #5157
  • Loading branch information
martyngigg committed Apr 1, 2014
1 parent 7268e6d commit a125277
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -6,6 +6,7 @@

#include <boost/python/class.hpp>
#include <boost/python/def.hpp>
#include <boost/python/overloads.hpp>
#include <Poco/ScopedLock.h>

// Python frameobject. This is under the boost includes so that boost will have done the
Expand Down Expand Up @@ -96,6 +97,8 @@ GCC_DIAG_OFF(cast-qual)
FileLoaderRegistry::Instance().unsubscribe(descr.first, descr.second);
}

BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(existsOverloader, exists, 1, 2);

///@endcond
}
GCC_DIAG_ON(cast-qual)
Expand All @@ -104,8 +107,14 @@ void export_AlgorithmFactory()
{

class_<AlgorithmFactoryImpl,boost::noncopyable>("AlgorithmFactoryImpl", no_init)
.def("exists", &AlgorithmFactoryImpl::exists,
existsOverloader((arg("name"), arg("version")=-1),
"Returns true if the given algorithm exists with an option to specify the version"))

.def("getRegisteredAlgorithms", &getRegisteredAlgorithms, "Returns a Python dictionary of currently registered algorithms")

.def("subscribe", &subscribe, "Register a Python class derived from PythonAlgorithm into the factory")

.def("Instance", &AlgorithmFactory::Instance, return_value_policy<reference_existing_object>(),
"Returns a reference to the AlgorithmFactory singleton")
.staticmethod("Instance")
Expand Down
Expand Up @@ -14,7 +14,12 @@ class AlgorithmFactoryTest(unittest.TestCase):

def test_get_algorithm_factory_does_not_return_None(self):
self.assertTrue(AlgorithmFactory is not None )


def test_exists_returns_correct_value_for_given_args(self):
self.assertTrue(AlgorithmFactory.exists('ConvertUnits')) #any version
self.assertTrue(AlgorithmFactory.exists('ConvertUnits', 1)) #any version
self.assertTrue(not AlgorithmFactory.exists('ConvertUnits', 100)) #any version

def test_get_registered_algs_returns_dictionary_of_known_algorithms(self):
all_algs = AlgorithmFactory.getRegisteredAlgorithms(True)
self.assertTrue( len(all_algs) > 0 )
Expand Down

0 comments on commit a125277

Please sign in to comment.