-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resurrect test for Python instrument export.
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
1 parent
7ce819c
commit 8a1706b
Showing
2 changed files
with
58 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 45 additions & 14 deletions
59
Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/InstrumentTest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |