diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-11-11 21:35:41 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-11-11 21:35:41 +0100 |
commit | 0662915f58949a4084f9fb0c278d143708cf3ede (patch) | |
tree | 48ad658a3312343a1a42bf268a015aaace562c86 | |
parent | ffde3264f09c5412ce3987617130f2c9d5d7a22b (diff) | |
download | psutil-test-flag.tar.gz |
get rid of PSUTIL_TESTING env var: it must be necessarily set from cmdline, hence 'python -m psutil.tests' won't work out of the boxpsutil-test-flag
-rw-r--r-- | psutil/_psutil_aix.c | 6 | ||||
-rw-r--r-- | psutil/_psutil_bsd.c | 6 | ||||
-rw-r--r-- | psutil/_psutil_common.c | 18 | ||||
-rw-r--r-- | psutil/_psutil_common.h | 3 | ||||
-rw-r--r-- | psutil/_psutil_linux.c | 6 | ||||
-rw-r--r-- | psutil/_psutil_osx.c | 6 | ||||
-rw-r--r-- | psutil/_psutil_sunos.c | 6 | ||||
-rw-r--r-- | psutil/_psutil_windows.c | 6 | ||||
-rw-r--r-- | psutil/tests/__init__.py | 4 |
9 files changed, 38 insertions, 23 deletions
diff --git a/psutil/_psutil_aix.c b/psutil/_psutil_aix.c index 0834726d..3b188b85 100644 --- a/psutil/_psutil_aix.c +++ b/psutil/_psutil_aix.c @@ -899,8 +899,10 @@ PsutilMethods[] = "Return CPU statistics"}, // --- others - {"py_psutil_testing", py_psutil_testing, METH_VARARGS, - "Return True if PSUTIL_TESTING env var is set"}, + {"py_psutil_is_testing", py_psutil_is_testing, METH_VARARGS, + "Return True if psutil is in testing mode"}, + {"py_psutil_set_testing", py_psutil_set_testing, METH_VARARGS, + "Set psutil in testing mode"}, {NULL, NULL, 0, NULL} }; diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c index 3527b666..7b0f140e 100644 --- a/psutil/_psutil_bsd.c +++ b/psutil/_psutil_bsd.c @@ -984,8 +984,10 @@ PsutilMethods[] = { #endif // --- others - {"py_psutil_testing", py_psutil_testing, METH_VARARGS, - "Return True if PSUTIL_TESTING env var is set"}, + {"py_psutil_is_testing", py_psutil_is_testing, METH_VARARGS, + "Return True if psutil is in testing mode"}, + {"py_psutil_set_testing", py_psutil_set_testing, METH_VARARGS, + "Set psutil in testing mode"}, {NULL, NULL, 0, NULL} }; diff --git a/psutil/_psutil_common.c b/psutil/_psutil_common.c index dace4724..1fd2344e 100644 --- a/psutil/_psutil_common.c +++ b/psutil/_psutil_common.c @@ -37,7 +37,7 @@ AccessDenied(void) { } -static int _psutil_testing = -1; +static int _psutil_testing = 0; /* @@ -45,12 +45,6 @@ static int _psutil_testing = -1; */ int psutil_testing(void) { - if (_psutil_testing == -1) { - if (getenv("PSUTIL_TESTING") != NULL) - _psutil_testing = 1; - else - _psutil_testing = 0; - } return _psutil_testing; } @@ -59,7 +53,7 @@ psutil_testing(void) { * Return True if PSUTIL_TESTING env var is set else False. */ PyObject * -py_psutil_testing(PyObject *self, PyObject *args) { +py_psutil_is_testing(PyObject *self, PyObject *args) { PyObject *res; res = psutil_testing() ? Py_True : Py_False; Py_INCREF(res); @@ -67,6 +61,14 @@ py_psutil_testing(PyObject *self, PyObject *args) { } +PyObject * +py_psutil_set_testing(PyObject *self, PyObject *args) { + _psutil_testing = 1; + Py_INCREF(Py_None); + return Py_None; +} + + /* * Backport of unicode FS APIs from Python 3. * On Python 2 we just return a plain byte string diff --git a/psutil/_psutil_common.h b/psutil/_psutil_common.h index 13404532..09999bba 100644 --- a/psutil/_psutil_common.h +++ b/psutil/_psutil_common.h @@ -12,7 +12,8 @@ static const int PSUTIL_CONN_NONE = 128; PyObject* AccessDenied(void); PyObject* NoSuchProcess(void); int psutil_testing(void); -PyObject* py_psutil_testing(PyObject *self, PyObject *args); +PyObject* py_psutil_is_testing(PyObject *self, PyObject *args); +PyObject* py_psutil_set_testing(PyObject *self, PyObject *args); #if PY_MAJOR_VERSION < 3 PyObject* PyUnicode_DecodeFSDefault(char *s); PyObject* PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size); diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c index a15ebe5c..2391a67a 100644 --- a/psutil/_psutil_linux.c +++ b/psutil/_psutil_linux.c @@ -607,8 +607,10 @@ PsutilMethods[] = { #endif // --- others - {"py_psutil_testing", py_psutil_testing, METH_VARARGS, - "Return True if PSUTIL_TESTING env var is set"}, + {"py_psutil_is_testing", py_psutil_is_testing, METH_VARARGS, + "Return True if psutil is in testing mode"}, + {"py_psutil_set_testing", py_psutil_set_testing, METH_VARARGS, + "Set psutil in testing mode"}, {NULL, NULL, 0, NULL} }; diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c index 2924aa39..9908d033 100644 --- a/psutil/_psutil_osx.c +++ b/psutil/_psutil_osx.c @@ -1845,8 +1845,10 @@ PsutilMethods[] = { "Return CPU statistics"}, // --- others - {"py_psutil_testing", py_psutil_testing, METH_VARARGS, - "Return True if PSUTIL_TESTING env var is set"}, + {"py_psutil_is_testing", py_psutil_is_testing, METH_VARARGS, + "Return True if psutil is in testing mode"}, + {"py_psutil_set_testing", py_psutil_set_testing, METH_VARARGS, + "Set psutil in testing mode"}, {NULL, NULL, 0, NULL} }; diff --git a/psutil/_psutil_sunos.c b/psutil/_psutil_sunos.c index 083b78cb..2abcd829 100644 --- a/psutil/_psutil_sunos.c +++ b/psutil/_psutil_sunos.c @@ -1592,8 +1592,10 @@ PsutilMethods[] = { "Return CPU statistics"}, // --- others - {"py_psutil_testing", py_psutil_testing, METH_VARARGS, - "Return True if PSUTIL_TESTING env var is set"}, + {"py_psutil_is_testing", py_psutil_is_testing, METH_VARARGS, + "Return True if psutil is in testing mode"}, + {"py_psutil_set_testing", py_psutil_set_testing, METH_VARARGS, + "Set psutil in testing mode"}, {NULL, NULL, 0, NULL} }; diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index 1d1fd939..e1110b53 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -3624,8 +3624,10 @@ PsutilMethods[] = { "QueryDosDevice binding"}, // --- others - {"py_psutil_testing", py_psutil_testing, METH_VARARGS, - "Return True if PSUTIL_TESTING env var is set"}, + {"py_psutil_is_testing", py_psutil_is_testing, METH_VARARGS, + "Return True if psutil is in testing mode"}, + {"py_psutil_set_testing", py_psutil_set_testing, METH_VARARGS, + "Set psutil in testing mode"}, {NULL, NULL, 0, NULL} }; diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index b94cfe6c..9f943d7a 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -755,8 +755,8 @@ unittest.TestCase = TestCase def _setup_tests(): if 'PSUTIL_TESTING' not in os.environ: os.environ['PSUTIL_TESTING'] = '1' # not guaranteed to work - if not psutil._psplatform.cext.py_psutil_testing(): - raise AssertionError('PSUTIL_TESTING env var is not set') + psutil._psplatform.cext.py_psutil_set_testing() + assert psutil._psplatform.cext.py_psutil_is_testing() def get_suite(): |