Skip to content
Snippets Groups Projects
Commit da0b1fec authored by Gagik Vardanyan's avatar Gagik Vardanyan
Browse files

Re #16676 added functionality to set instrument and

data search directories from test, that are restored to initial settings after test
parent 9b8aa627
No related merge requests found
......@@ -8,16 +8,38 @@
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidKernel/ConfigService.h"
#include <boost/algorithm/string/predicate.hpp> //for ends_with
using namespace Mantid::API;
using namespace Mantid::DataObjects;
using namespace Mantid::DataHandling;
using namespace Mantid::Kernel;
class LoadTest : public CxxTest::TestSuite {
private:
std::vector<std::string> m_dataSearchDirs;
std::string m_instName;
public:
void tearDown() override { AnalysisDataService::Instance().clear(); }
void setUp() override {
m_dataSearchDirs = ConfigService::Instance().getDataSearchDirs();
m_instName = ConfigService::Instance().getString("default.instrument");
}
void tearDown() override {
ConfigService::Instance().setDataSearchDirs(m_dataSearchDirs);
ConfigService::Instance().setString("default.instrument",m_instName);
AnalysisDataService::Instance().clear();
}
void testViaProxy() {
IAlgorithm_sptr proxy = AlgorithmManager::Instance().create("Load");
......@@ -238,10 +260,13 @@ public:
* without instrument prefix in the file names.
*/
void test_ILLLoadMultipleFilesNoPrefix() {
ConfigService::Instance().setString("default.instrument","IN4");
ConfigService::Instance().appendDataSearchSubDir("ILL/IN4/");
Load loader;
loader.initialize();
loader.setPropertyValue("Filename", "ILL/IN4/IN4084446+084447.nxs");
// Note that here IN4 prefix is absent from the actual file name.
loader.setPropertyValue("Filename", "084446+084447.nxs");
std::string outputWS = "LoadTest_out";
loader.setPropertyValue("OutputWorkspace", outputWS);
......@@ -254,7 +279,6 @@ public:
TS_ASSERT_EQUALS(output2D->getNumberHistograms(), 397);
AnalysisDataService::Instance().clear();
}
void test_EventPreNeXus_WithNoExecute() {
......
......@@ -201,6 +201,8 @@ public:
void setDataSearchDirs(const std::string &searchDirs);
/// Adds the passed path to the end of the list of data search paths
void appendDataSearchDir(const std::string &path);
/// Appends subdirectory to each of the specified data search directories
void appendDataSearchSubDir(const std::string &subdir);
/// Get the list of user search paths
const std::vector<std::string> &getUserSearchDirs() const;
/// Get instrument search directory
......
......@@ -1581,6 +1581,39 @@ void ConfigServiceImpl::setDataSearchDirs(const std::string &searchDirs) {
setString("datasearch.directories", searchDirs);
}
/**
* Appends the passed subdirectory path to the end of each of data
* search dirs and adds these new dirs to data search directories
* @param subdir :: the subdirectory path to add (relative)
*/
void ConfigServiceImpl::appendDataSearchSubDir(const std::string &subdir) {
if (subdir.empty())
return;
Poco::Path subDirPath;
try {
subDirPath = Poco::Path(subdir);
} catch (Poco::PathSyntaxException &) {
return;
}
std::vector<std::string> newDataDirs = m_DataSearchDirs;
std::vector<std::string>::const_iterator it = newDataDirs.begin();
std::vector<std::string>::const_iterator end = newDataDirs.end();
for (; it != end; ++it) {
Poco::Path newDirPath;
try {
newDirPath = Poco::Path(*it);
newDirPath.append(subDirPath);
newDataDirs.push_back(newDirPath.toString());
} catch (Poco::PathSyntaxException &) {
continue;
}
}
setDataSearchDirs(newDataDirs);
}
/**
* Adds the passed path to the end of the list of data search paths
* the path name must be absolute
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment