Skip to content

Commit

Permalink
Fix unit tests. Refs #11824
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiSavici committed May 27, 2015
1 parent 4d60207 commit 06eaa4f
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 32 deletions.
Expand Up @@ -107,7 +107,7 @@ def PyExec(self):
peak_range[2*i] = x_min
peak_range[2*i+1] = x_max
elif len(peak_range) < 2:
raise RuntimeError, "SignalPeakPixelRange should have a length of at least 2."
raise RuntimeError("SignalPeakPixelRange should have a length of at least 2.")

if len(background_range)==2:
x_min = int(background_range[0])
Expand All @@ -117,12 +117,12 @@ def PyExec(self):
background_range[2*i] = x_min
background_range[2*i+1] = x_max
elif len(background_range) < 2:
raise RuntimeError, "SignalBackgroundPixelRange should have a length of at least 2."
raise RuntimeError("SignalBackgroundPixelRange should have a length of at least 2.")

# Check that the peak range arrays are of the proper length
if not (len(peak_range) == 2*len(data_runs) \
and len(background_range) == 2*len(data_runs)):
raise RuntimeError, "Supplied peak/background arrays should be of the same length as the run array."
raise RuntimeError("Supplied peak/background arrays should be of the same length as the run array.")

# Slit information for the previous run (see loop below)
previous_slits = None
Expand Down Expand Up @@ -166,7 +166,7 @@ def PyExec(self):
if wavelength is None:
wavelength = wl
elif abs(wl-wavelength) > 0.2:
raise RuntimeError, "Supplied runs don't have matching wavelengths."
raise RuntimeError("Supplied runs don't have matching wavelengths.")

peak = [int(peak_range[2*i]), int(peak_range[2*i+1])]
background = [int(background_range[2*i]), int(background_range[2*i+1])]
Expand All @@ -179,7 +179,7 @@ def PyExec(self):
# attenuator.
if have_attenuator_info is True:
if attenuators[i] < n_attenuator:
raise RuntimeError, "Runs were not supplied in increasing number of attenuators."
raise RuntimeError("Runs were not supplied in increasing number of attenuators.")
n_attenuator = attenuators[i]

