Skip to content

Commit

Permalink
Resurrect test for Python instrument export.
Browse files Browse the repository at this point in the history
It had been implemented incorrectly and it looked as if it was passing
when it wasn't.
There was also a bug with the getReferenceFrame import that this also
caught and fixed.
Refs #8000
  • Loading branch information
martyngigg committed Sep 24, 2013
1 parent 7ce819c commit 8a1706b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,28 @@ void export_Instrument()
REGISTER_SHARED_PTR_TO_PYTHON(Instrument);

class_<Instrument, bases<CompAssembly>, boost::noncopyable>("Instrument", no_init)
.def("getSample", (boost::shared_ptr<IObjComponent> (Instrument::*)())&Instrument::getSample,
.def("getSample", (boost::shared_ptr<IObjComponent> (Instrument::*)())&Instrument::getSample,
"Return the object that represents the sample")

.def("getSource", (boost::shared_ptr<IObjComponent> (Instrument::*)())&Instrument::getSource,
"Return the object that represents the source")

.def("getComponentByName", (boost::shared_ptr<IComponent> (Instrument::*)(const std::string&))&Instrument::getComponentByName,
"Returns the named component")

.def("getDetector", (boost::shared_ptr<IDetector> (Instrument::*)(const detid_t&)const)&Instrument::getDetector,
"Returns the dector with the given ID")
.def("getReferenceFrame", (boost::shared_ptr<const ReferenceFrame> (Instrument::*)())&Instrument::getReferenceFrame )

.def("getReferenceFrame", (boost::shared_ptr<const ReferenceFrame> (Instrument::*)())&Instrument::getReferenceFrame,
return_value_policy<RemoveConstSharedPtr>(),
"Returns the reference frame attached that defines the instrument axes")

.def("getValidFromDate", &Instrument::getValidFromDate, "Return the valid from date of the instrument")

.def("getValidToDate", &Instrument::getValidToDate, "Return the valid to date of the instrument")
.def("getBaseInstrument", &Instrument::baseInstrument,return_value_policy<RemoveConstSharedPtr>(), "Return reference to the base instrument")

.def("getBaseInstrument", &Instrument::baseInstrument,return_value_policy<RemoveConstSharedPtr>(),
"Return reference to the base instrument")
;
;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,52 @@
import unittest
from mantid.geometry import Instrument
from testhelpers import can_be_instantiated
from mantid.kernel import DateAndTime
from mantid.geometry import(Detector, Instrument, ObjComponent, ReferenceFrame)
from testhelpers import can_be_instantiated, WorkspaceCreationHelper

class InstrumentTest(object):
class InstrumentTest(unittest.TestCase):

__testws = None

def setUp(self):
if self.__testws is None:
self.__class__.__testws = \
WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument(1,1)

def test_Instrument_cannot_be_instantiated(self):
self.assertFalse(can_be_instantiated(Instrument))

def test_Instrument_has_expected_attrs(self):
expected_attrs = ["getSample", "getSource",
"getComponentByName", "getDetector",
"nelements", "__getitem__",
"get_parameter_names", "has_parameter",
"get_number_parameter", "get_position_parameter",
"get_rotation_parameter", "get_string_parameter",
"get_pos", "get_distance", "get_name", "type"]
for att in expected_attrs:
self.assertTrue(att in attrs)
def test_getSample(self):
sample_pos = self.__testws.getInstrument().getSample()
self.assertTrue(isinstance(sample_pos, ObjComponent))

def test_getSource(self):
source_pos = self.__testws.getInstrument().getSource()
self.assertTrue(isinstance(source_pos, ObjComponent))

def test_getComponentByName(self):
comp = self.__testws.getInstrument().getComponentByName("pixel-0)")
self.assertTrue(isinstance(comp, Detector))

def test_getDetector(self):
comp = self.__testws.getInstrument().getDetector(1)
self.assertTrue(isinstance(comp, Detector))

def test_getReferenceFrame(self):
frame = self.__testws.getInstrument().getReferenceFrame()
self.assertTrue(isinstance(frame, ReferenceFrame))

def test_ValidDates(self):
inst = self.__testws.getInstrument()
valid_from = inst.getValidFromDate()
valid_to = inst.getValidToDate()

self.assertTrue(isinstance(valid_from, DateAndTime))
self.assertTrue(isinstance(valid_to, DateAndTime))

if __name__ == '__main__': unittest.main()
def test_baseInstrument_Can_Be_Retrieved(self):
inst = self.__testws.getInstrument()
base_inst = inst.getBaseInstrument()
self.assertEquals("testInst", base_inst.getName())

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

0 comments on commit 8a1706b

Please sign in to comment.