Skip to content

Commit

Permalink
Merge remote branch 'origin/feature/8107_hide_listeners_in_startlived…
Browse files Browse the repository at this point in the history
…ata'
  • Loading branch information
Michael Reuter committed Oct 11, 2013
2 parents d427920 + ec1f504 commit c55108b
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 28 deletions.
4 changes: 3 additions & 1 deletion Code/Mantid/Framework/LiveData/src/LiveDataAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ namespace LiveData
instruments.push_back( it->name() );
}
}
// TEMPORARY: Add all the listeners by hand while this is all under development
#ifndef NDEBUG
// Debug builds only: Add all the listeners by hand for development testing purposes
std::vector<std::string> listeners = Mantid::API::LiveListenerFactory::Instance().getKeys();
instruments.insert( instruments.end(), listeners.begin(), listeners.end() );
#endif
declareProperty(new PropertyWithValue<std::string>("Instrument","", boost::make_shared<StringListValidator>(instruments)),
"Name of the instrument to monitor.");

Expand Down
9 changes: 6 additions & 3 deletions Code/Mantid/Framework/LiveData/test/LiveDataAlgorithmTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <iomanip>
#include "MantidLiveData/LiveDataAlgorithm.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include "MantidTestHelpers/FacilityHelper.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/FrameworkManager.h"
Expand All @@ -25,8 +26,8 @@ class LiveDataAlgorithmImpl : public LiveDataAlgorithm
// Make all the members public so I can test them.
friend class LiveDataAlgorithmTest;
public:
virtual const std::string name() const { return "LiveDataAlgorithmImpl";};
virtual int version() const { return 1;};
virtual const std::string name() const { return "LiveDataAlgorithmImpl";}
virtual int version() const { return 1;}
virtual const std::string category() const { return "Testing";}
void init()
{ this->initProps(); }
Expand Down Expand Up @@ -66,6 +67,8 @@ class LiveDataAlgorithmTest : public CxxTest::TestSuite

void test_validateInputs()
{
FacilityHelper::ScopedFacilities loadTESTFacility("IDFs_for_UNIT_TESTING/UnitTestFacilities.xml", "TEST");

LiveDataAlgorithmImpl alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
Expand All @@ -87,7 +90,7 @@ class LiveDataAlgorithmTest : public CxxTest::TestSuite
alg.setPropertyValue("AccumulationWorkspace", "out_ws");
TSM_ASSERT("AccumulationWorkspace == OutputWorkspace", !alg.validateInputs()["AccumulationWorkspace"].empty() );

alg.setPropertyValue("Instrument", "ISISHistoDataListener");
alg.setPropertyValue("Instrument", "TESTHISTOLISTENER");
alg.setPropertyValue("AccumulationMethod","Add");
TSM_ASSERT("Shouldn't add histograms", !alg.validateInputs()["AccumulationMethod"].empty() );
}
Expand Down
41 changes: 19 additions & 22 deletions Code/Mantid/Framework/LiveData/test/LoadLiveDataTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@
#include "MantidDataObjects/Workspace2D.h"
#include "MantidKernel/ConfigService.h"
#include "MantidAPI/LiveListenerFactory.h"
#include "MantidTestHelpers/FacilityHelper.h"

using namespace Mantid;
using namespace Mantid::LiveData;
using namespace Mantid::DataObjects;
using namespace Mantid::API;
using namespace Mantid::Kernel;

class LoadLiveDataImpl : public LoadLiveData
{
public:
// void store() { Algorithm::store(); }
};

class LoadLiveDataTest : public CxxTest::TestSuite
{
public:
Expand Down Expand Up @@ -64,27 +59,29 @@ class LoadLiveDataTest : public CxxTest::TestSuite
bool makeThrow = false
)
{
std::auto_ptr<LoadLiveDataImpl> alg(new LoadLiveDataImpl);
TS_ASSERT_THROWS_NOTHING( alg->initialize() )
TS_ASSERT( alg->isInitialized() )
TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("Instrument", "TestDataListener") );
TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("AccumulationMethod", AccumulationMethod) );
TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("ProcessingAlgorithm", ProcessingAlgorithm) );
TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("ProcessingProperties", ProcessingProperties) );
TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("PostProcessingAlgorithm", PostProcessingAlgorithm) );
TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("PostProcessingProperties", PostProcessingProperties) );
TS_ASSERT_THROWS_NOTHING( alg->setProperty("PreserveEvents", PreserveEvents) );
FacilityHelper::ScopedFacilities loadTESTFacility("IDFs_for_UNIT_TESTING/UnitTestFacilities.xml", "TEST");

