diff options
author | Palaparthy Adityachandra | 2020-04-30 17:24:17 +0530 |
---|---|---|
committer | GitHub | 2020-04-30 17:24:17 +0530 |
commit | 2fd29bf1fff3d57a49b8a5cdffa9efc305946214 (patch) | |
tree | 16d974b5a5e1effaf15be2235813dca4108c4f29 /yaksh/r_code_evaluator.py | |
parent | 6fc01303dba0b821aa2344b761e98dc36b33807b (diff) | |
parent | 53a0c4ad3e733f3960000527f83565f2fd8fc412 (diff) | |
download | online_test-2fd29bf1fff3d57a49b8a5cdffa9efc305946214.tar.gz online_test-2fd29bf1fff3d57a49b8a5cdffa9efc305946214.tar.bz2 online_test-2fd29bf1fff3d57a49b8a5cdffa9efc305946214.zip |
Merge branch 'master' into API
Diffstat (limited to 'yaksh/r_code_evaluator.py')
-rw-r--r-- | yaksh/r_code_evaluator.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/yaksh/r_code_evaluator.py b/yaksh/r_code_evaluator.py index ca4c94a..8eaeb38 100644 --- a/yaksh/r_code_evaluator.py +++ b/yaksh/r_code_evaluator.py @@ -7,6 +7,7 @@ import re # Local imports from .base_evaluator import BaseEvaluator from .file_utils import copy_files, delete_files +from .error_messages import prettify_exceptions class RCodeEvaluator(BaseEvaluator): @@ -49,9 +50,8 @@ class RCodeEvaluator(BaseEvaluator): # Throw message if there are commmands that terminates scilab add_err = "" if terminate_commands: - add_err = "Please do not use quit() in your\ - code.\n Otherwise your code will not be evaluated\ - correctly.\n" + add_err = "Please do not use quit() q() in your code.\ + \n Otherwise your code will not be evaluated.\n" cmd = 'Rscript main.r' ret = self._run_command(cmd, shell=True, stdout=subprocess.PIPE, @@ -66,10 +66,12 @@ class RCodeEvaluator(BaseEvaluator): success, err = True, None mark_fraction = 1.0 if self.partial_grading else 0.0 else: - err = add_err + stdout + err = stdout + add_err else: - err = add_err + stderr - + err = stderr + add_err + if err: + err = re.sub(r'.*?: ', '', err, count=1) + err = prettify_exceptions('Error', err) return success, err, mark_fraction def _remove_r_quit(self, string): @@ -79,7 +81,8 @@ class RCodeEvaluator(BaseEvaluator): new_string = "" terminate_commands = False for line in string.splitlines(): - new_line = re.sub(r"quit.*$", "", line) + new_line = re.sub(r'quit(.*$)', "", line) + new_line = re.sub(r'q(.*$)', "", new_line) if line != new_line: terminate_commands = True new_string = new_string + '\n' + new_line |