README 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. Gajja: Fake objects for real tests
  2. ##################################
  3. The `gajja` library provides a system of Python `test double`_ classes
  4. for specific system objects:
  5. * `Filesystem entries`_
  6. * `Subprocesses`_
  7. .. _test double: http://xunitpatterns.com/Test%20Double.html
  8. The Korean word 가짜 (*gajja*; IPA ˈkaːt͡ɕ̤a) means “fake thing”.
  9. ============
  10. Test doubles
  11. ============
  12. Filesystem entries
  13. ==================
  14. * Create a `gajja.FileDouble` instance for the specific filesystem
  15. path, and the file content you want the fake file to present.
  16. * Register that `FileDouble` instance to the test case, so it will
  17. only be faked during that one test case.
  18. * Call helper functions that wrap a `mock.patch` object around each of
  19. the specific system APIs that access the filesystem (e.g.
  20. `gajja.patch_os_path_exists`, `gajja.patch_os_stat`, etc.).
  21. * Customise the `FileDouble` instance's behaviour in response to any
  22. of those interfaces (e.g. `FileDouble.set_os_stat_scenario`, etc.),
  23. or leave the default behaviour.
  24. * Test your program code as normal, letting it call the filesystem
  25. access APIs. When the program accesses the filesystem path for the
  26. `FileDouble`, the test double's behaviour will be invoked; for any
  27. other filesystem path, the normal API's behaviour will occur.
  28. * Inspect the `FileDouble` instance for changes you need to assert in
  29. the unit test (e.g. `FileDouble.fake_file.getvalue`). Inspect the
  30. API mock objects to see how they were called (e.g.
  31. `os.stat.assert_called_with`).
  32. * At the end of the test case, `mock.patch` will ensure the wrapper is
  33. removed and the normal API behaviour continues.
  34. Subprocesses
  35. ============
  36. =======
  37. Copying
  38. =======
  39. Copyright © 2015–2016 Ben Finney <ben+python@benfinney.id.au>
  40. This is free software: you may copy, modify, and/or distribute this work
  41. under the terms of the GNU General Public License as published by the
  42. Free Software Foundation; version 3 of that license or any later version.
  43. No warranty expressed or implied. See the file ‘LICENSE.GPL-3’ for details.
  44. ..
  45. This document is written using `reStructuredText`_ markup, and can
  46. be rendered with `Docutils`_ to other formats.
  47. .. _Docutils: http://docutils.sourceforge.net/
  48. .. _reStructuredText: http://docutils.sourceforge.net/rst.html
  49. ..
  50. Local variables:
  51. coding: utf-8
  52. mode: text
  53. mode: rst
  54. End:
  55. vim: fileencoding=utf-8 filetype=rst :