-
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.
Refs #4399. Exported the WorkspaceProperty constructors.
- Loading branch information
1 parent
0422162
commit 8f0376a
Showing
6 changed files
with
216 additions
and
8 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
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
4 changes: 4 additions & 0 deletions
4
Code/Mantid/Framework/PythonInterface/test/python/PythonAlgorithmPropertiesTest.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
4 changes: 4 additions & 0 deletions
4
Code/Mantid/Framework/PythonInterface/test/python/PythonAlgorithmTraitsTest.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
44 changes: 44 additions & 0 deletions
44
Code/Mantid/Framework/PythonInterface/test/python/PythonAlgorithmWorkspacePropertyTest.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Defines tests for the WorkspaceProperty types within | ||
Python algorithms | ||
""" | ||
import unittest | ||
from mantid.api import PythonAlgorithm, WorkspaceProperty | ||
from mantid.kernel import Direction | ||
|
||
class PythonAlgorithmWorkspacePropertyTest(unittest.TestCase): | ||
|
||
def _do_test(self, classtype): | ||
"""Perform the test for the given type | ||
@param classtype :: The property class to declare | ||
""" | ||
class WorkspaceProperties(PythonAlgorithm): | ||
|
||
_testdocstring = 'This is a workspace property' | ||
def PyInit(self): | ||
self.declareProperty(classtype("NoDocString", "", Direction.Input)) | ||
self.declareProperty(classtype("WithDocString", "", Direction.Input), self._testdocstring) | ||
|
||
def PyExec(self): | ||
pass | ||
####################################################### | ||
alg = WorkspaceProperties() | ||
alg.initialize() | ||
props = alg.getProperties() | ||
self.assertEquals(2, len(props)) | ||
|
||
nodoc = alg.getProperty("NoDocString") | ||
self.assertTrue(isinstance(nodoc, classtype)) | ||
self.assertEquals("", nodoc.documentation) | ||
withdoc = alg.getProperty("WithDocString") | ||
self.assertTrue(isinstance(withdoc, classtype)) | ||
self.assertEquals(alg._testdocstring, withdoc.documentation) | ||
|
||
def test_alg_accepts_WorkspaceProperty_declaration(self): | ||
"""Runs test for a general WorkspaceProperty | ||
""" | ||
self._do_test(WorkspaceProperty) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
|
53 changes: 53 additions & 0 deletions
53
Code/Mantid/Framework/PythonInterface/test/python/WorkspacePropertiesTest.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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Tests the construction of the various workspace | ||
property types | ||
""" | ||
import unittest | ||
import testhelpers | ||
from mantid.api import (WorkspaceProperty, MatrixWorkspaceProperty, IEventWorkspaceProperty, | ||
ITableWorkspaceProperty) | ||
from mantid.kernel import Direction | ||
|
||
class WorkspacePropertiesTest(unittest.TestCase): | ||
|
||
def _do_test(self, classtype): | ||
self._do_construction_with_name_default_direction(classtype) | ||
self._do_construction_with_name_default_direction_optional(classtype) | ||
|
||
def _do_construction_with_name_default_direction(self, classtype): | ||
prop = classtype("NoValidation", "test", Direction.Output) | ||
self.assertTrue(isinstance(prop, classtype)) | ||
self.assertEquals("NoValidation", prop.name) | ||
self.assertEquals(Direction.Output, prop.direction) | ||
self.assertEquals("test", prop.valueAsStr) | ||
|
||
def _do_construction_with_name_default_direction_optional(self, classtype): | ||
prop = classtype("IsOptional", "test", Direction.Output, True) | ||
self.assertTrue(isinstance(prop, classtype)) | ||
self.assertEquals("IsOptional", prop.name) | ||
self.assertEquals(Direction.Output, prop.direction) | ||
self.assertTrue(prop.isOptional()) | ||
self.assertEquals("test", prop.valueAsStr) | ||
|
||
def _do_construction_with_name_default_direction_optional_locking(self, classtype): | ||
prop = classtype("DoesNotLock", "test", Direction.Output, True, False) | ||
self.assertTrue(isinstance(prop, classtype)) | ||
self.assertEquals("DoesNotLock", prop.name) | ||
self.assertEquals(Direction.Output, prop.direction) | ||
self.assertTrue(prop.isOptional()) | ||
self.assertFalse(prop.isLocking()) | ||
self.assertEquals("test", prop.valueAsStr) | ||
|
||
def test_WorkspaceProperty_can_be_instantiated(self): | ||
self._do_test(WorkspaceProperty) | ||
|
||
def test_MatrixWorkspaceProperty_can_be_instantiated(self): | ||
self._do_test(MatrixWorkspaceProperty) | ||
|
||
def test_IEventWorkspaceProperty_can_be_instantiated(self): | ||
self._do_test(IEventWorkspaceProperty) | ||
|
||
def test_ITableWorkspaceProperty_can_be_instantiated(self): | ||
self._do_test(ITableWorkspaceProperty) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |