diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-17 20:28:09 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-17 20:28:09 +0200 |
commit | 3de7b673a08d3931beb03af28d471b984f411d23 (patch) | |
tree | 2220d3320686a0d817983b6c7f53ecf29ae1390f /psutil/_psutil_common.c | |
parent | c630eff0991116c036723a80531e85d8d599e6c8 (diff) | |
download | psutil-testing-envvar.tar.gz |
Introduce PSUTIL_TESTING env varpsutil-testing-envvar
...so that we can make stricter assertions in C and py code during tests
only.
* define a C function in _common.c which returns whether the var is set
* set PSUTIL_TESTING from the Makefile
Diffstat (limited to 'psutil/_psutil_common.c')
-rw-r--r-- | psutil/_psutil_common.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/psutil/_psutil_common.c b/psutil/_psutil_common.c index bcbd623b..37cc2f16 100644 --- a/psutil/_psutil_common.c +++ b/psutil/_psutil_common.c @@ -7,6 +7,7 @@ */ #include <Python.h> +#include <stdio.h> /* * Set OSError(errno=ESRCH, strerror="No such process") Python exception. @@ -37,6 +38,30 @@ AccessDenied(void) { /* + * Return 1 if PSUTIL_TESTING env var is set else 0. + */ +int +psutil_testing(void) { + if (getenv("PSUTIL_TESTING") != NULL) + return 1; + else + return 0; +} + + +/* + * Return True if PSUTIL_TESTING env var is set else False. + */ +PyObject * +py_psutil_testing(PyObject *self, PyObject *args) { + PyObject *res; + res = psutil_testing() ? Py_True : Py_False; + Py_INCREF(res); + return res; +} + + +/* * Backport of unicode FS APIs from Python 3. * On Python 2 we just return a plain byte string * which is never supposed to raise decoding errors. @@ -52,4 +77,4 @@ PyObject * PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size) { return PyString_FromStringAndSize(s, size); } -#endif
\ No newline at end of file +#endif |