Python library to create test doubles that fake basic system interfaces: filesystem entries, subprocesses.

Ben Finney 0acc3cdb43 Prepare a new change log entry for development. 8 years ago
doc 46ee346d38 Explain why we use ‘tempfile.mktemp’ specifically. 8 years ago
gajja ffd3d2aab7 Refactor patch of ‘builtins.open’ to a separate function. 8 years ago
test 94541f9091 Rename project to have normal title case for the name. 8 years ago
.gitignore 09d2f18615 Add Git ignore patterns for common Python artifacts. 8 years ago
CHANGES 0acc3cdb43 Prepare a new change log entry for development. 8 years ago
CONTRIBUTORS ef270bbb89 Add a file to contain identities of contributors to this work. 8 years ago
LICENSE.GPL-3 6836025d70 Add text of GNU GPLv3. 8 years ago
MANIFEST.in 1c0a2b17f3 Distribute full source code in generated ‘sdist’. 8 years ago
README d271f8e7b3 Add a point-form overview of how file doubles solve a problem. 8 years ago
setup.py 98da9b4b47 Finalise version “0.1.3”. 8 years ago

README

Gajja: Fake objects for real tests
##################################

The `gajja` library provides a system of Python `test double`_ classes
for specific system objects:

* `Filesystem entries`_

* `Subprocesses`_

.. _test double: http://xunitpatterns.com/Test%20Double.html

The Korean word 가짜 (*gajja*; IPA ˈkaːt͡ɕ̤a) means “fake thing”.


============
Test doubles
============

Filesystem entries
==================

* Create a `gajja.FileDouble` instance for the specific filesystem
path, and the file content you want the fake file to present.

* Register that `FileDouble` instance to the test case, so it will
only be faked during that one test case.

* Call helper functions that wrap a `mock.patch` object around each of
the specific system APIs that access the filesystem (e.g.
`gajja.patch_os_path_exists`, `gajja.patch_os_stat`, etc.).

* Customise the `FileDouble` instance's behaviour in response to any
of those interfaces (e.g. `FileDouble.set_os_stat_scenario`, etc.),
or leave the default behaviour.

* Test your program code as normal, letting it call the filesystem
access APIs. When the program accesses the filesystem path for the
`FileDouble`, the test double's behaviour will be invoked; for any
other filesystem path, the normal API's behaviour will occur.

* Inspect the `FileDouble` instance for changes you need to assert in
the unit test (e.g. `FileDouble.fake_file.getvalue`). Inspect the
API mock objects to see how they were called (e.g.
`os.stat.assert_called_with`).

* At the end of the test case, `mock.patch` will ensure the wrapper is
removed and the normal API behaviour continues.


Subprocesses
============



=======
Copying
=======

Copyright © 2015–2016 Ben Finney

This is free software: you may copy, modify, and/or distribute this work
under the terms of the GNU General Public License as published by the
Free Software Foundation; version 3 of that license or any later version.
No warranty expressed or implied. See the file ‘LICENSE.GPL-3’ for details.


..
This document is written using `reStructuredText`_ markup, and can
be rendered with `Docutils`_ to other formats.

.. _Docutils: http://docutils.sourceforge.net/
.. _reStructuredText: http://docutils.sourceforge.net/rst.html

..
Local variables:
coding: utf-8
mode: text
mode: rst
End:
vim: fileencoding=utf-8 filetype=rst :