Exemple #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 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.lstrip())
     module = self.SETUP.format(importing.path_to_module_string(self.file))
     self.case = doctest_case.DoctestCase(self.console,
                                          module,
                                          code='\n'.join(code))
Exemple #2
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))
Exemple #3
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 interpreter.Console.CASE_PREFIX in line.strip():
             self.console.show_all_cases = True
         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))
 def get_code(self):
     """Render code for tracing."""
     setup = self.IMPORT_STRING.format(importing.path_to_module_string(self.file))
     data = {
         self.name: {
         'setup': setup + '\n',
         'code': self.case.formatted_code(),
         'teardown': '',
         }
     }
     return data