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
fb323e4e
Commit
fb323e4e
authored
10 years ago
by
Karl Palmen
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/feature/8336_better_unit_test_for_removelogs'
parents
385840d8
6d3f3309
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
Code/Mantid/Framework/DataHandling/test/RemoveLogsTest.h
+98
-173
98 additions, 173 deletions
Code/Mantid/Framework/DataHandling/test/RemoveLogsTest.h
with
98 additions
and
173 deletions
Code/Mantid/Framework/DataHandling/test/RemoveLogsTest.h
+
98
−
173
View file @
fb323e4e
...
@@ -15,8 +15,10 @@
...
@@ -15,8 +15,10 @@
#include
"MantidAPI/Algorithm.h"
#include
"MantidAPI/Algorithm.h"
#include
"MantidGeometry/Instrument/Component.h"
#include
"MantidGeometry/Instrument/Component.h"
#include
"MantidKernel/TimeSeriesProperty.h"
#include
"MantidKernel/TimeSeriesProperty.h"
#include
<vector>
#include
"MantidTestHelpers/WorkspaceCreationHelper.h"
#include
"MantidTestHelpers/WorkspaceCreationHelper.h"
#include
<vector>
using
namespace
Mantid
::
API
;
using
namespace
Mantid
::
API
;
using
namespace
Mantid
::
Kernel
;
using
namespace
Mantid
::
Kernel
;
using
namespace
Mantid
::
DataHandling
;
using
namespace
Mantid
::
DataHandling
;
...
@@ -24,214 +26,137 @@ using namespace Mantid::DataObjects;
...
@@ -24,214 +26,137 @@ using namespace Mantid::DataObjects;
class
RemoveLogsTest
:
public
CxxTest
::
TestSuite
class
RemoveLogsTest
:
public
CxxTest
::
TestSuite
{
{
public:
public:
static
RemoveLogsTest
*
createSuite
()
{
return
new
RemoveLogsTest
();
}
static
RemoveLogsTest
*
createSuite
()
{
return
new
RemoveLogsTest
();
}
static
void
destroySuite
(
RemoveLogsTest
*
suite
)
{
delete
suite
;
}
static
void
destroySuite
(
RemoveLogsTest
*
suite
)
{
delete
suite
;
}
RemoveLogsTest
()
RemoveLogsTest
()
{
//initialise framework manager to allow logging
//Mantid::API::FrameworkManager::Instance().initialize();
}
void
testInit
()
{
{
TS_ASSERT
(
!
remover
.
isInitialized
()
);
TS_ASSERT_THROWS_NOTHING
(
remover
.
initialize
());
TS_ASSERT
(
remover
.
isInitialized
()
);
}
}
void
testExecWithSingleLogFile
()
/**
* Creates a sample workspace in ADS.
*/
void
setUp
()
{
{
if
(
!
loader
.
isInitialized
()
)
loader
.
initialize
();
m_sampleWorkspace
=
"__remove_logs_test_ws"
;
createSampleWorkspace
();
// Path to test input file assumes Test directory checked out from SVN
}
TS_ASSERT_THROWS_NOTHING
(
loader
.
setPropertyValue
(
"Filename"
,
"HRP37129_ICPevent.txt"
)
)
inputFile
=
loader
.
getPropertyValue
(
"Filename"
);
outputSpace
=
"RemoveLogsTest-singleLogFile"
;
TS_ASSERT_THROWS
(
loader
.
setPropertyValue
(
"Workspace"
,
outputSpace
),
std
::
invalid_argument
)
// Create an empty workspace and put it in the AnalysisDataService
Workspace_sptr
ws
=
WorkspaceFactory
::
Instance
().
create
(
"Workspace2D"
,
1
,
1
,
1
);
TS_ASSERT_THROWS_NOTHING
(
AnalysisDataService
::
Instance
().
add
(
outputSpace
,
ws
));
std
::
string
result
;
TS_ASSERT_THROWS_NOTHING
(
result
=
loader
.
getPropertyValue
(
"Filename"
)
)
TS_ASSERT
(
!
result
.
compare
(
inputFile
));
TS_ASSERT_THROWS_NOTHING
(
result
=
loader
.
getPropertyValue
(
"Workspace"
)
)
TS_ASSERT
(
!
result
.
compare
(
outputSpace
));
TS_ASSERT_THROWS_NOTHING
(
loader
.
execute
());
/**
* Removes the sample workspace from ADS.
*/
void
tearDown
()
{
AnalysisDataService
::
Instance
().
remove
(
m_sampleWorkspace
);
}
TS_ASSERT
(
loader
.
isExecuted
()
);
/**
* Tests creation and initialisation of the algorithm.
*/
void
test_init
()
{
TS_ASSERT
(
!
m_remover
.
isInitialized
());
TS_ASSERT_THROWS_NOTHING
(
m_remover
.
initialize
());
TS_ASSERT
(
m_remover
.
isInitialized
());
}
// Get back the saved workspace
/**
* Tests removal of all logs from the workspace.
*/
void
test_removeAllLogs
()
{
// Get the sample workspace from ADS
MatrixWorkspace_sptr
output
;
MatrixWorkspace_sptr
output
;
TS_ASSERT_THROWS_NOTHING
(
output
=
AnalysisDataService
::
Instance
().
retrieveWS
<
MatrixWorkspace
>
(
outputSpace
));
TS_ASSERT_THROWS_NOTHING
(
output
=
AnalysisDataService
::
Instance
().
retrieveWS
<
MatrixWorkspace
>
(
m_sampleWorkspace
));
if
(
!
remover
.
isInitialized
()
)
remover
.
initialize
();
TS_ASSERT_THROWS_NOTHING
(
remover
.
setPropertyValue
(
"Workspace"
,
outputSpace
))
TS_ASSERT_THROWS_NOTHING
(
remover
.
execute
());
TS_ASSERT
(
remover
.
isExecuted
()
);
// Make sure it has log data
TS_ASSERT_DIFFERS
(
output
->
run
().
getLogData
().
size
(),
0
);
// log should have been removed
// Remove it's logs
TS_ASSERT_THROWS
(
output
->
run
().
getLogData
(
"HRP37129_ICPevent"
),
std
::
runtime_error
);
TS_ASSERT_THROWS_NOTHING
(
m_remover
.
initialize
());
TS_ASSERT_THROWS_NOTHING
(
m_remover
.
setPropertyValue
(
"Workspace"
,
m_sampleWorkspace
));
TS_ASSERT_THROWS_NOTHING
(
m_remover
.
execute
());
TS_ASSERT
(
m_remover
.
isExecuted
());
AnalysisDataService
::
Instance
().
remove
(
outputSpace
);
// Ensure it's no longer has any log data
TS_ASSERT_EQUALS
(
output
->
run
().
getLogData
().
size
(),
0
);
}
}
/**
void
do_test_SNSTextFile
(
std
::
string
names
,
std
::
string
units
,
bool
willFail
,
bool
createWorkspace
=
true
)
* Tests keeping certain logs in the workspace.
*/
void
test_keepLogs
()
{
{
// Create an empty workspace and put it in the AnalysisDataService
// Get the sample workspace from ADS
outputSpace
=
"test_SNSTextFile"
;
if
(
createWorkspace
)
{
Workspace_sptr
ws
=
WorkspaceFactory
::
Instance
().
create
(
"Workspace2D"
,
1
,
1
,
1
);
TS_ASSERT_THROWS_NOTHING
(
AnalysisDataService
::
Instance
().
addOrReplace
(
outputSpace
,
ws
));
}
// Set up the algo
LoadLog
alg
;
alg
.
initialize
();
TS_ASSERT
(
alg
.
isInitialized
()
);
TS_ASSERT_THROWS_NOTHING
(
alg
.
setPropertyValue
(
"Filename"
,
"VULCAN_furnace4208.txt"
)
);
TS_ASSERT_THROWS_NOTHING
(
alg
.
setPropertyValue
(
"Workspace"
,
outputSpace
)
);
TS_ASSERT_THROWS_NOTHING
(
alg
.
setPropertyValue
(
"Names"
,
names
)
);
TS_ASSERT_THROWS_NOTHING
(
alg
.
setPropertyValue
(
"Units"
,
units
)
);
TS_ASSERT_THROWS_NOTHING
(
alg
.
execute
()
);
if
(
willFail
)
{
TS_ASSERT
(
!
alg
.
isExecuted
()
);
return
;
}
else
{
TS_ASSERT
(
alg
.
isExecuted
()
);}
// Get back the saved workspace
MatrixWorkspace_sptr
output
;
MatrixWorkspace_sptr
output
;
TS_ASSERT_THROWS_NOTHING
(
output
=
AnalysisDataService
::
Instance
().
retrieveWS
<
MatrixWorkspace
>
(
outputS
pace
));
TS_ASSERT_THROWS_NOTHING
(
output
=
AnalysisDataService
::
Instance
().
retrieveWS
<
MatrixWorkspace
>
(
m_sampleWorks
pace
));
if
(
!
remover
.
isInitialized
()
)
remover
.
initialize
();
// Make sure it has log data
TS_ASSERT_THROWS_NOTHING
(
remover
.
setPropertyValue
(
"Workspace"
,
outputSpace
))
TS_ASSERT_DIFFERS
(
output
->
run
().
getLogData
().
size
(),
0
);
TS_ASSERT_THROWS_NOTHING
(
remover
.
execute
());
// Remove it's logs
TS_ASSERT_THROWS_NOTHING
(
m_remover
.
initialize
());
TS_ASSERT_THROWS_NOTHING
(
m_remover
.
setPropertyValue
(
"Workspace"
,
m_sampleWorkspace
));
TS_ASSERT_THROWS_NOTHING
(
m_remover
.
setPropertyValue
(
"KeepLogs"
,
"Ei, scan_index"
));
TS_ASSERT_THROWS_NOTHING
(
m_remover
.
execute
());
TS_ASSERT
(
m_remover
.
isExecuted
());
TS_ASSERT
(
remover
.
isExecuted
()
);
// Ensure it has the correct log data
TS_ASSERT_DIFFERS
(
output
->
run
().
getLogData
().
size
(),
0
);
// logs should have been removed
TS_ASSERT_THROWS
(
output
->
run
().
getLogData
(
"some_prop"
),
std
::
runtime_error
);
TS_ASSERT_THROWS
(
output
->
run
().
getLogData
(
"Yadda"
),
std
::
runtime_error
);
TS_ASSERT_THROWS
(
output
->
run
().
getLogData
(
"T0"
),
std
::
runtime_error
);
TS_ASSERT_THROWS
(
output
->
run
().
getLogData
(
"Temp1"
),
std
::
runtime_error
);
TS_ASSERT_THROWS
(
output
->
run
().
getLogData
(
"Temp2"
),
std
::
runtime_error
);
TS_ASSERT_THROWS
(
output
->
run
().
getLogData
(
"Temp3"
),
std
::
runtime_error
);
TS_ASSERT_THROWS
(
output
->
run
().
getLogData
(
"Extra"
),
std
::
runtime_error
);
TS_ASSERT_THROWS_NOTHING
(
output
->
run
().
getLogData
(
"Ei"
));
TS_ASSERT_THROWS_NOTHING
(
output
->
run
().
getLogData
(
"scan_index"
));
}
}
void
test_SNSTextFile_noNames_fails
()
private
:
{
do_test_SNSTextFile
(
""
,
""
,
true
);
}
void
test_SNSTextFile_tooFewNames_fails
()
{
do_test_SNSTextFile
(
"Yadda,Yadda"
,
""
,
true
);
}
void
test_SNSTextFile_tooManyNames_fails
()
/**
* Creates a sample workspace with various types of log entries
*/
void
createSampleWorkspace
()
{
{
do_test_SNSTextFile
(
"Yadda,Yadda,Yadda,Yadda,Yadda,Yadda"
,
""
,
true
);
// Create the workspace
}
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
Create2DWorkspace
(
10
,
100
);
// Add some log entries to it
std
::
vector
<
DateAndTime
>
times
;
std
::
vector
<
int
>
index
;
std
::
vector
<
double
>
dbl1
,
dbl2
;
DateAndTime
startTime
(
"2010-01-01T00:00:00"
);
for
(
int
i
=
0
;
i
<
100
;
++
i
)
{
times
.
push_back
(
startTime
+
i
*
10.0
);
index
.
push_back
(
i
);
dbl1
.
push_back
(
i
*
0.1
);
dbl2
.
push_back
(
6.0
);
}
void
test_SNSTextFile
()
auto
scan_index
=
new
TimeSeriesProperty
<
int
>
(
"scan_index"
);
{
scan_index
->
addValues
(
times
,
index
);
do_test_SNSTextFile
(
"Temp1,Temp2,Temp3,Extra"
,
"C,K,F,Furlongs"
,
false
);
ws
->
mutableRun
().
addProperty
(
scan_index
);
}
void
test_SNSTextFile_noUnits
()
auto
dbl_prop1
=
new
TimeSeriesProperty
<
double
>
(
"some_prop"
);
{
auto
dbl_prop2
=
new
TimeSeriesProperty
<
double
>
(
"some_other_prop"
);
d
o_test_SNSTextFile
(
"Temp1,Temp2,Temp3,Extra"
,
""
,
false
);
d
bl_prop1
->
addValues
(
times
,
dbl1
);
}
dbl_prop2
->
addValues
(
times
,
dbl2
);
void
test_SNSTextFile_wrongNumberOfUnits_fails
()
ws
->
mutableRun
().
addProperty
(
dbl_prop1
);
{
ws
->
mutableRun
().
addProperty
(
dbl_prop2
);
do_test_SNSTextFile
(
"Temp1,Temp2,Temp3,Extra"
,
"Dynes,Ergs"
,
true
);
}
void
test_SNSTextFile_twice_overwrites_logs
()
ws
->
mutableRun
().
addProperty
(
"Ei"
,
42.
);
{
ws
->
mutableRun
().
addProperty
(
"T0"
,
42.
);
do_test_SNSTextFile
(
"Temp1,Temp2,Temp3,Extra"
,
"C,K,F,Furlongs"
,
false
,
true
);
// Dont re-create the workspace the 2nd time around.
// Switch a unit around to make sure the new one got overwritten
do_test_SNSTextFile
(
"Temp1,Temp2,Temp3,Yadda"
,
"C,K,F,Fortnights"
,
false
,
false
);
}
void
test_KeepLogs
()
// Store it in ADS
{
TS_ASSERT_THROWS_NOTHING
(
AnalysisDataService
::
Instance
().
add
(
m_sampleWorkspace
,
ws
));
// Create an empty workspace and put it in the AnalysisDataService
EventWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
CreateEventWorkspace
(
1000
,
1
,
10000
);
outputSpace
=
"PartiallyRemoveLogs"
;
// Add a bunch of logs
std
::
vector
<
DateAndTime
>
times
;
std
::
vector
<
int
>
index
;
std
::
vector
<
double
>
dbl1
,
dbl2
;
DateAndTime
startTime
(
"2010-01-01T00:00:00"
);
for
(
int
i
=
0
;
i
<
100
;
++
i
)
{
times
.
push_back
(
startTime
+
i
*
10.0
);
index
.
push_back
(
i
);
dbl1
.
push_back
(
i
*
0.1
);
dbl2
.
push_back
(
6.0
);
}
auto
scan_index
=
new
TimeSeriesProperty
<
int
>
(
"scan_index"
);
scan_index
->
addValues
(
times
,
index
);
ws
->
mutableRun
().
addProperty
(
scan_index
);
auto
dbl_prop1
=
new
TimeSeriesProperty
<
double
>
(
"some_prop"
);
auto
dbl_prop2
=
new
TimeSeriesProperty
<
double
>
(
"some_other_prop"
);
dbl_prop1
->
addValues
(
times
,
dbl1
);
dbl_prop2
->
addValues
(
times
,
dbl2
);
ws
->
mutableRun
().
addProperty
(
dbl_prop1
);
ws
->
mutableRun
().
addProperty
(
dbl_prop2
);
ws
->
mutableRun
().
addProperty
(
"Ei"
,
42.
);
ws
->
mutableRun
().
addProperty
(
"T0"
,
42.
);
TS_ASSERT_THROWS_NOTHING
(
AnalysisDataService
::
Instance
().
add
(
outputSpace
,
ws
));
// Get back the saved workspace
MatrixWorkspace_sptr
output
;
TS_ASSERT_THROWS_NOTHING
(
output
=
AnalysisDataService
::
Instance
().
retrieveWS
<
MatrixWorkspace
>
(
outputSpace
));
if
(
!
remover
.
isInitialized
()
)
remover
.
initialize
();
TS_ASSERT_THROWS_NOTHING
(
remover
.
setPropertyValue
(
"Workspace"
,
outputSpace
));
TS_ASSERT_THROWS_NOTHING
(
remover
.
setPropertyValue
(
"KeepLogs"
,
"Ei, scan_index"
));
TS_ASSERT_THROWS_NOTHING
(
remover
.
execute
());
TS_ASSERT
(
remover
.
isExecuted
()
);
// log should have been removed
TS_ASSERT_THROWS
(
output
->
run
().
getLogData
(
"some_other_prop"
),
std
::
runtime_error
);
TS_ASSERT_THROWS
(
output
->
run
().
getLogData
(
"some_prop"
),
std
::
runtime_error
);
TS_ASSERT_THROWS
(
output
->
run
().
getLogData
(
"T0"
),
std
::
runtime_error
);
TS_ASSERT_THROWS_NOTHING
(
output
->
run
().
getLogData
(
"Ei"
));
TS_ASSERT_THROWS_NOTHING
(
output
->
run
().
getLogData
(
"scan_index"
));
AnalysisDataService
::
Instance
().
remove
(
outputSpace
);
}
}
private
:
RemoveLogs
m_remover
;
LoadLog
loader
;
std
::
string
m_sampleWorkspace
;
RemoveLogs
remover
;
std
::
string
inputFile
;
std
::
string
outputSpace
;
std
::
string
inputSpace
;
};
};
...
...
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