is_reference = False
Expand All @@ -203,7 +203,7 @@ def PyExec(self):
# If the number of attenuators is zero, skip.
if n_attenuator == 0:
if references.has_key(0):
raise RuntimeError, "More than one run with zero attenuator was supplied."
raise RuntimeError("More than one run with zero attenuator was supplied.")
references[0] = {'index': i,
'run': run,
'ref_ws': workspace_name,
Expand Down Expand Up @@ -235,7 +235,7 @@ def PyExec(self):
# Divide by the reference for this number of attenuators
# and multiply by the reference ratio
if not references.has_key(n_attenuator):
raise RuntimeError, "No reference for %s attenuators: check run ordering." % n_attenuator
raise RuntimeError("No reference for %s attenuators: check run ordering." % n_attenuator)
f_ws = "F_%s_%s" % (run, n_attenuator)
Divide(LHSWorkspace=workspace_name,
RHSWorkspace=references[n_attenuator]['ref_ws'],
Expand Down
Expand Up @@ -291,7 +291,7 @@ def PyExec(self):

# Sanity check
if sum(data_y) == 0:
raise RuntimeError, "The reflectivity is all zeros: check your peak selection"
raise RuntimeError("The reflectivity is all zeros: check your peak selection")

# Avoid leaving trash behind
for ws in ['ws_event_data', 'normalized_data', 'q_workspace']:
Expand Down Expand Up @@ -342,7 +342,7 @@ def process_data(self, workspace, tof_range, crop_low_res, low_res_range,
error_msg = "Requested TOF range does not match data for %s: " % str(workspace)
error_msg += "[%g, %g] found [%g, %g]" % (tof_range[0], tof_range[1],
tof_min, tof_max)
raise RuntimeError, error_msg
raise RuntimeError(error_msg)

tof_step = self.getProperty("TOFSteps").value
workspace = Rebin(InputWorkspace=workspace, Params=[0, tof_step, tof_max],
Expand Down
Expand Up @@ -55,10 +55,9 @@ def getGeneralLogValue(self,ws,name,begin):
v=v.unfiltered()
for tt in v.times:
times2.append((datetime.datetime(*(time.strptime(str(tt),"%Y-%m-%dT%H:%M:%S")[0:6]))-begin).total_seconds())
except AttributeError:
except:
#print "probably not a time series"
pass

if name[0:8]=="Beamlog_" and (name.find("Counts")>0 or name.find("Frames")>0):
i=bisect.bisect_right(times2,2) # allowance for "slow" clearing of DAE
#print "returning max beam log, list cut 0:",i,":",len(times2)
Expand Down
Expand Up @@ -116,7 +116,7 @@ def __init__(self, filenames):
# Validate.
if not isinstance(filenames, list):
raise TypeError("Expected a list.")
if not all([s._is_string for s in filenames]):
if not all([self._is_string(s) for s in filenames]):
raise TypeError("Expected a list of strings.")
if len(filenames) < 1:
raise ValueError("Expected at least one filename.")
Expand Down
Expand Up @@ -154,7 +154,7 @@ def _with_frame_skipping(self, source_aperture_radius):
if workspace.getRun().hasProperty("wavelength_max"):
wl_max_f1 = workspace.getRun().getProperty("wavelength_max").value
if wl_min_f1 is None and wl_max_f1 is None:
raise RuntimeError, "Could not get the wavelength band for frame 1"
raise RuntimeError("Could not get the wavelength band for frame 1")

# Second frame
wl_min_f2 = None
Expand All @@ -164,7 +164,7 @@ def _with_frame_skipping(self, source_aperture_radius):
if workspace.getRun().hasProperty("wavelength_max_frame2"):
wl_max_f2 = workspace.getRun().getProperty("wavelength_max_frame2").value
if wl_min_f2 is None and wl_max_f2 is None:
raise RuntimeError, "Could not get the wavelength band for frame 2"
raise RuntimeError("Could not get the wavelength band for frame 2")

# Compute binning
if independent_binning:
Expand Down Expand Up @@ -369,7 +369,7 @@ def _get_binning(self, workspace, wavelength_min, wavelength_max):
beam_ctr_x = property_manager.getProperty("LatestBeamCenterX").value
beam_ctr_y = property_manager.getProperty("LatestBeamCenterY").value
else:
raise RuntimeError, "No beam center information can be found on the data set"
raise RuntimeError("No beam center information can be found on the data set")

# Q min is one pixel from the center, unless we have the beam trap size
if workspace.getRun().hasProperty("beam-trap-diameter"):
Expand Down
Expand Up @@ -164,12 +164,12 @@ def _crop_and_compute(wl_min_prop, wl_max_prop, suffix):
if workspace.getRun().hasProperty(wl_min_prop):
wl_min = workspace.getRun().getProperty(wl_min_prop).value
else:
raise RuntimeError, "DirectBeamTransmission could not retrieve the %s property" % wl_min_prop
raise RuntimeError("DirectBeamTransmission could not retrieve the %s property" % wl_min_prop)

if workspace.getRun().hasProperty(wl_max_prop):
wl_max = workspace.getRun().getProperty(wl_max_prop).value
else:
raise RuntimeError, "DirectBeamTransmission could not retrieve the %s property" % wl_max_prop
raise RuntimeError("DirectBeamTransmission could not retrieve the %s property" % wl_max_prop)

rebin_params = "%4.1f,%4.1f,%4.1f" % (wl_min, 0.1, wl_max)
alg = TransmissionUtils.simple_algorithm("Rebin",\
Expand Down
Expand Up @@ -31,7 +31,7 @@ def _multiple_load(self, data_file, workspace,
# Make sure we process a list of files written as a string
def _load_data(filename, output_ws):
if not property_manager.existsProperty("LoadAlgorithm"):
raise RuntimeError, "SANS reduction not set up properly: missing load algorithm"
raise RuntimeError("SANS reduction not set up properly: missing load algorithm")
p=property_manager.getProperty("LoadAlgorithm")
alg=Algorithm.fromString(p.valueAsStr)
alg.setProperty("Filename", filename)
Expand Down
Expand Up @@ -18,9 +18,9 @@
17.09e4: tuple([10.4, 11.6]),\
18.86e4: tuple([11.0, 12.5])}\

""" A "wrapper" class for a map, which maps workspaces from their corresponding
time regimes.
"""
# A "wrapper" class for a map, which maps workspaces from their corresponding
#time regimes.

class DRangeToWsMap(object):

def __init__(self):
Expand Down
Expand Up @@ -72,7 +72,7 @@ def PyExec(self):
for i in range(len(input_ws.readX(0))):
input_ws.dataDx(0)[i] = math.sqrt(res_factor+math.pow((input_ws.readX(0)[i]*d_wvl), 2)/6.0)
else:
raise RuntimeError, "ReactorSANSResolution could not find all the run parameters needed to compute the resolution."
raise RuntimeError("ReactorSANSResolution could not find all the run parameters needed to compute the resolution.")


AlgorithmFactory.subscribe(ReactorSANSResolution)
Expand Up @@ -86,7 +86,7 @@ def PyExec(self):
self.setProperty("OutputMessage", msg)
return

#pylint: disable=too-many-locals
#pylint: disable=too-many-locals,too-many-branches
def _hfir_scaling(self, property_manager):
property_manager_name = self.getProperty("ReductionProperties").value
input_ws = self.getProperty("InputWorkspace").value
Expand All @@ -103,7 +103,7 @@ def _hfir_scaling(self, property_manager):
def _load_data(filename, output_ws):
if not property_manager.existsProperty("LoadAlgorithm"):
Logger("SANSDirectBeamTransmission").error("SANS reduction not set up properly: missing load algorithm")
raise RuntimeError, "SANS reduction not set up properly: missing load algorithm"
raise RuntimeError("SANS reduction not set up properly: missing load algorithm")
p=property_manager.getProperty("LoadAlgorithm")
alg=Algorithm.fromString(p.valueAsStr)
alg.setChild(True)
Expand Down Expand Up @@ -145,7 +145,7 @@ def _load_data(filename, output_ws):
beam_diameter = ref_ws.getRun().getProperty("beam-diameter").value
Logger("SANSAbsoluteScale").debug("Found beamstop diameter: %g" % beam_diameter)
else:
raise RuntimeError, "AbsoluteScale could not read the beam radius and none was provided"
raise RuntimeError("AbsoluteScale could not read the beam radius and none was provided")

# Apply sensitivity correction
apply_sensitivity = self.getProperty("ApplySensitivity").value
Expand Down Expand Up @@ -199,7 +199,7 @@ def _load_data(filename, output_ws):
if pixel_size_param is not None:
pixel_size = pixel_size_param[0]
else:
raise RuntimeError, "AbsoluteScale could not read the pixel size"
raise RuntimeError("AbsoluteScale could not read the pixel size")

attenuator_trans = self.getProperty("AttenuatorTransmission").value
# (detector count rate)/(attenuator transmission)/(monitor rate)*(pixel size/SDD)**2
Expand Down
Expand Up @@ -78,11 +78,11 @@ def PyExec(self):
x = workspace.dataX(1)
x_length = len(x)
if x_length < 2:
raise RuntimeError, "Azimuthal averaging expects at least one wavelength bin"
raise RuntimeError("Azimuthal averaging expects at least one wavelength bin")
wavelength_max = (x[x_length-2]+x[x_length-1])/2.0
wavelength_min = (x[0]+x[1])/2.0
if wavelength_min==0 or wavelength_max==0:
raise RuntimeError, "Azimuthal averaging needs positive wavelengths"
raise RuntimeError("Azimuthal averaging needs positive wavelengths")
qmin, qstep, qmax = self._get_binning(workspace, wavelength_min, wavelength_max)
align = self.getProperty("AlignWithDecades").value
log_binning = self.getProperty("LogBinning").value
Expand Down Expand Up @@ -210,7 +210,7 @@ def _get_binning(self, workspace, wavelength_min, wavelength_max):
beam_ctr_x = property_manager.getProperty("LatestBeamCenterX").value
beam_ctr_y = property_manager.getProperty("LatestBeamCenterY").value
else:
raise RuntimeError, "No beam center information can be found on the data set"
raise RuntimeError("No beam center information can be found on the data set")

# Q min is one pixel from the center, unless we have the beam trap size
if workspace.getRun().hasProperty("beam-trap-diameter"):
Expand Down
Expand Up @@ -86,7 +86,7 @@ def PyExec(self):
def _load_data(filename, output_ws):
if not property_manager.existsProperty("LoadAlgorithm"):
Logger("SANSBeamSpreaderTransmission").error("SANS reduction not set up properly: missing load algorithm")
raise RuntimeError, "SANS reduction not set up properly: missing load algorithm"
raise RuntimeError("SANS reduction not set up properly: missing load algorithm")
p=property_manager.getProperty("LoadAlgorithm")
alg=Algorithm.fromString(p.valueAsStr)
alg.setProperty("Filename", filename)
Expand Down
Expand Up @@ -30,7 +30,7 @@ def _py_init(self):
def _load_data(self, filename, output_ws, property_manager, property_manager_name):
if not property_manager.existsProperty('LoadAlgorithm'):
property_manager.existsProperty('LoadAlgorithm')
raise RuntimeError, 'SANS reduction not set up properly: missing load algorithm'
raise RuntimeError('SANS reduction not set up properly: missing load algorithm')
else:
property_manager.existsProperty('LoadAlgorithm')
p = property_manager.getProperty('LoadAlgorithm')
Expand Down
Expand Up @@ -55,7 +55,7 @@ def load_monitors(self, property_manager):
def _load_data(filename, output_ws):
if not property_manager.existsProperty("LoadAlgorithm"):
Logger("SANSDirectBeamTransmission").error("SANS reduction not set up properly: missing load algorithm")
raise RuntimeError, "SANS reduction not set up properly: missing load algorithm"
raise RuntimeError("SANS reduction not set up properly: missing load algorithm")
p=property_manager.getProperty("LoadAlgorithm")

alg_props = {"Filename": filename,
Expand Down

0 comments on commit 06eaa4f

Please sign in to comment.