LoadLiveData alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Instrument", "TestDataListener") );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("AccumulationMethod", AccumulationMethod) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("ProcessingAlgorithm", ProcessingAlgorithm) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("ProcessingProperties", ProcessingProperties) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("PostProcessingAlgorithm", PostProcessingAlgorithm) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("PostProcessingProperties", PostProcessingProperties) );
TS_ASSERT_THROWS_NOTHING( alg.setProperty("PreserveEvents", PreserveEvents) );
if (!PostProcessingAlgorithm.empty())
TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("AccumulationWorkspace", "fake_accum") );
TS_ASSERT_THROWS_NOTHING( alg->setPropertyValue("OutputWorkspace", "fake") );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("AccumulationWorkspace", "fake_accum") );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", "fake") );
if (listener)
alg->setLiveListener(listener);
alg.setLiveListener(listener);

if (!makeThrow)
{ TS_ASSERT_THROWS_NOTHING( alg->execute(); ); }
{ TS_ASSERT_THROWS_NOTHING( alg.execute(); ); }
else
alg->exec();
TS_ASSERT( alg->isExecuted() );
alg.exec();
TS_ASSERT( alg.isExecuted() );

// Retrieve the workspace from data service.
boost::shared_ptr<TYPE> ws;
Expand Down
7 changes: 7 additions & 0 deletions Code/Mantid/Framework/LiveData/test/MonitorLiveDataTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidKernel/ConfigService.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidTestHelpers/FacilityHelper.h"

using namespace Mantid;
using namespace Mantid::LiveData;
Expand All @@ -22,12 +23,18 @@ using namespace Mantid::Kernel;

class MonitorLiveDataTest : public CxxTest::TestSuite
{
private:
FacilityHelper::ScopedFacilities loadTESTFacility;

public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static MonitorLiveDataTest *createSuite() { return new MonitorLiveDataTest(); }
static void destroySuite( MonitorLiveDataTest *suite ) { delete suite; }

MonitorLiveDataTest() : loadTESTFacility("IDFs_for_UNIT_TESTING/UnitTestFacilities.xml", "TEST")
{}

void setUp()
{
// Register algorithms
Expand Down
6 changes: 6 additions & 0 deletions Code/Mantid/Framework/LiveData/test/StartLiveDataTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include "MantidTestHelpers/FacilityHelper.h"

using namespace Mantid;
using namespace Mantid::LiveData;
Expand All @@ -21,12 +22,17 @@ using namespace Mantid::Kernel;

class StartLiveDataTest : public CxxTest::TestSuite
{
private:
FacilityHelper::ScopedFacilities loadTESTFacility;

public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static StartLiveDataTest *createSuite() { return new StartLiveDataTest(); }
static void destroySuite( StartLiveDataTest *suite ) { delete suite; }

StartLiveDataTest() : loadTESTFacility("IDFs_for_UNIT_TESTING/UnitTestFacilities.xml", "TEST")
{}

void test_Init()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ void export_ConfigService()
(arg("facilityName")), return_value_policy<reference_existing_object>(),
"Returns the named facility. Raises an RuntimeError if it does not exist")

.def("setFacility", &ConfigServiceImpl::setString, (arg("facilityName")), "Sets the current facility to the given name")
.def("setFacility", &ConfigServiceImpl::setFacility, "Sets the current facility to the given name")

.def("updateFacilities", &ConfigServiceImpl::updateFacilities, "Loads facility information from a provided file")

.def("getInstrument", &ConfigServiceImpl::getInstrument,
getInstrument_Overload("Returns the named instrument. If name = \"\" then the default.instrument is returned",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def test_getFacilities_and_Facility_Names_are_in_sync_and_non_empty(self):
for i in range(len(names)):
self.assertEquals(names[i],facilities[i].name())

def test_update_and_set_facility(self):
self.assertFalse("TEST" in config.getFacilityNames())
ConfigService.updateFacilities(os.path.join(ConfigService.getInstrumentDirectory(),"IDFs_for_UNIT_TESTING/UnitTestFacilities.xml"))
ConfigService.setFacility("TEST")
self.assertEquals(config.getFacility().name(), "TEST")
self.assertRaises(RuntimeError, config.getFacility, "SNS")

def test_getInstrumentReturns_A_InstrumentInfo_Object(self):
self.assertTrue(isinstance(config.getInstrument("WISH"), InstrumentInfo))
self.assertRaises(RuntimeError, config.getInstrument, "MadeUpInstrument")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class LoadLiveDataTest(unittest.TestCase):

def setUp(self):
FrameworkManager.clearData()
ConfigService.updateFacilities(os.path.join(ConfigService.getInstrumentDirectory(),"IDFs_for_UNIT_TESTING/UnitTestFacilities.xml"))
ConfigService.setFacility("TEST")
pass


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
<livedata listener="ISISHistoDataListener" address="127.0.0.1:6789" />
</instrument>

<instrument name="TestDataListener">
<technique>Test Listener</technique>
<livedata listener="TestDataListener" address="127.0.0.1:0" />
</instrument>

<instrument name="FakeEventDataListener">
<technique>Test Listener</technique>
<livedata listener="FakeEventDataListener" address="127.0.0.1:0" />
</instrument>

</facility>

</facilities>
</facilities>

0 comments on commit c55108b

Please sign in to comment.