Skip to content
Snippets Groups Projects
Commit 3000bdef authored by Elliot Oram's avatar Elliot Oram
Browse files

Use optional output workspace name

Refs #23388
parent 01216696
No related branches found
No related tags found
No related merge requests found
...@@ -593,7 +593,7 @@ void LoadAscii2::fillInputValues(std::vector<double> &values, ...@@ -593,7 +593,7 @@ void LoadAscii2::fillInputValues(std::vector<double> &values,
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/// Initialisation method. /// Initialisation method.
void LoadAscii2::init() { void LoadAscii2::init() {
const std::vector<std::string> exts{".dat", ".txt", ".csv"}; const std::vector<std::string> exts{".dat", ".txt", ".csv", ""};
declareProperty(Kernel::make_unique<FileProperty>("Filename", "", declareProperty(Kernel::make_unique<FileProperty>("Filename", "",
FileProperty::Load, exts), FileProperty::Load, exts),
"The name of the text file to read, including its full or " "The name of the text file to read, including its full or "
......
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
from mantid.api import FileProperty, WorkspaceProperty, PythonAlgorithm, AlgorithmFactory, FileAction from mantid.api import (FileProperty, WorkspaceProperty, PythonAlgorithm,
AlgorithmFactory, FileAction, PropertyMode)
from mantid.kernel import Direction from mantid.kernel import Direction
from mantid.simpleapi import LoadAscii, CreateWorkspace from mantid.simpleapi import LoadAscii, CreateWorkspace
...@@ -25,15 +26,16 @@ class LoadGudrunOutput(PythonAlgorithm): ...@@ -25,15 +26,16 @@ class LoadGudrunOutput(PythonAlgorithm):
".mdor01", ".mdor01",
".mgor01"]), ".mgor01"]),
doc="Gudrun output file to be loaded.") doc="Gudrun output file to be loaded.")
self.declareProperty(WorkspaceProperty(name='OutputWorkspace', defaultValue='None', self.declareProperty(WorkspaceProperty(name='OutputWorkspace', defaultValue='',
direction=Direction.Output), direction=Direction.Output,
optional=PropertyMode.Optional),
doc="If OutputWorkpsace is None," doc="If OutputWorkpsace is None,"
" then the workpsace name will be obtained from the input file.") " then the workpsace name will be obtained from the input file.")
def PyExec(self): def PyExec(self):
input_file = self.getProperty('InputFile').value input_file = self.getProperty('InputFile').value
output_ws = self.getPropertyValue('OutputWorkspace') output_ws = self.getPropertyValue('OutputWorkspace')
if output_ws == 'None': if not output_ws:
output_ws = self.get_title(input_file) output_ws = self.get_title(input_file)
number_of_columns, data_line_start = self.find_number_of_columns(input_file) number_of_columns, data_line_start = self.find_number_of_columns(input_file)
self.load_gudrun_file(input_file, output_ws, number_of_columns, data_line_start) self.load_gudrun_file(input_file, output_ws, number_of_columns, data_line_start)
......
...@@ -66,9 +66,13 @@ class LoadGudrunOutputTest(unittest.TestCase): ...@@ -66,9 +66,13 @@ class LoadGudrunOutputTest(unittest.TestCase):
self.assertRaises(ValueError, LoadGudrunOutput, tmp.name, 'out_ws') self.assertRaises(ValueError, LoadGudrunOutput, tmp.name, 'out_ws')
def test_rename_with_default_output(self): def test_rename_with_default_output(self):
actual = LoadGudrunOutput(InputFile=self.file_name.format('.dcs'), OutputWorkspace='None') actual = LoadGudrunOutput(InputFile=self.file_name.format('.dcs'), OutputWorkspace='')
self.assertEqual(actual.name(), 'POLARIS00097947-dcs01') self.assertEqual(actual.name(), 'POLARIS00097947-dcs01')
def test_name_when_given(self):
actual = LoadGudrunOutput(InputFile=self.file_name.format('.dcs'), OutputWorkspace='actual')
self.assertEqual(actual.name(), 'actual')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -171,7 +171,7 @@ QString formatExtension(const std::string &extension) { ...@@ -171,7 +171,7 @@ QString formatExtension(const std::string &extension) {
formattedExtension.insert(1, "."); formattedExtension.insert(1, ".");
} else if (extension.at(0) == '.') { } else if (extension.at(0) == '.') {
formattedExtension.prepend("*"); formattedExtension.prepend("*");
} else { } else {
formattedExtension.prepend("*."); formattedExtension.prepend("*.");
} }
} }
......
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