test_tutorial.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8; -*-
  2. #
  3. # test/test_tutorial.py
  4. # Part of Gajja, a Python test double library.
  5. #
  6. # Copyright © 2016 Ben Finney <ben+python@benfinney.id.au>
  7. #
  8. # This is free software: you may copy, modify, and/or distribute this work
  9. # under the terms of the GNU General Public License as published by the
  10. # Free Software Foundation; version 3 of that license or any later version.
  11. # No warranty expressed or implied. See the file ‘LICENSE.GPL-3’ for details.
  12. """ Test suite for tutorial examples. """
  13. from __future__ import (absolute_import, unicode_literals)
  14. import os
  15. import os.path
  16. import doctest
  17. __package__ = str("test")
  18. __import__(__package__)
  19. this_dir = os.path.dirname(__file__)
  20. doc_dir = os.path.join(os.path.pardir, "doc")
  21. def load_tests(loader, tests, pattern):
  22. """ Test discovery hook to load test cases for this module.
  23. :param loader: The `unittest.TestLoader` instance to use for
  24. loading test cases.
  25. :param tests: Collection of cases already loaded for this
  26. module.
  27. :param pattern: File glob pattern to match test modules.
  28. :return: A `unittest.TestSuite` instance comprising the
  29. modified test suite for this module.
  30. See the `load_tests protocol`_ section of the Python
  31. `unittest` documentation.
  32. .. _load_tests protocol:
  33. https://docs.python.org/3/library/unittest.html#load-tests-protocol
  34. """
  35. tutorial_file_path = os.path.join(doc_dir, "tutorial.txt")
  36. tests.addTests(doctest.DocFileSuite(
  37. tutorial_file_path,
  38. optionflags=doctest.NORMALIZE_WHITESPACE))
  39. return tests
  40. # Local variables:
  41. # coding: utf-8
  42. # mode: python
  43. # End:
  44. # vim: fileencoding=utf-8 filetype=python :