Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mantidproject
mantid
Commits
b783175f
Commit
b783175f
authored
14 years ago
by
Doucet, Mathieu
Browse files
Options
Downloads
Patches
Plain Diff
Added test for new python alg functionality. Re #2270
parent
3a881c35
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Mantid/Framework/PythonAPI/CMakeLists.txt
+1
-0
1 addition, 0 deletions
Code/Mantid/Framework/PythonAPI/CMakeLists.txt
Code/Mantid/Framework/PythonAPI/test/PythonAlgorithmTest.py
+69
-0
69 additions, 0 deletions
Code/Mantid/Framework/PythonAPI/test/PythonAlgorithmTest.py
with
70 additions
and
0 deletions
Code/Mantid/Framework/PythonAPI/CMakeLists.txt
+
1
−
0
View file @
b783175f
...
...
@@ -21,6 +21,7 @@ set ( TEST_FILES test/PythonFrameworkTests.h
test/SimplePythonAPITest.h
)
set
(
TEST_PY_FILES test/ImportTest.py
test/PythonAlgorithmTest.py
test/NumpyTest.py
)
# Add local dependencies
...
...
This diff is collapsed.
Click to expand it.
Code/Mantid/Framework/PythonAPI/test/PythonAlgorithmTest.py
0 → 100644
+
69
−
0
View file @
b783175f
import
unittest
from
MantidFramework
import
mtd
from
MantidFramework
import
PythonAlgorithm
mtd
.
initialise
()
from
mantidsimple
import
*
class
DummyAlg
(
PythonAlgorithm
):
"""
Dummy algorithm that uses executeSubAlg()
"""
def
category
(
self
):
return
"
SANS
"
def
name
(
self
):
return
"
DummyAlg
"
def
PyInit
(
self
):
self
.
declareWorkspaceProperty
(
"
OutputWorkspace
"
,
""
,
Direction
=
Direction
.
Output
,
Description
=
''
)
def
PyExec
(
self
):
output_ws
=
self
.
getPropertyValue
(
"
OutputWorkspace
"
)
a
=
self
.
executeSubAlg
(
CreateWorkspace
,
output_ws
,
[
0
,
1
,
2
],
[
0
,
1
,
2
],
[
0
,
0
,
0
])
self
.
_setWorkspaceProperty
(
"
OutputWorkspace
"
,
a
.
_getWorkspaceProperty
(
"
OutputWorkspace
"
))
mtd
.
registerPyAlgorithm
(
DummyAlg
())
class
PythonAlgorithmTest
(
unittest
.
TestCase
):
"""
Tests for python algorithms
"""
def
setUp
(
self
):
pass
def
test_sub_alg_wksp_transfer
(
self
):
"""
Check that we can execute a sub-algorithm and pass
ownership of an output workspace to the parent algo.
"""
algm
=
mantid
.
createAlgorithm
(
"
DummyAlg
"
)
algm
.
setPropertyValue
(
"
OutputWorkspace
"
,
"
subalgtest
"
)
algm
.
setRethrows
(
True
)
algm
.
execute
()
self
.
assertTrue
(
mtd
.
workspaceExists
(
"
subalgtest
"
))
mtd
.
deleteWorkspace
(
"
subalgtest
"
)
def
test_sub_alg_variation
(
self
):
"""
Call signature variation for sub-algorithm execution
"""
class
DummyAlg2
(
DummyAlg
):
def
name
(
self
):
return
"
DummyAlg2
"
def
PyExec
(
self
):
output_ws
=
self
.
getPropertyValue
(
"
OutputWorkspace
"
)
a
=
self
.
executeSubAlg
(
CreateWorkspace
,
OutputWorkspace
=
output_ws
,
DataX
=
[
0
,
1
,
2
],
DataY
=
[
0
,
1
,
2
],
DataE
=
[
0
,
0
,
0
])
self
.
_setWorkspaceProperty
(
"
OutputWorkspace
"
,
a
.
_getWorkspaceProperty
(
"
OutputWorkspace
"
))
mtd
.
registerPyAlgorithm
(
DummyAlg2
())
algm
=
mantid
.
createAlgorithm
(
"
DummyAlg2
"
)
algm
.
setPropertyValue
(
"
OutputWorkspace
"
,
"
subalgtest2
"
)
algm
.
setRethrows
(
True
)
algm
.
execute
()
self
.
assertTrue
(
mtd
.
workspaceExists
(
"
subalgtest2
"
))
mtd
.
deleteWorkspace
(
"
subalgtest2
"
)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment