parameters: (self)
docstring: Function validates student script using instructor script as
          reference. Test cases can optionally be provided.  The first argument
          ref_path, is the path to instructor script, it is assumed to
          have executable permission.  The second argument submit_path, is
          the path to the student script, it is assumed to have executable
          permission.  The Third optional argument is the path to test the
          scripts.  Each line in this file is a test case and each test case is
          passed to the script as standard arguments.
  
          Returns
          --------
          success - Boolean, indicating if code was executed successfully,
          correctly
          weight - Float, indicating total weight of all successful test cases
          error - String, error message if success is false
  
          returns (True, "Correct answer", 1.0) : If the student script passes
          all test cases/have same output, when compared to the instructor script
  
          returns (False, error_msg, 0.0): If the student script fails a single
          test/have dissimilar output, when compared to the instructor script.
  
          Returns (False, error_msg, 0.0): If mandatory arguments are not files
          or if the required permissions are not given to the file(s).
docstring_summary: Function validates student script using instructor script as
          reference. Test cases can optionally be provided.  The first argument
          ref_path, is the path to instructor script, it is assumed to
          have executable permission.  The second argument submit_path, is
          the path to the student script, it is assumed to have executable
          permission.  The Third optional argument is the path to test the
          scripts.  Each line in this file is a test case and each test case is
          passed to the script as standard arguments.
docstring_tokens: Function validates student script using instructor script as reference . Test cases can optionally be provided . The first argument ref_path is the path to instructor script it is assumed to have executable permission . The second argument submit_path is the path to the student script it is assumed to have executable permission . The Third optional argument is the path to test the scripts . Each line in this file is a test case and each test case is passed to the script as standard arguments .
function: def check_code(self):
          """ Function validates student script using instructor script as
          reference. Test cases can optionally be provided.  The first argument
          ref_path, is the path to instructor script, it is assumed to
          have executable permission.  The second argument submit_path, is
          the path to the student script, it is assumed to have executable
          permission.  The Third optional argument is the path to test the
          scripts.  Each line in this file is a test case and each test case is
          passed to the script as standard arguments.
  
          Returns
          --------
          success - Boolean, indicating if code was executed successfully,
          correctly
          weight - Float, indicating total weight of all successful test cases
          error - String, error message if success is false
  
          returns (True, "Correct answer", 1.0) : If the student script passes
          all test cases/have same output, when compared to the instructor script
  
          returns (False, error_msg, 0.0): If the student script fails a single
          test/have dissimilar output, when compared to the instructor script.
  
          Returns (False, error_msg, 0.0): If mandatory arguments are not files
          or if the required permissions are not given to the file(s).
          """
          mark_fraction = 0.0
          self.submit_code_path = self.create_submit_code_file('submit.sh')
          self._set_file_as_executable(self.submit_code_path)
          self.test_code_path = self.create_submit_code_file('main.sh')
          self._set_file_as_executable(self.test_code_path)
          if self.test_case_args:
              self.tc_args_path = self.create_submit_code_file('main.args')
              self.write_to_submit_code_file(self.tc_args_path,
                                             self.test_case_args)
          shebang = "#!/bin/bash\n"
          self.user_answer = shebang + self.user_answer.replace("\r", "")
          self.test_case = self.test_case.replace("\r", "")
          self.write_to_submit_code_file(self.submit_code_path, self.user_answer)
          self.write_to_submit_code_file(self.test_code_path, self.test_case)
          clean_ref_code_path, clean_test_case_path = \
              self.test_code_path, self.tc_args_path
  
          if self.file_paths:
              self.files = copy_files(self.file_paths)
          if not isfile(clean_ref_code_path):
              msg = "No file at %s or Incorrect path" % clean_ref_code_path
              return False, msg, 0.0
          if not isfile(self.submit_code_path):
              msg = "No file at %s or Incorrect path" % self.submit_code_path
              return False, msg, 0.0
          if not os.access(clean_ref_code_path, os.X_OK):
              msg = "Script %s is not executable" % clean_ref_code_path
              return False, msg, 0.0
          if not os.access(self.submit_code_path, os.X_OK):
              msg = "Script %s is not executable" % self.submit_code_path
              return False, msg, 0.0
  
          if not clean_test_case_path:
              ret = self._run_command(["bash", clean_ref_code_path],
                                      stdin=None,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE
                                      )
              proc, inst_stdout, inst_stderr = ret
              ret = self._run_command(["bash", self.submit_code_path],
                                      stdin=None,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE
                                      )
              proc, stdnt_stdout, stdnt_stderr = ret
              if inst_stdout == stdnt_stdout:
                  mark_fraction = 1.0 if self.partial_grading else 0.0
                  return True, None, mark_fraction
              else:
                  err = "Error: expected %s, got %s" % (
                      inst_stdout + inst_stderr,
                      stdnt_stdout + stdnt_stderr
                  )
                  return False, err, 0.0
          else:
              if not isfile(clean_test_case_path):
                  msg = "No test case at %s" % clean_test_case_path
                  return False, msg, 0.0
              if not os.access(clean_ref_code_path, os.R_OK):
                  msg = "Test script %s, not readable" % clean_test_case_path
                  return False, msg, 0.0
              # valid_answer is True, so that we can stop once a test case fails
              valid_answer = True
              # loop_count has to be greater than or equal to one.
              # Useful for caching things like empty test files,etc.
              loop_count = 0
              test_cases = open(clean_test_case_path).readlines()
              num_lines = len(test_cases)
              for tc in test_cases:
                  loop_count += 1
                  if valid_answer:
                      args = ["bash", clean_ref_code_path] + \
                          [x for x in tc.split()]
                      ret = self._run_command(args,
                                              stdin=None,
                                              stdout=subprocess.PIPE,
                                              stderr=subprocess.PIPE
                                              )
                      proc, inst_stdout, inst_stderr = ret
                      if self.file_paths:
                          self.files = copy_files(self.file_paths)
                      args = ["bash", self.submit_code_path] + \
                          [x for x in tc.split()]
                      ret = self._run_command(args,
                                              stdin=None,
                                              stdout=subprocess.PIPE,
                                              stderr=subprocess.PIPE
                                              )
                      proc, stdnt_stdout, stdnt_stderr = ret
                      valid_answer = inst_stdout == stdnt_stdout
              if valid_answer and (num_lines == loop_count):
                  mark_fraction = 1.0 if self.partial_grading else 0.0
                  return True, None, mark_fraction
              else:
                  err = ("Error:expected {0}, got {1}").format(
                          inst_stdout+inst_stderr,
                          stdnt_stdout+stdnt_stderr
                      )
                  return False, err, 0.0
