Skip to content

Commit

Permalink
Refs #8315 - Simplify ADS cleanup after each test.
Browse files Browse the repository at this point in the history
Replaced multiple calls to ADS.remove() with a single tearDown fixture.
  • Loading branch information
PeterParker committed Dec 19, 2013
1 parent 923f3e4 commit 999b42a
Showing 1 changed file with 4 additions and 50 deletions.
54 changes: 4 additions & 50 deletions Code/Mantid/Framework/DataHandling/test/LoadTest.h
Expand Up @@ -13,23 +13,13 @@ using namespace Mantid::API;
using namespace Mantid::DataObjects;
using namespace Mantid::DataHandling;

namespace
{
void removeGroupFromADS(WorkspaceGroup_sptr group)
{
const std::vector<std::string> wsNames = group->getNames();
std::vector<std::string>::const_iterator it = wsNames.begin();
AnalysisDataService::Instance().remove(group->name());
for(; it != wsNames.end(); ++it)
{
AnalysisDataService::Instance().remove(*it);
}
}
}

class LoadTest : public CxxTest::TestSuite
{
public:
void tearDown()
{
AnalysisDataService::Instance().clear();
}

void testViaProxy()
{
Expand Down Expand Up @@ -129,7 +119,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(loader.execute());
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("LoadTest_Output");
TS_ASSERT(ws);
AnalysisDataService::Instance().remove("LoadTest_Output");
}

void testRawWithOneSpectrum()
Expand All @@ -152,7 +141,6 @@ class LoadTest : public CxxTest::TestSuite

// Check it only has 1 spectrum
TS_ASSERT_EQUALS( ws->getNumberHistograms(), 1 );
AnalysisDataService::Instance().remove(outputName);
}

void testRaw1()
Expand All @@ -164,7 +152,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(loader.execute());
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("LoadTest_Output");
TS_ASSERT(ws);
AnalysisDataService::Instance().remove("LoadTest_Output");
}

void testRawGroup()
Expand All @@ -178,9 +165,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT(wsg);
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("LoadTest_Output_1");
TS_ASSERT(ws);
AnalysisDataService::Instance().remove("LoadTest_Output");
AnalysisDataService::Instance().remove("LoadTest_Output_1");
AnalysisDataService::Instance().remove("LoadTest_Output_2");

}

Expand All @@ -193,7 +177,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(loader.execute());
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("LoadTest_Output");
TS_ASSERT(ws);
AnalysisDataService::Instance().remove("LoadTest_Output");
}

void _ARGUS_NXS()
Expand All @@ -217,9 +200,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT(wsg);
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("LoadTest_Output_1");
TS_ASSERT(ws);
AnalysisDataService::Instance().remove("LoadTest_Output");
AnalysisDataService::Instance().remove("LoadTest_Output_1");
AnalysisDataService::Instance().remove("LoadTest_Output_2");
}
void testISISNexus()
{
Expand All @@ -230,7 +210,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(loader.execute());
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("LoadTest_Output");
TS_ASSERT(ws);
AnalysisDataService::Instance().remove("LoadTest_Output");
}

void testUnknownExt()
Expand All @@ -249,7 +228,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(loader.execute());
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("LoadTest_Output");
TS_ASSERT(ws);
AnalysisDataService::Instance().remove("LoadTest_Output");
}

void testAscii()
Expand All @@ -261,7 +239,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(loader.execute());
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("LoadTest_Output");
TS_ASSERT(ws);
AnalysisDataService::Instance().remove("LoadTest_Output");
}

void testSpice2D()
Expand All @@ -273,7 +250,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(loader.execute());
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("LoadTest_Output");
TS_ASSERT(ws);
AnalysisDataService::Instance().remove("LoadTest_Output");
}
void testSNSSpec()
{
Expand All @@ -284,7 +260,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(loader.execute());
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("LoadTest_Output");
TS_ASSERT(ws);
AnalysisDataService::Instance().remove("LoadTest_Output");
}

void testGSS()
Expand All @@ -311,7 +286,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(loader.execute());
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("LoadTest_Output");
TS_ASSERT(ws);
AnalysisDataService::Instance().remove("LoadTest_Output");
}

void test_EventPreNeXus_WithNoExecute()
Expand Down Expand Up @@ -341,7 +315,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(loader.execute());
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("LoadTest_Output");
TS_ASSERT(ws);
AnalysisDataService::Instance().remove("LoadTest_Output");
}

