Skip to content

Commit

Permalink
Fix failing SaveParameterFiles documentation test.
Browse files Browse the repository at this point in the history
This commit fixes two issues.

  1. The output file was not being written in a cross-platform friendly
     way. We now use `os.path.expanduser` to select a writable file path
     on any platform.

  2. The usage example test was failing. This was caused by the faulty
     assumption that the output of SaveParameterFile is deterministic.
     The data it outputs is, but the actual ordering of elements in the
     XML isn't, so checking the raw contents of the XML file was an
     unreliable testing method. Instead we now rely on the unit test for
     SaveParameterFile and provide an example of the output to the user
     (and the pre-existing link to the parameter file wiki page).

Refs #10023
  • Loading branch information
Harry Jeffery committed Jul 31, 2014
1 parent a36c795 commit 37ba90f
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions Code/Mantid/docs/source/algorithms/SaveParameterFile-v1.rst
Expand Up @@ -21,37 +21,31 @@ used to adjust the location of any components. Specifically, it will skip "x", "
Usage
-----

**Example - save an instrument's parameters to a file:**
.. testcode::

.. testcode:: ExParametersSimple
import os

ws = Load(Filename = "MAR11001.raw")
SaveParameterFile(Workspace = ws, Filename = "/tmp/params.xml", LocationParameters = False)

pfile = open("/tmp/params.xml", "r")
lines = pfile.readlines()
pfile.close()
#Create a path in the user's home directory
filename = os.path.expanduser("~/params.xml")

for line in lines[0:6]:
print(line.strip())

print("etc...")
#Load a workspace
ws = Load(Filename = "MAR11001.raw")

.. testcleanup:: ExParametersSimple
#Save the workspace's instrument's parameters to the given file.
SaveParameterFile(Workspace = ws, Filename = filename, LocationParameters = False)

import os
os.remove("/tmp/params.xml")
.. testcleanup::

Output:
os.remove(filename)

.. testoutput:: ExParametersSimple
Example Output::

<?xml version="1.0" encoding="UTF-8"?>
<parameter-file instrument="MARI" valid-from="1900-01-31T23:59:59">
<component-link name="MARI">
<parameter name="DelayTime">
<value val="-3.9"/>
</parameter>
etc...
<?xml version="1.0" encoding="UTF-8"?>
<parameter-file instrument="InstrumentName" valid-from="1900-01-31T23:59:59">
<component-link name="ComponentName">
<parameter name="ParameterName">
<value val="2.17"/>
</parameter>
</component-link>
</parameter-file>

.. categories::

0 comments on commit 37ba90f

Please sign in to comment.