Beispiel #1
0
 def post_instantiation(self):
     # TODO(albert): rewrite test validation. Inconsistent leading space is
     # currently not validated correctly (see tests).
     self.docstring = textwrap.dedent(self.docstring)
     code = []
     prompt_on = False
     leading_space = ''
     for line in self.docstring.split('\n'):
         prompt_match = self.prompt_re.match(line)
         if prompt_match:
             if prompt_on and not line.startswith(leading_space):
                 raise ex.SerializeException(
                     'Inconsistent tabs for doctest')
             elif not prompt_on:
                 prompt_on = True
                 leading_space = prompt_match.group(1)
             code.append(line.lstrip())
         elif line.endswith('...'):
             # A line consisting only of ... is treated as a noop. See
             # issue #46
             continue
         elif not line.strip():
             prompt_on = False
             leading_space = ''
         elif prompt_on:
             if not line.startswith(leading_space):
                 raise ex.SerializeException(
                     'Inconsistent tabs for doctest')
             code.append(line[len(leading_space):])
     module = self.SETUP.format(importing.path_to_module_string(self.file))
     self.case = interpreter.CodeCase(self.console,
                                      module,
                                      code='\n'.join(code))
Beispiel #2
0
 def makeCase(self, code):
     return interpreter.CodeCase(self.console, code=code)
Beispiel #3
0
 def makeCase(self, **fields):
     return interpreter.CodeCase(self.console, **fields)
Beispiel #4
0
 def makeCase(self, code, setup='', teardown=''):
     return interpreter.CodeCase(self.console, setup, teardown, code=code)
Beispiel #5
0
 def post_instantiation(self):
     for i, case in enumerate(self.cases):
         if not isinstance(case, dict):
             raise ex.SerializeException('Test cases must be dictionaries')
         self.cases[i] = interpreter.CodeCase(self.console, self.setup,
                                              self.teardown, **case)