Skip to content

Commit

Permalink
refs #10904. Python tests for PeakShape.
Browse files Browse the repository at this point in the history
Also fix GCC and Windows warnings
  • Loading branch information
OwenArnold committed Feb 9, 2015
1 parent 5612143 commit 8996ec6
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IPeak.h
Expand Up @@ -3,6 +3,7 @@

#include "MantidAPI/DllConfig.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Crystal/PeakShape.h"
#include "MantidKernel/Matrix.h"
#include "MantidKernel/V3D.h"
#include "MantidKernel/PhysicalConstants.h"
Expand Down Expand Up @@ -84,6 +85,8 @@ class MANTID_API_DLL IPeak {
virtual Mantid::Kernel::V3D getDetPos() const = 0;
virtual double getL1() const = 0;
virtual double getL2() const = 0;

virtual const Mantid::Geometry::PeakShape& getPeakShape() = 0;
};

} // namespace Mantid
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/API/test/MockObjects.h
Expand Up @@ -10,7 +10,7 @@

#include "MantidAPI/PeakTransform.h"
#include "MantidAPI/PeakTransformFactory.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidAPI/PeaksWorkspace.h"
#include "MantidAPI/IPeak.h"
#include <boost/regex.hpp>
#include <gmock/gmock.h>
Expand Down Expand Up @@ -156,6 +156,7 @@ namespace
Mantid::Kernel::V3D());
MOCK_CONST_METHOD0(getDetectorPositionNoCheck,
Mantid::Kernel::V3D());
MOCK_METHOD0(getPeakShape, const Mantid::Geometry::PeakShape&());
};


Expand Down
Expand Up @@ -51,7 +51,7 @@ PeakShapeSpherical::PeakShapeSpherical(const double &peakRadius,
PeakShapeSpherical::~PeakShapeSpherical() {}

/**
* @brief Copy constructor
* @brief Copy constructor from other PeakShapeSpherical
* @param other : source of the copy
*/
PeakShapeSpherical::PeakShapeSpherical(const PeakShapeSpherical &other)
Expand Down
Expand Up @@ -11,6 +11,7 @@
#include <jsoncpp/json/json.h>

using Mantid::DataObjects::PeakShapeEllipsoid;
using Mantid::Kernel::SpecialCoordinateSystem;
using namespace Mantid;
using namespace Mantid::Kernel;
using namespace boost::assign;
Expand Down
Expand Up @@ -5,6 +5,13 @@
using Mantid::API::IPeak;
using namespace boost::python;

namespace {
Mantid::Geometry::PeakShape_sptr getPeakShape(IPeak& peak) {
// Use clone to make a copy of the PeakShape.
return Mantid::Geometry::PeakShape_sptr(peak.getPeakShape().clone());
}
}

void export_IPeak()
{
register_ptr_to_python<IPeak*>();
Expand Down Expand Up @@ -53,6 +60,7 @@ void export_IPeak()
.def("getDetPos", &IPeak::getDetPos, "Return the detector position vector")
.def("getL1", &IPeak::getL1, "Return the L1 flight path length (source to sample), in meters. ")
.def("getL2", &IPeak::getL2, "Return the L2 flight path length (sample to detector), in meters.")
.def("getPeakShape", getPeakShape, "Get the peak shape")
;
}

Expand Up @@ -8,7 +8,7 @@ using namespace boost::python;

void export_PeakShape()
{
register_ptr_to_python<PeakShape*>();
register_ptr_to_python<Mantid::Geometry::PeakShape_sptr>();

class_<PeakShape, boost::noncopyable>("PeakShape", no_init)
.def("toJSON", &PeakShape::toJSON, "Serialize object to JSON")
Expand Down
Expand Up @@ -11,6 +11,7 @@ set ( TEST_PY_FILES
RectangularDetectorTest.py
ReferenceFrameTest.py
UnitCellTest.py
PeakShapeTest.py
PointGroupTest.py
SpaceGroupTest.py
SymmetryOperationTest.py
Expand Down
@@ -0,0 +1,17 @@
import unittest
from mantid.simpleapi import CreatePeaksWorkspace, CreateSampleWorkspace
from mantid.geometry import PeakShape

class PeakShapeTest(unittest.TestCase):

def test_basic_access(self):
sampleWs = CreateSampleWorkspace()
ws = CreatePeaksWorkspace(InstrumentWorkspace=sampleWs,NumberOfPeaks=1)
peak = ws.getPeak(0)
peak_shape = peak.getPeakShape()
self.assertTrue(isinstance(peak_shape, PeakShape))
self.assertEquals(peak_shape.shapeName(), "none")


if __name__ == '__main__':
unittest.main()
3 changes: 2 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/test/MockObjects.h
Expand Up @@ -253,7 +253,8 @@ class MockPeakTransformFactory : public PeakTransformFactory
Mantid::Kernel::V3D());
MOCK_CONST_METHOD0(getDetectorPositionNoCheck,
Mantid::Kernel::V3D());
};
MOCK_METHOD0(getPeakShape, const Mantid::Geometry::PeakShape&());
};

/*------------------------------------------------------------
Mock MDGeometry
Expand Down

0 comments on commit 8996ec6

Please sign in to comment.