Skip to content

Commit 2ffb0ec

Browse files
author
Giampaolo Rodola
authored
Revert "Move tests out of package to top level directory (giampaolo#1232)" (giampaolo#1242)
This reverts commit b578d2f.
1 parent b578d2f commit 2ffb0ec

27 files changed

+331
-316
lines changed

.ci/travis/run.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ python setup.py develop
2020

2121
# run tests (with coverage)
2222
if [[ $PYVER == '2.7' ]] && [[ "$(uname -s)" != 'Darwin' ]]; then
23-
PSUTIL_TESTING=1 python -Wa -m coverage run tests/__main__.py
23+
PSUTIL_TESTING=1 python -Wa -m coverage run psutil/tests/__main__.py
2424
else
25-
PSUTIL_TESTING=1 python -Wa tests/__main__.py
25+
PSUTIL_TESTING=1 python -Wa psutil/tests/__main__.py
2626
fi
2727

2828
if [ "$PYVER" == "2.7" ] || [ "$PYVER" == "3.6" ]; then
2929
# run mem leaks test
30-
PSUTIL_TESTING=1 python -Wa tests/test_memory_leaks.py
30+
PSUTIL_TESTING=1 python -Wa psutil/tests/test_memory_leaks.py
3131
# run linter (on Linux only)
3232
if [[ "$(uname -s)" != 'Darwin' ]]; then
3333
python -m flake8

.coveragerc

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include =
44
*psutil*
55
omit =
66
psutil/_compat.py
7-
tests/*
7+
psutil/tests/*
88
setup.py
99
exclude_lines =
1010
enum.IntEnum

DEVGUIDE.rst

+8-7
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ Usually the files involved when adding a new functionality are:
9999
psutil/_ps{platform}.py # python platform wrapper
100100
psutil/_psutil_{platform}.c # C platform extension
101101
psutil/_psutil_{platform}.h # C header file
102-
tests/test_process|system.py # main test suite
103-
tests/test_{platform}.py # platform specific test suite
102+
psutil/tests/test_process|system.py # main test suite
103+
psutil/tests/test_{platform}.py # platform specific test suite
104104
105105
Typical process occurring when adding a new functionality (API):
106106

@@ -109,11 +109,12 @@ Typical process occurring when adding a new functionality (API):
109109
(e.g. ``psutil/_pslinux.py``).
110110
- if the change requires C, write the C implementation in
111111
``psutil/_psutil_{platform}.c`` (e.g. ``psutil/_psutil_linux.c``).
112-
- write a generic test in ``tests/test_system.py`` or
113-
``tests/test_process.py``.
114-
- if possible, write a platform specific test in ``tests/test_{platform}.py``
115-
(e.g. ``test_linux.py``). This usually means testing the return value of the
116-
new feature against a system CLI tool.
112+
- write a generic test in ``psutil/tests/test_system.py`` or
113+
``psutil/tests/test_process.py``.
114+
- if possible, write a platform specific test in
115+
``psutil/tests/test_{platform}.py`` (e.g. ``test_linux.py``).
116+
This usually means testing the return value of the new feature against
117+
a system CLI tool.
117118
- update doc in ``doc/index.py``.
118119
- update ``HISTORY.rst``.
119120
- update ``README.rst`` (if necessary).

MANIFEST.in

+17-17
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,23 @@ include psutil/arch/windows/security.c
7979
include psutil/arch/windows/security.h
8080
include psutil/arch/windows/services.c
8181
include psutil/arch/windows/services.h
82+
include psutil/tests/README.rst
83+
include psutil/tests/__init__.py
84+
include psutil/tests/__main__.py
85+
include psutil/tests/test_aix.py
86+
include psutil/tests/test_bsd.py
87+
include psutil/tests/test_connections.py
88+
include psutil/tests/test_contracts.py
89+
include psutil/tests/test_linux.py
90+
include psutil/tests/test_memory_leaks.py
91+
include psutil/tests/test_misc.py
92+
include psutil/tests/test_osx.py
93+
include psutil/tests/test_posix.py
94+
include psutil/tests/test_process.py
95+
include psutil/tests/test_sunos.py
96+
include psutil/tests/test_system.py
97+
include psutil/tests/test_unicode.py
98+
include psutil/tests/test_windows.py
8299
include scripts/battery.py
83100
include scripts/cpu_distribution.py
84101
include scripts/disk_usage.py
@@ -111,21 +128,4 @@ include scripts/top.py
111128
include scripts/who.py
112129
include scripts/winservices.py
113130
include setup.py
114-
include tests/README.rst
115-
include tests/__init__.py
116-
include tests/__main__.py
117-
include tests/test_aix.py
118-
include tests/test_bsd.py
119-
include tests/test_connections.py
120-
include tests/test_contracts.py
121-
include tests/test_linux.py
122-
include tests/test_memory_leaks.py
123-
include tests/test_misc.py
124-
include tests/test_osx.py
125-
include tests/test_posix.py
126-
include tests/test_process.py
127-
include tests/test_sunos.py
128-
include tests/test_system.py
129-
include tests/test_unicode.py
130-
include tests/test_windows.py
131131
include tox.ini

Makefile

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# You can set the variables below from the command line.
44

55
PYTHON = python
6-
TSCRIPT = tests/__main__.py
6+
TSCRIPT = psutil/tests/__main__.py
77
ARGS =
88
# List of nice-to-have dev libs.
99
DEPS = \
@@ -113,41 +113,41 @@ test: ## Run all tests.
113113

114114
test-process: ## Run process-related API tests.
115115
${MAKE} install
116-
$(TEST_PREFIX) $(PYTHON) -m unittest -v tests.test_process
116+
$(TEST_PREFIX) $(PYTHON) -m unittest -v psutil.tests.test_process
117117

118118
test-system: ## Run system-related API tests.
119119
${MAKE} install
120-
$(TEST_PREFIX) $(PYTHON) -m unittest -v tests.test_system
120+
$(TEST_PREFIX) $(PYTHON) -m unittest -v psutil.tests.test_system
121121

122122
test-misc: ## Run miscellaneous tests.
123123
${MAKE} install
124-
$(TEST_PREFIX) $(PYTHON) tests/test_misc.py
124+
$(TEST_PREFIX) $(PYTHON) psutil/tests/test_misc.py
125125

126126
test-unicode: ## Test APIs dealing with strings.
127127
${MAKE} install
128-
$(TEST_PREFIX) $(PYTHON) tests/test_unicode.py
128+
$(TEST_PREFIX) $(PYTHON) psutil/tests/test_unicode.py
129129

130130
test-contracts: ## APIs sanity tests.
131131
${MAKE} install
132-
$(TEST_PREFIX) $(PYTHON) tests/test_contracts.py
132+
$(TEST_PREFIX) $(PYTHON) psutil/tests/test_contracts.py
133133

134134
test-connections: ## Test net_connections() and Process.connections().
135135
${MAKE} install
136-
$(TEST_PREFIX) $(PYTHON) tests/test_connections.py
136+
$(TEST_PREFIX) $(PYTHON) psutil/tests/test_connections.py
137137

138138
test-posix: ## POSIX specific tests.
139139
${MAKE} install
140-
$(TEST_PREFIX) $(PYTHON) tests/test_posix.py
140+
$(TEST_PREFIX) $(PYTHON) psutil/tests/test_posix.py
141141

142142
test-platform: ## Run specific platform tests only.
143143
${MAKE} install
144-
$(TEST_PREFIX) $(PYTHON) tests/test_`$(PYTHON) -c 'import psutil; print([x.lower() for x in ("LINUX", "BSD", "OSX", "SUNOS", "WINDOWS", "AIX") if getattr(psutil, x)][0])'`.py
144+
$(TEST_PREFIX) $(PYTHON) psutil/tests/test_`$(PYTHON) -c 'import psutil; print([x.lower() for x in ("LINUX", "BSD", "OSX", "SUNOS", "WINDOWS", "AIX") if getattr(psutil, x)][0])'`.py
145145

146146
test-memleaks: ## Memory leak tests.
147147
${MAKE} install
148-
$(TEST_PREFIX) $(PYTHON) tests/test_memory_leaks.py
148+
$(TEST_PREFIX) $(PYTHON) psutil/tests/test_memory_leaks.py
149149

150-
test-by-name: ## e.g. make test-by-name ARGS=tests.test_system.TestSystemAPIs
150+
test-by-name: ## e.g. make test-by-name ARGS=psutil.tests.test_system.TestSystemAPIs
151151
${MAKE} install
152152
@$(TEST_PREFIX) $(PYTHON) -m unittest -v $(ARGS)
153153

appveyor.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ build: off
8383

8484
test_script:
8585
- "%WITH_COMPILER% %PYTHON%/python -V"
86-
- "set PYTHONWARNINGS=all && set PSUTIL_TESTING=1 && set PSUTIL_DEBUG=1 && %WITH_COMPILER% %PYTHON%/python tests/__main__.py"
86+
- "set PYTHONWARNINGS=all && set PSUTIL_TESTING=1 && set PSUTIL_DEBUG=1 && %WITH_COMPILER% %PYTHON%/python psutil/tests/__main__.py"
8787

8888
after_test:
8989
- "%WITH_COMPILER% %PYTHON%/python setup.py bdist_wheel"
@@ -112,12 +112,12 @@ only_commits:
112112
psutil/_psutil_windows.*
113113
psutil/_pswindows.py
114114
psutil/arch/windows/*
115-
tests/__init__.py
116-
tests/__main__.py
117-
tests/test_memory_leaks.py
118-
tests/test_misc.py
119-
tests/test_process.py
120-
tests/test_system.py
121-
tests/test_windows.py
115+
psutil/tests/__init__.py
116+
psutil/tests/__main__.py
117+
psutil/tests/test_memory_leaks.py
118+
psutil/tests/test_misc.py
119+
psutil/tests/test_process.py
120+
psutil/tests/test_system.py
121+
psutil/tests/test_windows.py
122122
scripts/*
123123
setup.py

docs/index.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -2605,7 +2605,12 @@ FAQs
26052605
Running tests
26062606
=============
26072607

2608-
First, obtain a copy of the source code. Then run tests using the command::
2608+
There are two ways of running tests. If psutil is already installed use::
2609+
2610+
$ python -m psutil.tests
2611+
2612+
You can use this method as a quick way to make sure psutil fully works on your
2613+
platform. If you have a copy of the source code you can also use::
26092614

26102615
$ make test
26112616

tests/README.rst psutil/tests/README.rst

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
Instructions for running tests
22
==============================
33

4-
* To run tests::
4+
* There are two ways of running tests. As a "user", if psutil is already
5+
installed and you just want to test it works::
6+
7+
python -m psutil.tests --install-deps # install test deps
8+
python -m psutil.tests
9+
10+
As a "developer", if you have a copy of the source code and you whish to hack
11+
on psutil::
512

613
make setup-dev-env # install test deps (+ other things)
714
make test

tests/__init__.py psutil/tests/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142

143143
# --- paths
144144

145-
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
145+
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
146146
SCRIPTS_DIR = os.path.join(ROOT_DIR, 'scripts')
147147
HERE = os.path.abspath(os.path.dirname(__file__))
148148

@@ -788,7 +788,7 @@ def get_suite():
788788
suite = unittest.TestSuite()
789789
for tm in testmods:
790790
# ...so that the full test paths are printed on screen
791-
tm = "tests.%s" % tm
791+
tm = "psutil.tests.%s" % tm
792792
suite.addTest(unittest.defaultTestLoader.loadTestsFromName(tm))
793793
return suite
794794

tests/__main__.py psutil/tests/__main__.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
# found in the LICENSE file.
66

77
"""
8-
Run unit tests.
8+
Run unit tests. This is invoked by:
9+
10+
$ python -m psutil.tests
911
"""
1012

1113
import contextlib
@@ -19,8 +21,8 @@
1921
except ImportError:
2022
from urllib2 import urlopen
2123

22-
from tests import PYTHON_EXE
23-
from tests import run_suite
24+
from psutil.tests import PYTHON_EXE
25+
from psutil.tests import run_suite
2426

2527

2628
HERE = os.path.abspath(os.path.dirname(__file__))
@@ -69,7 +71,7 @@ def install_test_deps(deps=None):
6971

7072

7173
def main():
72-
usage = "%s -m tests [opts]" % PYTHON_EXE
74+
usage = "%s -m psutil.tests [opts]" % PYTHON_EXE
7375
parser = optparse.OptionParser(usage=usage, description="run unit tests")
7476
parser.add_option("-i", "--install-deps",
7577
action="store_true", default=False,
@@ -84,7 +86,7 @@ def main():
8486
try:
8587
__import__(dep.split("==")[0])
8688
except ImportError:
87-
sys.exit("%r lib is not installed; run %s -m tests "
89+
sys.exit("%r lib is not installed; run %s -m psutil.tests "
8890
"--install-deps" % (dep, PYTHON_EXE))
8991
run_suite()
9092

tests/test_aix.py psutil/tests/test_aix.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import re
1212

1313
from psutil import AIX
14-
from tests import run_test_module_by_name
15-
from tests import sh
16-
from tests import unittest
14+
from psutil.tests import run_test_module_by_name
15+
from psutil.tests import sh
16+
from psutil.tests import unittest
1717
import psutil
1818

1919

@@ -38,9 +38,9 @@ def test_virtual_memory(self):
3838

3939
psutil_result = psutil.virtual_memory()
4040

41-
# MEMORY_TOLERANCE from tests is not enough. For some reason we're
42-
# seeing differences of ~1.2 MB. 2 MB is still a good tolerance when
43-
# compared to GBs.
41+
# MEMORY_TOLERANCE from psutil.tests is not enough. For some reason
42+
# we're seeing differences of ~1.2 MB. 2 MB is still a good tolerance
43+
# when compared to GBs.
4444
MEMORY_TOLERANCE = 2 * KB * KB # 2 MB
4545
self.assertEqual(psutil_result.total, total)
4646
self.assertAlmostEqual(

tests/test_bsd.py psutil/tests/test_bsd.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
from psutil import FREEBSD
2121
from psutil import NETBSD
2222
from psutil import OPENBSD
23-
from tests import get_test_subprocess
24-
from tests import HAS_BATTERY
25-
from tests import MEMORY_TOLERANCE
26-
from tests import reap_children
27-
from tests import retry_before_failing
28-
from tests import run_test_module_by_name
29-
from tests import sh
30-
from tests import unittest
31-
from tests import which
23+
from psutil.tests import get_test_subprocess
24+
from psutil.tests import HAS_BATTERY
25+
from psutil.tests import MEMORY_TOLERANCE
26+
from psutil.tests import reap_children
27+
from psutil.tests import retry_before_failing
28+
from psutil.tests import run_test_module_by_name
29+
from psutil.tests import sh
30+
from psutil.tests import unittest
31+
from psutil.tests import which
3232

3333

3434
if BSD:

tests/test_connections.py psutil/tests/test_connections.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@
2626
from psutil import WINDOWS
2727
from psutil._common import supports_ipv6
2828
from psutil._compat import PY3
29-
from tests import AF_UNIX
30-
from tests import bind_socket
31-
from tests import bind_unix_socket
32-
from tests import check_connection_ntuple
33-
from tests import create_sockets
34-
from tests import get_free_port
35-
from tests import HAS_CONNECTIONS_UNIX
36-
from tests import pyrun
37-
from tests import reap_children
38-
from tests import run_test_module_by_name
39-
from tests import safe_rmpath
40-
from tests import skip_on_access_denied
41-
from tests import tcp_socketpair
42-
from tests import TESTFN
43-
from tests import TRAVIS
44-
from tests import unittest
45-
from tests import unix_socket_path
46-
from tests import unix_socketpair
47-
from tests import wait_for_file
29+
from psutil.tests import AF_UNIX
30+
from psutil.tests import bind_socket
31+
from psutil.tests import bind_unix_socket
32+
from psutil.tests import check_connection_ntuple
33+
from psutil.tests import create_sockets
34+
from psutil.tests import get_free_port
35+
from psutil.tests import HAS_CONNECTIONS_UNIX
36+
from psutil.tests import pyrun
37+
from psutil.tests import reap_children
38+
from psutil.tests import run_test_module_by_name
39+
from psutil.tests import safe_rmpath
40+
from psutil.tests import skip_on_access_denied
41+
from psutil.tests import tcp_socketpair
42+
from psutil.tests import TESTFN
43+
from psutil.tests import TRAVIS
44+
from psutil.tests import unittest
45+
from psutil.tests import unix_socket_path
46+
from psutil.tests import unix_socketpair
47+
from psutil.tests import wait_for_file
4848

4949

5050
thisproc = psutil.Process()
@@ -471,7 +471,7 @@ def test_multi_sockets_procs(self):
471471
fname = os.path.realpath(TESTFN) + str(i)
472472
src = textwrap.dedent("""\
473473
import time, os
474-
from tests import create_sockets
474+
from psutil.tests import create_sockets
475475
with create_sockets():
476476
with open('%s', 'w') as f:
477477
f.write(str(os.getpid()))

0 commit comments

Comments
 (0)