Skip to content

Commit

Permalink
Refs #10135. Added python unit tests
Browse files Browse the repository at this point in the history
Since it appears to be impossible to export shared_ptr<const T> to python, the pointer from the factory has to be const-casted before it's returned.
  • Loading branch information
Michael Wedel committed Sep 11, 2014
1 parent 1ba49c6 commit bdb8289
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
Expand Up @@ -6,12 +6,23 @@
using namespace Mantid::Geometry;
using namespace boost::python;

namespace {
using namespace Mantid::PythonInterface;

SymmetryOperation_sptr createSymOpPython(SymmetryOperationFactoryImpl & self, const std::string &identifier)
{
SymmetryOperation_const_sptr constSymOp = self.createSymOp(identifier);

return boost::const_pointer_cast<SymmetryOperation>(constSymOp);
}
}

void export_SymmetryOperationFactory()
{

class_<SymmetryOperationFactoryImpl,boost::noncopyable>("SymmetryOperationFactoryImpl", no_init)
.def("exists", &SymmetryOperationFactoryImpl::exists)
.def("createSymOp", &SymmetryOperationFactoryImpl::createSymOp)
.def("createSymOp", &createSymOpPython)
.def("getKeys", &SymmetryOperationFactoryImpl::getKeys, "Returns all registered symmetry operations")
.def("Instance", &SymmetryOperationFactory::Instance, return_value_policy<reference_existing_object>(),
"Returns a reference to the SymmetryOperationFactory singleton")
Expand Down
Expand Up @@ -10,6 +10,8 @@ set ( TEST_PY_FILES
RectangularDetectorTest.py
ReferenceFrameTest.py
UnitCellTest.py
PointGroupTest.py
SymmetryOperationTest.py
)

check_tests_valid ( ${CMAKE_CURRENT_SOURCE_DIR} ${TEST_PY_FILES} )
Expand Down
@@ -0,0 +1,47 @@
import unittest
from mantid.geometry import PointGroup, PointGroupFactoryImpl
from mantid.kernel import V3D

class PointGroupTest(unittest.TestCase):

def test_creation(self):
self.assertRaises(RuntimeError, PointGroupFactoryImpl.Instance().createPointGroup, "none")

PointGroupFactoryImpl.Instance().createPointGroup("m-3m")

def test_getInfo(self):
pg = PointGroupFactoryImpl.Instance().createPointGroup("m-3m")
self.assertEquals(pg.getName(), "m-3m (Cubic)")
self.assertEquals(pg.getSymbol(), "m-3m")
self.assertEquals(pg.crystalSystem(), PointGroup.CrystalSystem.Cubic)

def test_isEquivalent(self):
hkl1 = V3D(1, 1, 1)
hkl2 = V3D(-1, -1, -1)
hkl3 = V3D(-1, -1, 2)

pg = PointGroupFactoryImpl.Instance().createPointGroup("m-3m")
self.assertTrue(pg.isEquivalent(hkl1, hkl2))
self.assertFalse(pg.isEquivalent(hkl1, hkl3))

def test_getEquivalents(self):
hkl1 = V3D(1, 0, 0)
hkl2 = V3D(-1, 0, 0)

pg = PointGroupFactoryImpl.Instance().createPointGroup("-1")
equivalents = pg.getEquivalents(hkl1)

self.assertTrue(hkl1 in equivalents)
self.assertTrue(hkl2 in equivalents)

self.assertEquals(len(equivalents), 2)

def test_getReflectionFamily(self):
hkl1 = V3D(0, 0, 1)
hkl2 = V3D(-1, 0, 0)

pg = PointGroupFactoryImpl.Instance().createPointGroup("m-3m")
self.assertEquals(pg.getReflectionFamily(hkl1), pg.getReflectionFamily(hkl2))

if __name__ == '__main__':
unittest.main()
@@ -0,0 +1,28 @@
import unittest
from mantid.geometry import SymmetryOperation, SymmetryOperationFactoryImpl
from mantid.kernel import V3D

class SymmetryOperationTest(unittest.TestCase):

def test_creation(self):
self.assertRaises(RuntimeError, SymmetryOperationFactoryImpl.Instance().createSymOp, "none")

SymmetryOperationFactoryImpl.Instance().createSymOp("m [001]")

def test_getInfo(self):
symOp = SymmetryOperationFactoryImpl.Instance().createSymOp("m [001]")
self.assertEquals(symOp.order(), 2)
self.assertEquals(symOp.identifier(), "m [001]")

def test_apply(self):
symOp = SymmetryOperationFactoryImpl.Instance().createSymOp("m [001]")

hkl1 = V3D(1, 1, 1)
hkl2 = symOp.apply(hkl1)

self.assertEquals(hkl2, V3D(1, 1, -1))
self.assertEquals(symOp.apply(hkl2), hkl1)


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

0 comments on commit bdb8289

Please sign in to comment.