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
3225dee0
Commit
3225dee0
authored
8 years ago
by
David Fairbrother
Browse files
Options
Downloads
Patches
Plain Diff
Re #19113 Added test for extract_ws_spectra
parent
70d36f92
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/test/ISISPowderCommonTest.py
+33
-6
33 additions, 6 deletions
scripts/test/ISISPowderCommonTest.py
with
33 additions
and
6 deletions
scripts/test/ISISPowderCommonTest.py
+
33
−
6
View file @
3225dee0
...
...
@@ -16,17 +16,16 @@ class ISISPowderCommonTest(unittest.TestCase):
def
test_cal_map_dict_helper
(
self
):
missing_key_name
=
"
wrong_key
"
correct_key_name
=
"
right_key
"
dict_without_key
=
{
correct_key_name
:
None
}
dict_with_key
=
{
correct_key_name
:
123
}
# Check it correctly raises
with
self
.
assertRaisesRegexp
(
KeyError
,
"
The field
'"
+
missing_key_name
+
"'
is required
"
):
common
.
cal_map_dictionary_key_helper
(
dictionary
=
dict_with
out
_key
,
key
=
missing_key_name
)
common
.
cal_map_dictionary_key_helper
(
dictionary
=
dict_with_key
,
key
=
missing_key_name
)
# Check it correctly appends the passed error message when raising
appended_e_msg
=
"
test append message
"
with
self
.
assertRaisesRegexp
(
KeyError
,
appended_e_msg
):
common
.
cal_map_dictionary_key_helper
(
dictionary
=
dict_with
out
_key
,
key
=
missing_key_name
,
common
.
cal_map_dictionary_key_helper
(
dictionary
=
dict_with_key
,
key
=
missing_key_name
,
append_to_error_message
=
appended_e_msg
)
# Check that it correctly returns the key value where it exists
...
...
@@ -42,7 +41,7 @@ class ISISPowderCommonTest(unittest.TestCase):
for
i
in
range
(
0
,
3
):
out_name
=
"
crop_banks_in_tof-
"
+
str
(
i
)
cropping_value_list
.
append
(
cropping_value
)
bank_list
.
append
(
mantid
.
CreateSampleWorkspace
(
OutputWorkspace
=
out_name
,
XMin
=
0
,
XMax
=
200
00
,
BinWidth
=
1
))
bank_list
.
append
(
mantid
.
CreateSampleWorkspace
(
OutputWorkspace
=
out_name
,
XMin
=
0
,
XMax
=
11
00
,
BinWidth
=
1
))
# Check a list of WS and single cropping value is detected
with
self
.
assertRaisesRegexp
(
ValueError
,
"
The cropping values were not in a list type
"
):
...
...
@@ -75,7 +74,7 @@ class ISISPowderCommonTest(unittest.TestCase):
for
i
in
range
(
0
,
3
):
out_name
=
"
crop_banks_in_tof-
"
+
str
(
i
)
ws_list
.
append
(
mantid
.
CreateSampleWorkspace
(
OutputWorkspace
=
out_name
,
XMin
=
0
,
XMax
=
200
00
,
BinWidth
=
1
))
ws_list
.
append
(
mantid
.
CreateSampleWorkspace
(
OutputWorkspace
=
out_name
,
XMin
=
0
,
XMax
=
6
00
,
BinWidth
=
1
))
# Crop a single workspace in TOF
tof_single_ws
=
common
.
crop_in_tof
(
ws_to_crop
=
ws_list
[
0
],
x_min
=
x_min
,
x_max
=
x_max
)
...
...
@@ -92,7 +91,7 @@ class ISISPowderCommonTest(unittest.TestCase):
# Checks that crop_in_tof converts to TOF before cropping
ws_list
=
[]
x_min
=
100
x_max
=
500
# Crop to 0-500 microseconds for unit tests
x_max
=
200
expected_number_of_bins
=
20000
# Hard code number of expected bins for dSpacing
for
i
in
range
(
0
,
3
):
...
...
@@ -111,5 +110,33 @@ class ISISPowderCommonTest(unittest.TestCase):
self
.
assertEqual
(
ws
.
getNumberBins
(),
expected_number_of_bins
)
mantid
.
DeleteWorkspace
(
ws
)
def
test_dictionary_key_helper
(
self
):
good_key_name
=
"
key_exists
"
bad_key_name
=
"
key_does_not_exist
"
test_dictionary
=
{
good_key_name
:
123
}
e_msg
=
"
test message
"
with
self
.
assertRaises
(
KeyError
):
common
.
dictionary_key_helper
(
dictionary
=
test_dictionary
,
key
=
bad_key_name
)
with
self
.
assertRaisesRegexp
(
KeyError
,
e_msg
):
common
.
dictionary_key_helper
(
dictionary
=
test_dictionary
,
key
=
bad_key_name
,
exception_msg
=
e_msg
)
self
.
assertEqual
(
common
.
dictionary_key_helper
(
dictionary
=
test_dictionary
,
key
=
good_key_name
),
123
)
def
test_extract_ws_spectra
(
self
):
number_of_expected_banks
=
5
ws_to_split
=
mantid
.
CreateSampleWorkspace
(
XMin
=
0
,
XMax
=
1
,
BankPixelWidth
=
1
,
NumBanks
=
number_of_expected_banks
)
input_name
=
ws_to_split
.
getName
()
extracted_banks
=
common
.
extract_ws_spectra
(
ws_to_split
=
ws_to_split
)
self
.
assertEqual
(
len
(
extracted_banks
),
number_of_expected_banks
)
for
i
,
ws
in
enumerate
(
extracted_banks
):
expected_name
=
input_name
+
'
-
'
+
str
(
i
+
1
)
self
.
assertEqual
(
expected_name
,
ws
.
getName
())
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