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
f58659f4
Commit
f58659f4
authored
9 years ago
by
Anton Piccardo-Selg
Browse files
Options
Downloads
Patches
Plain Diff
Refs #13458 unit test for nexus saving with x errors
parent
34cade82
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Framework/DataHandling/test/SaveNexusProcessedTest.h
+75
-46
75 additions, 46 deletions
Framework/DataHandling/test/SaveNexusProcessedTest.h
with
75 additions
and
46 deletions
Framework/DataHandling/test/SaveNexusProcessedTest.h
+
75
−
46
View file @
f58659f4
...
@@ -62,59 +62,32 @@ public:
...
@@ -62,59 +62,32 @@ public:
}
}
void
testExec
()
{
void
testExec
()
{
auto
useXErrors
=
false
;
std
::
string
outputFile
=
"SaveNexusProcessedTest_testExec.nxs"
;
outputFile
=
doExec
(
outputFile
,
useXErrors
);
SaveNexusProcessed
algToBeTested
;
// Clean up
if
(
!
algToBeTested
.
isInitialized
())
if
(
clearfiles
)
algToBeTested
.
initialize
();
// Should fail because mandatory parameter has not been set
TS_ASSERT_THROWS
(
algToBeTested
.
execute
(),
std
::
runtime_error
);
// create dummy 2D-workspace
Workspace2D_sptr
localWorkspace2D
=
boost
::
dynamic_pointer_cast
<
Workspace2D
>
(
WorkspaceFactory
::
Instance
().
create
(
"Workspace2D"
,
1
,
10
,
10
));
localWorkspace2D
->
getAxis
(
0
)
->
unit
()
=
UnitFactory
::
Instance
().
create
(
"TOF"
);
double
d
=
0.0
;
for
(
int
i
=
0
;
i
<
10
;
++
i
,
d
+=
0.1
)
{
localWorkspace2D
->
dataX
(
0
)[
i
]
=
d
;
localWorkspace2D
->
dataY
(
0
)[
i
]
=
d
;
localWorkspace2D
->
dataE
(
0
)[
i
]
=
d
;
}
AnalysisDataService
::
Instance
().
addOrReplace
(
"testSpace"
,
localWorkspace2D
);
// Now set it...
// specify name of file to save workspace to
algToBeTested
.
setPropertyValue
(
"InputWorkspace"
,
"testSpace"
);
outputFile
=
"SaveNexusProcessedTest_testExec.nxs"
;
// entryName = "test";
dataName
=
"spectra"
;
title
=
"A simple workspace saved in Processed Nexus format"
;
TS_ASSERT_THROWS_NOTHING
(
algToBeTested
.
setPropertyValue
(
"Filename"
,
outputFile
));
outputFile
=
algToBeTested
.
getPropertyValue
(
"Filename"
);
// algToBeTested.setPropertyValue("EntryName", entryName);
algToBeTested
.
setPropertyValue
(
"Title"
,
title
);
if
(
Poco
::
File
(
outputFile
).
exists
())
Poco
::
File
(
outputFile
).
remove
();
Poco
::
File
(
outputFile
).
remove
();
AnalysisDataService
::
Instance
().
remove
(
"testSpace"
);
}
std
::
string
result
;
void
testExecWithXErrors
()
{
TS_ASSERT_THROWS_NOTHING
(
result
=
auto
useXErrors
=
true
;
algToBeTested
.
getPropertyValue
(
"Filename"
));
std
::
string
outputFile
=
"SaveNexusProcessedTest_testExec.nxs"
;
TS_ASSERT
(
!
result
.
compare
(
outputFile
));
outputFile
=
doExec
(
outputFile
,
useXErrors
);
// TS_ASSERT_THROWS_NOTHING( result =
// algToBeTested.getPropertyValue("EntryName") )
// TS_ASSERT( ! result.compare(entryName));
// changed so that 1D workspaces are no longer written.
// Assert XError correctness
TS_ASSERT_THROWS_NOTHING
(
algToBeTested
.
execute
());
NeXus
::
File
savedNexus
(
outputFile
);
TS_ASSERT
(
algToBeTested
.
isExecuted
());
savedNexus
.
openGroup
(
"mantid_workspace_1"
,
"NXentry"
);
savedNexus
.
openGroup
(
"workspace"
,
"NXdata"
);
TSM_ASSERT_THROWS_NOTHING
(
"Should find xerrors entry"
,
savedNexus
.
openData
(
"xerrors"
));
savedNexus
.
close
();
// Clean up
if
(
clearfiles
)
if
(
clearfiles
)
Poco
::
File
(
outputFile
).
remove
();
Poco
::
File
(
outputFile
).
remove
();
AnalysisDataService
::
Instance
().
remove
(
"testSpace"
);
AnalysisDataService
::
Instance
().
remove
(
"testSpace"
);
}
}
...
@@ -818,6 +791,62 @@ private:
...
@@ -818,6 +791,62 @@ private:
};
};
}
}
std
::
string
doExec
(
std
::
string
outputFile
=
"SaveNexusProcessedTest_testExec.nxs"
,
bool
useXErrors
=
false
)
{
SaveNexusProcessed
algToBeTested
;
if
(
!
algToBeTested
.
isInitialized
())
algToBeTested
.
initialize
();
// Should fail because mandatory parameter has not been set
TS_ASSERT_THROWS
(
algToBeTested
.
execute
(),
std
::
runtime_error
);
// create dummy 2D-workspace
Workspace2D_sptr
localWorkspace2D
=
boost
::
dynamic_pointer_cast
<
Workspace2D
>
(
WorkspaceFactory
::
Instance
().
create
(
"Workspace2D"
,
1
,
10
,
10
));
localWorkspace2D
->
getAxis
(
0
)
->
unit
()
=
UnitFactory
::
Instance
().
create
(
"TOF"
);
double
d
=
0.0
;
for
(
int
i
=
0
;
i
<
10
;
++
i
,
d
+=
0.1
)
{
localWorkspace2D
->
dataX
(
0
)[
i
]
=
d
;
localWorkspace2D
->
dataY
(
0
)[
i
]
=
d
;
localWorkspace2D
->
dataE
(
0
)[
i
]
=
d
;
if
(
useXErrors
)
{
localWorkspace2D
->
dataDx
(
0
)[
i
]
=
d
;
}
}
AnalysisDataService
::
Instance
().
addOrReplace
(
"testSpace"
,
localWorkspace2D
);
// Now set it...
// specify name of file to save workspace to
algToBeTested
.
setPropertyValue
(
"InputWorkspace"
,
"testSpace"
);
// entryName = "test";
dataName
=
"spectra"
;
title
=
"A simple workspace saved in Processed Nexus format"
;
TS_ASSERT_THROWS_NOTHING
(
algToBeTested
.
setPropertyValue
(
"Filename"
,
outputFile
));
outputFile
=
algToBeTested
.
getPropertyValue
(
"Filename"
);
// algToBeTested.setPropertyValue("EntryName", entryName);
algToBeTested
.
setPropertyValue
(
"Title"
,
title
);
if
(
Poco
::
File
(
outputFile
).
exists
())
Poco
::
File
(
outputFile
).
remove
();
std
::
string
result
;
TS_ASSERT_THROWS_NOTHING
(
result
=
algToBeTested
.
getPropertyValue
(
"Filename"
));
TS_ASSERT
(
!
result
.
compare
(
outputFile
));
// TS_ASSERT_THROWS_NOTHING( result =
// algToBeTested.getPropertyValue("EntryName") )
// TS_ASSERT( ! result.compare(entryName));
// changed so that 1D workspaces are no longer written.
TS_ASSERT_THROWS_NOTHING
(
algToBeTested
.
execute
());
TS_ASSERT
(
algToBeTested
.
isExecuted
());
return
outputFile
;
}
std
::
string
outputFile
;
std
::
string
outputFile
;
std
::
string
entryName
;
std
::
string
entryName
;
std
::
string
dataName
;
std
::
string
dataName
;
...
...
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