From aa380566020f3a15822a0909f2aeaf86edeba93e Mon Sep 17 00:00:00 2001 From: Samuel Jackson Date: Mon, 9 Jun 2014 11:44:40 +0100 Subject: [PATCH] Refs #9584 Add fix broken usage examples. --- .../algorithms/GeneratePythonScript-v1.rst | 41 ++++++++++++------ .../source/algorithms/SaveFocusedXYE-v1.rst | 9 ++-- .../docs/source/algorithms/SaveGSS-v1.rst | 12 +++--- .../algorithms/SaveNexusProcessed-v1.rst | 42 +++++++++++++++++-- .../algorithms/SortPeaksWorkspace-v1.rst | 10 ++--- 5 files changed, 82 insertions(+), 32 deletions(-) diff --git a/Code/Mantid/docs/source/algorithms/GeneratePythonScript-v1.rst b/Code/Mantid/docs/source/algorithms/GeneratePythonScript-v1.rst index f8ed16b0a617..639c66ccf6b2 100644 --- a/Code/Mantid/docs/source/algorithms/GeneratePythonScript-v1.rst +++ b/Code/Mantid/docs/source/algorithms/GeneratePythonScript-v1.rst @@ -26,7 +26,7 @@ Usage ws = RenameWorkspace(ws, OutputWorkspace="MyTestWorkspace") script_text = GeneratePythonScript(ws) - print script_text + print script_text.strip() Output: @@ -40,10 +40,23 @@ Output: Power(InputWorkspace='ws',OutputWorkspace='ws',Exponent='1.5') RenameWorkspace(InputWorkspace='ws',OutputWorkspace='MyTestWorkspace') +.. testcleanup:: ExGeneratePythonScriptSimple + + import os + def removeFiles(files): + for ws in files: + try: + path = os.path.join(config['defaultsave.directory'], ws) + os.remove(path) + except: + pass + + removeFiles(['myscript.py']) + **Example - generate a python script and save it to file:** -.. testcode:: ExGeneratePythonScriptSimple +.. testcode:: ExGeneratePythonScriptFile #create a workspace and run some operations on it ws = CreateSampleWorkspace() @@ -54,18 +67,11 @@ Output: GeneratePythonScript(ws, Filename='myscript.py') with open ('myscript.py', 'r') as script: - print script.read() - -.. testcleanup:: ExGeneratePythonScriptSimple - import os - try: - os.remove('myscript.py') - except: - pass + print script.read().strip() Output: -.. testoutput:: ExGeneratePythonScriptSimple +.. testoutput:: ExGeneratePythonScriptFile ###################################################################### #Python Script Generated by GeneratePythonScript Algorithm @@ -75,6 +81,17 @@ Output: Power(InputWorkspace='ws',OutputWorkspace='ws',Exponent='1.5') RenameWorkspace(InputWorkspace='ws',OutputWorkspace='MyTestWorkspace') - +.. testcleanup:: ExGeneratePythonScriptFile + + import os + def removeFiles(files): + for ws in files: + try: + path = os.path.join(config['defaultsave.directory'], ws) + os.remove(path) + except: + pass + + removeFiles(['myscript.py']) .. categories:: diff --git a/Code/Mantid/docs/source/algorithms/SaveFocusedXYE-v1.rst b/Code/Mantid/docs/source/algorithms/SaveFocusedXYE-v1.rst index ecc16986cab2..298a31043379 100644 --- a/Code/Mantid/docs/source/algorithms/SaveFocusedXYE-v1.rst +++ b/Code/Mantid/docs/source/algorithms/SaveFocusedXYE-v1.rst @@ -39,13 +39,12 @@ Usage ws = CreateSampleWorkspace() ws = ExtractSingleSpectrum(ws, 0) - file_name = "myworkspace" + file_name = "myworkspace.ascii" SaveFocusedXYE(ws, file_name) - path = os.path.join(config['defaultsave.directory'], file_name + "-0.ascii") + path = os.path.join(config['defaultsave.directory'], "myworkspace-0.ascii") print os.path.isfile(path) - Output: .. testoutput:: ExSaveFocusedXYESimple @@ -63,7 +62,7 @@ Output: except: pass - removeFiles(file_name + "-0.ascii") + removeFiles(["myworkspace-0.ascii"]) **Example - an example using SaveFocusedXYE with additional options.** @@ -98,6 +97,6 @@ Output: except: pass - removeFiles(file_name) + removeFiles([file_name]) .. categories:: diff --git a/Code/Mantid/docs/source/algorithms/SaveGSS-v1.rst b/Code/Mantid/docs/source/algorithms/SaveGSS-v1.rst index b534373f2bdc..b848263c4594 100644 --- a/Code/Mantid/docs/source/algorithms/SaveGSS-v1.rst +++ b/Code/Mantid/docs/source/algorithms/SaveGSS-v1.rst @@ -41,7 +41,7 @@ Usage ----- **Example - a basic example using SaveGSS.** -.. testcode:: ExSaveGSSimple +.. testcode:: ExSaveGSSSimple import os @@ -50,17 +50,17 @@ Usage file_name = "myworkspace.ascii" SaveGSS(ws, file_name) - path = os.path.join(config['defaultsave.directory'], file_name) + path = os.path.join(config['defaultsave.directory'], "myworkspace-0.ascii") print os.path.isfile(path) Output: -.. testoutput:: ExSaveGSSimple +.. testoutput:: ExSaveGSSSimple True -.. testcleanup:: ExSaveGSSimple +.. testcleanup:: ExSaveGSSSimple import os def removeFiles(files): @@ -71,7 +71,7 @@ Output: except: pass - removeFiles(file_name) + removeFiles(["myworkspace-0.ascii"]) **Example - an example using SaveGSS with additonal options.** @@ -105,7 +105,7 @@ Output: except: pass - removeFiles(file_name) + removeFiles([file_name]) .. categories:: diff --git a/Code/Mantid/docs/source/algorithms/SaveNexusProcessed-v1.rst b/Code/Mantid/docs/source/algorithms/SaveNexusProcessed-v1.rst index fc8786d4ab0c..ed9026e18b4b 100644 --- a/Code/Mantid/docs/source/algorithms/SaveNexusProcessed-v1.rst +++ b/Code/Mantid/docs/source/algorithms/SaveNexusProcessed-v1.rst @@ -77,7 +77,7 @@ Output: except: pass - removeFiles(file_name) + removeFiles([file_name]) **Example - an example using SaveNexusProcessed with additonal options.** @@ -95,7 +95,7 @@ Output: ws = Load(file_name) print "Saved workspace has %d spectra" % ws.getNumberHistograms() - + Output: .. testoutput:: ExSaveNexusProcessedOptions @@ -114,7 +114,43 @@ Output: except: pass - removeFiles(file_name) + removeFiles([file_name]) + +**Example - an example using SaveNexusProcessed to save an Event workspace.** + +.. testcode:: ExSaveNexusProcessedEvent + + import os + + ws = CreateSampleWorkspace("Event") + file_name = "myworkspace.nxs" + SaveNexusProcessed(ws, file_name, CompressNexus=True, PreserveEvents=True) + + path = os.path.join(config['defaultsave.directory'], file_name) + print os.path.isfile(path) + + ws = Load(file_name) + print "Saved workspace has %d spectra" % ws.getNumberHistograms() + +Output: + +.. testoutput:: ExSaveNexusProcessedEvent + + True + Saved workspace has 200 spectra + +.. testcleanup:: ExSaveNexusProcessedEvent + + import os + def removeFiles(files): + for ws in files: + try: + path = os.path.join(config['defaultsave.directory'], ws) + os.remove(path) + except: + pass + + removeFiles([file_name]) .. categories:: diff --git a/Code/Mantid/docs/source/algorithms/SortPeaksWorkspace-v1.rst b/Code/Mantid/docs/source/algorithms/SortPeaksWorkspace-v1.rst index 9b35880517fc..e478af802c2e 100644 --- a/Code/Mantid/docs/source/algorithms/SortPeaksWorkspace-v1.rst +++ b/Code/Mantid/docs/source/algorithms/SortPeaksWorkspace-v1.rst @@ -26,19 +26,17 @@ Usage #sort the table by column k peaks_ws = SortPeaksWorkspace(peaks_ws, ColumnNameToSortBy='k') - print "Column k in ascending order: \n" + str(peaks_ws.column('k')) + print "Column k in ascending order: " + str(peaks_ws.column('k')) #the algorithm can also sort in descending order peaks_ws = SortPeaksWorkspace(peaks_ws, ColumnNameToSortBy='k', SortAscending=False) - print "Column k in descending order: \n" + str(peaks_ws.column('k')) + print "Column k in descending order: " + str(peaks_ws.column('k')) Output: .. testoutput:: ExSortPeaksWorkspaceSimple - Column k in ascending order: - [-3.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -0.0, -0.0, -0.0, 0.0, -0.0, -0.0, 0.0, -0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 5.0, 5.0] - Column k in descending order: - [5.0, 5.0, 4.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -0.0, -0.0, -0.0, 0.0, -0.0, -0.0, 0.0, -0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -3.0] + Column k in ascending order: [-3.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -0.0, -0.0, -0.0, 0.0, -0.0, -0.0, 0.0, -0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 5.0, 5.0] + Column k in descending order: [5.0, 5.0, 4.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -0.0, -0.0, -0.0, 0.0, -0.0, -0.0, 0.0, -0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -3.0] .. categories::