Author: bugman Date: Tue Jan 8 15:36:16 2008 New Revision: 4487 URL: http://svn.gna.org/viewcvs/relax?rev=4487&view=rev Log: prompt.interpreter.interact_script() has been modified to allow RelaxErrors to be raised. Previously running a script would catch the error, send a nice message to STDERR, and quit. Now the function can raise the error if asked. This is required for the system tests (because of the unittest framework). Alternatively the status of the script could have been used by the test, but this is easier for the test writer and makes the code more flexible. Modified: 1.3/prompt/interpreter.py 1.3/relax Modified: 1.3/prompt/interpreter.py URL: http://svn.gna.org/viewcvs/relax/1.3/prompt/interpreter.py?rev=4487&r1=4486&r2=4487&view=diff ============================================================================== --- 1.3/prompt/interpreter.py (original) +++ 1.3/prompt/interpreter.py Tue Jan 8 15:36:16 2008 @@ -78,19 +78,23 @@ class Interpreter: - def __init__(self, relax, intro_string=None, show_script=True, quit=True): + def __init__(self, relax, intro_string=None, show_script=True, quit=True, raise_relax_error=False): """The interpreter class. - @param relax: The relax instance. - @type relax: instance - @param intro_string: The string to print at the start of execution. - @type intro_string: str - @param show_script: If true, the relax will print the script contents prior to executing - the script. - @type show_script: bool - @param quit: If true, the default, then relax will exit after running the run() - method. - @type quit: bool + @param relax: The relax instance. + @type relax: instance + @param intro_string: The string to print at the start of execution. + @type intro_string: str + @param show_script: If true, the relax will print the script contents prior to + executing the script. + @type show_script: bool + @param quit: If true, the default, then relax will exit after running the + run() method. + @type quit: bool + @param raise_relax_error: If false, the default, then relax will print a nice error + message to STDERR, without a traceback, when a RelaxError + occurs. This is to make things nicer for the user. + @type raise_relax_error: bool """ # Place the arguments in the class namespace. @@ -98,6 +102,7 @@ self.__intro_string = intro_string self.__show_script = show_script self.__quit_flag = quit + self.__raise_relax_error = raise_relax_error # The prompts. sys.ps1 = 'relax> ' @@ -241,7 +246,7 @@ self.intro = 1 # Run the script. - return run_script(intro=self.__intro_string, local=self.local, script_file=script_file, quit=self.__quit_flag, show_script=self.__show_script) + return run_script(intro=self.__intro_string, local=self.local, script_file=script_file, quit=self.__quit_flag, show_script=self.__show_script, raise_relax_error=self.__raise_relax_error) # Test for the dummy mode for generating documentation (then exit). elif hasattr(self.relax, 'dummy_mode'): @@ -337,7 +342,7 @@ more = 0 -def interact_script(self, intro, local, script_file, quit, show_script=True): +def interact_script(self, intro, local, script_file, quit, show_script=True, raise_relax_error=False): """Replacement function for 'code.InteractiveConsole.interact'. This will execute the script file. @@ -389,16 +394,22 @@ # Catch the RelaxErrors. except AllRelaxErrors, instance: - # Print the scary traceback normally hidden from the user. - if Debug: - self.showtraceback() - - # Print the RelaxError message line. + # Throw the error. + if raise_relax_error: + raise + + # Nice output for the user. else: - sys.stderr.write(instance.__str__()) - - # The script failed. - status = False + # Print the scary traceback normally hidden from the user. + if Debug: + self.showtraceback() + + # Print the RelaxError message line. + else: + sys.stderr.write(instance.__str__()) + + # The script failed. + status = False # Throw all other errors. except: @@ -431,7 +442,7 @@ console.interact(intro, local) -def run_script(intro=None, local=None, script_file=None, quit=1, show_script=True): +def run_script(intro=None, local=None, script_file=None, quit=1, show_script=True, raise_relax_error=False): """Python interpreter emulation. This function replaces 'code.interact'. @@ -443,7 +454,7 @@ # The console. console = InteractiveConsole(local) - return console.interact(intro, local, script_file, quit, show_script=show_script) + return console.interact(intro, local, script_file, quit, show_script=show_script, raise_relax_error=raise_relax_error) def runcode(self, code): Modified: 1.3/relax URL: http://svn.gna.org/viewcvs/relax/1.3/relax?rev=4487&r1=4486&r2=4487&view=diff ============================================================================== --- 1.3/relax (original) +++ 1.3/relax Tue Jan 8 15:36:16 2008 @@ -168,7 +168,7 @@ # Execute the relax test suite elif mode == 'test suite': # Load the interpreter and turn intros on. - self.interpreter = interpreter.Interpreter(self, show_script=False, quit=False) + self.interpreter = interpreter.Interpreter(self, show_script=False, quit=False, raise_relax_error=True) self.interpreter._on() # Run the tests. @@ -178,7 +178,7 @@ # Execute the relax system tests. elif mode == 'system tests': # Load the interpreter and turn intros on. - self.interpreter = interpreter.Interpreter(self, show_script=False, quit=False) + self.interpreter = interpreter.Interpreter(self, show_script=False, quit=False, raise_relax_error=True) self.interpreter._on() # Run the tests.