Guest User

Untitled

a guest
Jun 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import doctest
  2.  
  3. class BddDocTestRunner(doctest.DocTestRunner):
  4. """
  5. This is a customized test runner. It is meant
  6. to run code examples like DocTestRunner,
  7. but if a line preceeds the code example
  8. starting with '#', then it prints that
  9. comment.
  10.  
  11. If the line starts with '#when', it is printed
  12. out like a sentence, but with no outcome.
  13.  
  14. If the line starts with '#', but not '#when'
  15. it is printed out indented, and with the
  16. outcome.
  17. """
  18.  
  19. def report_start(self, out, test, example):
  20. prior_line = example.lineno-1
  21. line_before = test.docstring.splitlines()[prior_line]
  22. if line_before.startswith("#"):
  23. message = line_before[1:]
  24. if line_before.startswith("#when"):
  25. out("* %s\n" % message)
  26. example.silent = True
  27. example.indent = False
  28. else:
  29. out(" - %s: " % message)
  30. example.silent = False
  31. example.indent = True
  32. else:
  33. example.silent = True
  34. example.indent = False
  35. doctest.DocTestRunner(out, test, example)
  36.  
  37. def report_success(self, out, test, example, got):
  38. if not example.silent:
  39. out("ok\n")
  40. if self._verbose:
  41. if example.indent: out(" ")
  42. out(">>> %s\n" % example.source[:-1])
  43.  
  44. def report_failure(self, out, test, example, got):
  45. if not example.silent:
  46. out("FAIL\n")
  47. if self._verbose:
  48. if example.indent: out(" ")
  49. out(">>> %s\n" % example.source[:-1])
Add Comment
Please, Sign In to add comment