function_tokens: def check_code ( self ) : mark_fraction = 0.0 self . submit_code_path = self . create_submit_code_file ( 'submit.sh' ) self . _set_file_as_executable ( self . submit_code_path ) self . test_code_path = self . create_submit_code_file ( 'main.sh' ) self . _set_file_as_executable ( self . test_code_path ) if self . test_case_args : self . tc_args_path = self . create_submit_code_file ( 'main.args' ) self . write_to_submit_code_file ( self . tc_args_path , self . test_case_args ) shebang = "#!/bin/bash\n" self . user_answer = shebang + self . user_answer . replace ( "\r" , "" ) self . test_case = self . test_case . replace ( "\r" , "" ) self . write_to_submit_code_file ( self . submit_code_path , self . user_answer ) self . write_to_submit_code_file ( self . test_code_path , self . test_case ) clean_ref_code_path , clean_test_case_path = self . test_code_path , self . tc_args_path if self . file_paths : self . files = copy_files ( self . file_paths ) if not isfile ( clean_ref_code_path ) : msg = "No file at %s or Incorrect path" % clean_ref_code_path return False , msg , 0.0 if not isfile ( self . submit_code_path ) : msg = "No file at %s or Incorrect path" % self . submit_code_path return False , msg , 0.0 if not os . access ( clean_ref_code_path , os . X_OK ) : msg = "Script %s is not executable" % clean_ref_code_path return False , msg , 0.0 if not os . access ( self . submit_code_path , os . X_OK ) : msg = "Script %s is not executable" % self . submit_code_path return False , msg , 0.0 if not clean_test_case_path : ret = self . _run_command ( [ "bash" , clean_ref_code_path ] , stdin = None , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) proc , inst_stdout , inst_stderr = ret ret = self . _run_command ( [ "bash" , self . submit_code_path ] , stdin = None , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) proc , stdnt_stdout , stdnt_stderr = ret if inst_stdout == stdnt_stdout : mark_fraction = 1.0 if self . partial_grading else 0.0 return True , None , mark_fraction else : err = "Error: expected %s, got %s" % ( inst_stdout + inst_stderr , stdnt_stdout + stdnt_stderr ) return False , err , 0.0 else : if not isfile ( clean_test_case_path ) : msg = "No test case at %s" % clean_test_case_path return False , msg , 0.0 if not os . access ( clean_ref_code_path , os . R_OK ) : msg = "Test script %s, not readable" % clean_test_case_path return False , msg , 0.0 # valid_answer is True, so that we can stop once a test case fails valid_answer = True # loop_count has to be greater than or equal to one. # Useful for caching things like empty test files,etc. loop_count = 0 test_cases = open ( clean_test_case_path ) . readlines ( ) num_lines = len ( test_cases ) for tc in test_cases : loop_count += 1 if valid_answer : args = [ "bash" , clean_ref_code_path ] + [ x for x in tc . split ( ) ] ret = self . _run_command ( args , stdin = None , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) proc , inst_stdout , inst_stderr = ret if self . file_paths : self . files = copy_files ( self . file_paths ) args = [ "bash" , self . submit_code_path ] + [ x for x in tc . split ( ) ] ret = self . _run_command ( args , stdin = None , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) proc , stdnt_stdout , stdnt_stderr = ret valid_answer = inst_stdout == stdnt_stdout if valid_answer and ( num_lines == loop_count ) : mark_fraction = 1.0 if self . partial_grading else 0.0 return True , None , mark_fraction else : err = ( "Error:expected {0}, got {1}" ) . format ( inst_stdout + inst_stderr , stdnt_stdout + stdnt_stderr ) return False , err , 0.0