def grade(self, question, env=None, skip_locked_cases=False): """Runs tests for a particular question. The setup and teardown will always be executed. question -- str; a question name (as would be entered at the command line env -- dict; an environment in which to execute the tests. If None, uses the environment of __main__. The original dictionary is never modified; each test is given a duplicate of env. skip_locked_cases -- bool; if False, locked cases will be tested Returns: dict; maps question names (str) -> results (dict). The results dictionary contains the following fields: - "passed": int (number of test cases passed) - "failed": int (number of test cases failed) - "locked": int (number of test cases locked) """ if env is None: import __main__ env = __main__.__dict__ messages = {} tests = self._resolve_specified_tests([question], all_tests=False) for test in tests: try: for suite in test.suites: suite.skip_locked_cases = skip_locked_cases suite.console.skip_locked_cases = skip_locked_cases suite.console.hash_key = self.name except AttributeError: pass test_name = tests[0].name grade(tests, messages, env) return messages['grading'][test_name]
def grade(self, tests): data = {} print("Starting grading from external request") log_id = output.new_log() grade(tests, data, verbose=self.args.verbose) printed_output = ''.join(output.get_log(log_id)) output.remove_log(log_id) data['output'] = printed_output return data