void testArgusFileLoadingWithIncorrectZeroPadding()
Expand All @@ -353,7 +326,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(loader.execute());
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("LoadTest_Output");
TS_ASSERT(ws);
AnalysisDataService::Instance().remove("LoadTest_Output");
}

void testMDWorkspace()
Expand All @@ -365,7 +337,6 @@ class LoadTest : public CxxTest::TestSuite
loader.setPropertyValue("OutputWorkspace",outputWS);
TS_ASSERT( loader.execute() );
TS_ASSERT_THROWS_NOTHING( AnalysisDataService::Instance().retrieveWS<IMDWorkspace>(outputWS) );
AnalysisDataService::Instance().remove(outputWS);
}

void testList()
Expand Down Expand Up @@ -396,8 +367,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT(!AnalysisDataService::Instance().doesExist("MUSR00015189"));
TS_ASSERT(!AnalysisDataService::Instance().doesExist("MUSR00015190"));
TS_ASSERT(!AnalysisDataService::Instance().doesExist("MUSR00015191"));

removeGroupFromADS(output);
}

void testPlus()
Expand All @@ -410,7 +379,6 @@ class LoadTest : public CxxTest::TestSuite

MatrixWorkspace_sptr output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("LoadTest_Output");
TS_ASSERT(output);
AnalysisDataService::Instance().remove("LoadTest_Output");
}

void testPlusGroupWorkspaces()
Expand All @@ -426,7 +394,6 @@ class LoadTest : public CxxTest::TestSuite
MatrixWorkspace_sptr ws1 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("MUSR00015189_MUSR00015190_1");
TS_ASSERT(ws1);
MatrixWorkspace_sptr ws2 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("MUSR00015189_MUSR00015190_2");
removeGroupFromADS(output);
}

void testRange()
Expand Down Expand Up @@ -455,7 +422,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT(ws7);
MatrixWorkspace_sptr ws8 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("MUSR00015192_2");
TS_ASSERT(ws8);
removeGroupFromADS(output);
}

void testSteppedRange()
Expand All @@ -476,7 +442,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT(ws3);
MatrixWorkspace_sptr ws4 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("MUSR00015191_2");
TS_ASSERT(ws4);
removeGroupFromADS(output);
}

void testAddedRange()
Expand All @@ -499,8 +464,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT(ws2);
TS_ASSERT_DELTA(ws2->readY(0)[5], 2.0, 1e-12);
TS_ASSERT_DELTA(ws2->readY(8)[0], 6.0, 1e-12);

removeGroupFromADS(output);
}

void testAddedSteppedRange()
Expand All @@ -518,7 +481,6 @@ class LoadTest : public CxxTest::TestSuite
TS_ASSERT(ws1);
MatrixWorkspace_sptr ws2 = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("MUSR00015189_MUSR00015191_2");
TS_ASSERT(ws2);
removeGroupFromADS(output);
}

void testMultiFilesExtraProperties()
Expand All @@ -544,8 +506,6 @@ class LoadTest : public CxxTest::TestSuite

// Make sure that it contains the requested number of spectra as per SpectrumMin and SpectrumMax
TS_ASSERT_EQUALS(childWs->getNumberHistograms(), 91);

removeGroupFromADS(wsg);
}

void testCommaSeparatedListOfDifferentIntruments()
Expand All @@ -559,8 +519,6 @@ class LoadTest : public CxxTest::TestSuite
WorkspaceGroup_sptr wsg = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>("LoadTest_Output");
TS_ASSERT(wsg);
TS_ASSERT_EQUALS(wsg->getNames().size(), 3);

AnalysisDataService::Instance().remove("LoadTest_Output");
}

void test_outputWsNameSameAsOneOfTheSinglePeriodFileNames()
Expand All @@ -571,13 +529,9 @@ class LoadTest : public CxxTest::TestSuite
loader.setPropertyValue("OutputWorkspace","LOQ48127");
TS_ASSERT_THROWS_NOTHING(loader.execute());

std::set<std::string> adsContents = AnalysisDataService::Instance().getObjectNames();

WorkspaceGroup_sptr wsg = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>("LOQ48127");
TS_ASSERT(wsg);
TS_ASSERT_EQUALS(wsg->getNames().size(), 3);

AnalysisDataService::Instance().remove("LOQ48127");
}
};

Expand Down

0 comments on commit 999b42a

Please sign in to comment.