Example #1
0
 def check_attempt(self, test):
     now = int(time.time())
     last_attempt = get(test.name, 'last_attempt', now)
     attempts = get(test.name, 'attempts', 0)
     elapsed = now - last_attempt
     hint = self.hints[attempts % len(self.hints)]
     if attempts and hint.cooldown > elapsed:
         files = ' '.join(self.assignment.src)
         if elapsed <= RETRY_THRESHOLD * hint.cooldown:
             raise EarlyExit(COOLDOWN_MSG + hint.text.format(files=files))
         else:
             raise EarlyExit(hint.text.format(files=files) + RETRY_MSG)
     return now, attempts + 1
Example #2
0
 def get_tstfile(self, location):
     # return file, file as a string
     PATH = os.path.join(location, self.args.testing)
     name = self.args.testing
     if not name.endswith('.rst'):
         raise EarlyExit('python3 ok: error: '
                         'Only .rst files are supported at this time.')
     try:
         with open(PATH, "r") as testfile:
             data_str = testfile.read()
     except FileNotFoundError as e:
         raise EarlyExit(
             'python3 ok: error: '
             '{} test file ({}) cannot be found.'.format(
                 'Default' if DEFAULT_TST_FILE == name else 'Specified',
                 name))
     return name, data_str
Example #3
0
 def check_attempt(self, test):
     now = int(time.time())
     last_attempt = get(test.name, 'last_attempt', now)
     attempts = get(test.name, 'attempts', 0)
     secs_elapsed = now - last_attempt
     cooldown_time = self.cooldown[attempts] if attempts < len(
         self.cooldown) else self.cooldown[-1]
     cooldown = cooldown_time - secs_elapsed
     if attempts and cooldown > 0:
         files = ' '.join(self.assignment.src)
         raise EarlyExit(
             COOLDOWN_MSG.format(wait=cooldown,
                                 question=test.name.lower(),
                                 tries=attempts,
                                 files=files))
     return now, attempts + 1
Example #4
0
class TestingProtocol(models.Protocol):
    """A Protocol that executes doctests as lists of Example objects, supports 
    suite/case specificity, alternate file testing, and provides users with 
    details such as cases passed and test coverage.
    """
    def __init__(self, args, assignment):
        super().__init__(args, assignment)
        # The environment in which the doctests are run (global vars)
        self.good_env = {}
        self.verb = self.args.verbose
        # Initialize the doctest module objects that will do the testing/parse
        self.parser = DocTestParser()
        self.runner = DocTestRunner(verbose=self.verb,
                                    checker=DebugOutputChecker(),
                                    optionflags=FAIL_FAST)
        self.lines_exec = 0
        self.lines_total = 0

    def test(self, good_env={}, suite=None, case=None):
        test_results = {}
        # all examples to be run will be put in exs
        exs = collections.OrderedDict()
        # use regex to get raw strings organized into suite/case
        self.get_data()
        try:
            if suite:
                exs = self.get_suite_examples(suite, case)
            elif case:
                # No support for cases without their suite
                raise EarlyExit(
                    'python3 ok: error: '
                    'Please specify suite for given case ({}).'.format(
                        case[0]))
            else:
                exs = self.get_all_examples()
            # gets analytics to be returned
            test_results[self.tstfile_name] = self.analyze(suite, case, exs)
        except KeyError as e:
            raise EarlyExit('python3 ok: error: '
                            'Suite/Case label must be valid.'
                            '(Suites: {}, Cases: {})'.format(
                                self.num_suites, self.num_cases))
        return test_results
Example #5
0
 def handler(signum, frame):
     raise EarlyExit("Test examples timed out!")