def test_get_run_plot_no_file(self): """Should raise IOError if run file doesn't exist.""" with self.assertRaises(IOError): # Suppress ROOT error warnings about nonexistent file old_level = ROOT.gErrorIgnoreLevel ROOT.gErrorIgnoreLevel = ROOT.kFatal plots.get_run_plot('fake_plot', 999000) ROOT.gErrorIgnoreLevel = old_level
def runview_plot(run, name, sensor, run_data_dir, refRun='Auto', getRef=False, normalise=False, notifyBox=None): Config().run_data_dir = run_data_dir err = False # Need to append the sensor number to the name. # if not utils.valid_run(run): # err = True # msg = "Invalid run number provided: {0}".format(run) # print msg if not utils.valid_sensor(sensor): err = True msg = "Invalid sensor number provided: {0}".format(sensor) print msg name = name.format(sensor) if getRef: if refRun == 'Auto': print 'Getting auto ref' return plots.get_run_plot_with_reference(name, run, normalise=normalise, notifyBox=notifyBox) else: print 'Getting specified ref' return plots.get_run_plot_with_reference(name, run, refRun=refRun, normalise=normalise, notifyBox=notifyBox) else: return plots.get_run_plot(name, run, normalise=normalise, notifyBox=notifyBox)
def retrieve_run_view_plot(run, plot, sensor, reference): from veloview.runview import plots, response_formatters, utils # Check all arguments have valid values if not utils.valid_run(run): sys.stderr.write("Invalid run number provided: {0}".format(run)) sys.exit(1) if not utils.valid_sensor(sensor): sys.stderr.write("Invalid sensor number provided: {0}".format(sensor)) sys.exit(1) # Format the plot name with the sensor number # str.format will work even with no format specifiers in the string plot = plot.format(sensor) # Try to the get the plot object try: plot_obj = plots.get_run_plot(plot, run, reference=reference) except KeyError, e: sys.stderr.write("Invalid plot name provided: {0}".format(plot)) sys.stderr.write("Exception caught: {0}".format(e)) sys.exit(1)
def retrieve_run_view_plot(run, plot, sensor, noreference, run_data_dir): import json from veloview.runview import plots, response_formatters, utils # Change the run data directory to the user-specified one Config().run_data_dir = run_data_dir # Check all arguments have valid values err = False if not utils.valid_run(run): err = True msg = "Invalid run number provided: {0}".format(run) if not utils.valid_sensor(sensor): err = True msg = "Invalid sensor number provided: {0}".format(sensor) if err: exit_with_error(msg) # Format the plot name with the sensor number # str.format will work even with no format specifiers in the string plot = plot.format(sensor) # Try to the get the plot object, formatting it to JSON try: if noreference: # Return a 2-tuple to be consistent with the nominal+reference case response = (plots.get_run_plot( plot, run, reference=False, formatter=response_formatters.json_formatter), json.dumps(None)) else: response = plots.get_run_plot_with_reference( plot, run, formatter=response_formatters.json_formatter) except KeyError, e: err = True msg = ("Invalid plot name provided: {0}. " "Exception caught: {1}.").format(plot, e)
def test_get_run_plot_no_key(self): """Should raise KeyError if plot doesn't exist in run file.""" with self.assertRaises(KeyError): plots.get_run_plot('fake_plot', NOMINAL_RUN)
def test_get_run_plot_reference(self): """Should return the reference plot if reference is True.""" plot = plots.get_run_plot('h', NOMINAL_RUN, reference=True) self.assertEqual(plot.GetTitle(), 'h_ref')
def test_get_run_plot(self): """Should return plot from the correct run file.""" plot = plots.get_run_plot('h', NOMINAL_RUN) self.assertEqual(plot.GetTitle(), 'h_nom')
def test_get_run_plot_reference(self): """Should return the reference plot if reference is True.""" reference = plots.get_run_plot('h', NOMINAL_RUN, reference=True) self.assertEqual(reference['data']['title'], 'h_ref')
def test_get_run_plot(self): """Should return plot from the correct run file.""" plot = plots.get_run_plot('h', NOMINAL_RUN) self.assertEqual(plot['data']['title'], 'h_nom')