Skip to content

Commit

Permalink
Revert "Move tests out of package to top level directory (#1232)" (#1242
Browse files Browse the repository at this point in the history
)

This reverts commit b578d2f.
  • Loading branch information
giampaolo authored Mar 11, 2018
1 parent b578d2f commit 2ffb0ec
Show file tree
Hide file tree
Showing 27 changed files with 331 additions and 316 deletions.
6 changes: 3 additions & 3 deletions .ci/travis/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ python setup.py develop

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

if [ "$PYVER" == "2.7" ] || [ "$PYVER" == "3.6" ]; then
# run mem leaks test
PSUTIL_TESTING=1 python -Wa tests/test_memory_leaks.py
PSUTIL_TESTING=1 python -Wa psutil/tests/test_memory_leaks.py
# run linter (on Linux only)
if [[ "$(uname -s)" != 'Darwin' ]]; then
python -m flake8
Expand Down
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include =
*psutil*
omit =
psutil/_compat.py
tests/*
psutil/tests/*
setup.py
exclude_lines =
enum.IntEnum
Expand Down
15 changes: 8 additions & 7 deletions DEVGUIDE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ Usually the files involved when adding a new functionality are:
psutil/_ps{platform}.py # python platform wrapper
psutil/_psutil_{platform}.c # C platform extension
psutil/_psutil_{platform}.h # C header file
tests/test_process|system.py # main test suite
tests/test_{platform}.py # platform specific test suite
psutil/tests/test_process|system.py # main test suite
psutil/tests/test_{platform}.py # platform specific test suite
Typical process occurring when adding a new functionality (API):

Expand All @@ -109,11 +109,12 @@ Typical process occurring when adding a new functionality (API):
(e.g. ``psutil/_pslinux.py``).
- if the change requires C, write the C implementation in
``psutil/_psutil_{platform}.c`` (e.g. ``psutil/_psutil_linux.c``).
- write a generic test in ``tests/test_system.py`` or
``tests/test_process.py``.
- if possible, write a platform specific test in ``tests/test_{platform}.py``
(e.g. ``test_linux.py``). This usually means testing the return value of the
new feature against a system CLI tool.
- write a generic test in ``psutil/tests/test_system.py`` or
``psutil/tests/test_process.py``.
- if possible, write a platform specific test in
``psutil/tests/test_{platform}.py`` (e.g. ``test_linux.py``).
This usually means testing the return value of the new feature against
a system CLI tool.
- update doc in ``doc/index.py``.
- update ``HISTORY.rst``.
- update ``README.rst`` (if necessary).
Expand Down
34 changes: 17 additions & 17 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ include psutil/arch/windows/security.c
include psutil/arch/windows/security.h
include psutil/arch/windows/services.c
include psutil/arch/windows/services.h
include psutil/tests/README.rst
include psutil/tests/__init__.py
include psutil/tests/__main__.py
include psutil/tests/test_aix.py
include psutil/tests/test_bsd.py
include psutil/tests/test_connections.py
include psutil/tests/test_contracts.py
include psutil/tests/test_linux.py
include psutil/tests/test_memory_leaks.py
include psutil/tests/test_misc.py
include psutil/tests/test_osx.py
include psutil/tests/test_posix.py
include psutil/tests/test_process.py
include psutil/tests/test_sunos.py
include psutil/tests/test_system.py
include psutil/tests/test_unicode.py
include psutil/tests/test_windows.py
include scripts/battery.py
include scripts/cpu_distribution.py
include scripts/disk_usage.py
Expand Down Expand Up @@ -111,21 +128,4 @@ include scripts/top.py
include scripts/who.py
include scripts/winservices.py
include setup.py
include tests/README.rst
include tests/__init__.py
include tests/__main__.py
include tests/test_aix.py
include tests/test_bsd.py
include tests/test_connections.py
include tests/test_contracts.py
include tests/test_linux.py
include tests/test_memory_leaks.py
include tests/test_misc.py
include tests/test_osx.py
include tests/test_posix.py
include tests/test_process.py
include tests/test_sunos.py
include tests/test_system.py
include tests/test_unicode.py
include tests/test_windows.py
include tox.ini
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# You can set the variables below from the command line.

PYTHON = python
TSCRIPT = tests/__main__.py
TSCRIPT = psutil/tests/__main__.py
ARGS =
# List of nice-to-have dev libs.
DEPS = \
Expand Down Expand Up @@ -113,41 +113,41 @@ test: ## Run all tests.

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

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

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

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

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

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

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

test-platform: ## Run specific platform tests only.
${MAKE} install
$(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
$(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

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

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

Expand Down
16 changes: 8 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ build: off

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

after_test:
- "%WITH_COMPILER% %PYTHON%/python setup.py bdist_wheel"
Expand Down Expand Up @@ -112,12 +112,12 @@ only_commits:
psutil/_psutil_windows.*
psutil/_pswindows.py
psutil/arch/windows/*
tests/__init__.py
tests/__main__.py
tests/test_memory_leaks.py
tests/test_misc.py
tests/test_process.py
tests/test_system.py
tests/test_windows.py
psutil/tests/__init__.py
psutil/tests/__main__.py
psutil/tests/test_memory_leaks.py
psutil/tests/test_misc.py
psutil/tests/test_process.py
psutil/tests/test_system.py
psutil/tests/test_windows.py
scripts/*
setup.py
7 changes: 6 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2605,7 +2605,12 @@ FAQs
Running tests
=============

First, obtain a copy of the source code. Then run tests using the command::
There are two ways of running tests. If psutil is already installed use::

$ python -m psutil.tests

You can use this method as a quick way to make sure psutil fully works on your
platform. If you have a copy of the source code you can also use::

$ make test

Expand Down
9 changes: 8 additions & 1 deletion tests/README.rst → psutil/tests/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
Instructions for running tests
==============================

* To run tests::
* There are two ways of running tests. As a "user", if psutil is already
installed and you just want to test it works::

python -m psutil.tests --install-deps # install test deps
python -m psutil.tests

As a "developer", if you have a copy of the source code and you whish to hack
on psutil::

make setup-dev-env # install test deps (+ other things)
make test
Expand Down
4 changes: 2 additions & 2 deletions tests/__init__.py → psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@

# --- paths

ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
SCRIPTS_DIR = os.path.join(ROOT_DIR, 'scripts')
HERE = os.path.abspath(os.path.dirname(__file__))

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

Expand Down
12 changes: 7 additions & 5 deletions tests/__main__.py → psutil/tests/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
# found in the LICENSE file.

"""
Run unit tests.
Run unit tests. This is invoked by:
$ python -m psutil.tests
"""

import contextlib
Expand All @@ -19,8 +21,8 @@
except ImportError:
from urllib2 import urlopen

from tests import PYTHON_EXE
from tests import run_suite
from psutil.tests import PYTHON_EXE
from psutil.tests import run_suite


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


def main():
usage = "%s -m tests [opts]" % PYTHON_EXE
usage = "%s -m psutil.tests [opts]" % PYTHON_EXE
parser = optparse.OptionParser(usage=usage, description="run unit tests")
parser.add_option("-i", "--install-deps",
action="store_true", default=False,
Expand All @@ -84,7 +86,7 @@ def main():
try:
__import__(dep.split("==")[0])
except ImportError:
sys.exit("%r lib is not installed; run %s -m tests "
sys.exit("%r lib is not installed; run %s -m psutil.tests "
"--install-deps" % (dep, PYTHON_EXE))
run_suite()

Expand Down
12 changes: 6 additions & 6 deletions tests/test_aix.py → psutil/tests/test_aix.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import re

from psutil import AIX
from tests import run_test_module_by_name
from tests import sh
from tests import unittest
from psutil.tests import run_test_module_by_name
from psutil.tests import sh
from psutil.tests import unittest
import psutil


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

psutil_result = psutil.virtual_memory()

# MEMORY_TOLERANCE from tests is not enough. For some reason we're
# seeing differences of ~1.2 MB. 2 MB is still a good tolerance when
# compared to GBs.
# MEMORY_TOLERANCE from psutil.tests is not enough. For some reason
# we're seeing differences of ~1.2 MB. 2 MB is still a good tolerance
# when compared to GBs.
MEMORY_TOLERANCE = 2 * KB * KB # 2 MB
self.assertEqual(psutil_result.total, total)
self.assertAlmostEqual(
Expand Down
18 changes: 9 additions & 9 deletions tests/test_bsd.py → psutil/tests/test_bsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
from psutil import FREEBSD
from psutil import NETBSD
from psutil import OPENBSD
from tests import get_test_subprocess
from tests import HAS_BATTERY
from tests import MEMORY_TOLERANCE
from tests import reap_children
from tests import retry_before_failing
from tests import run_test_module_by_name
from tests import sh
from tests import unittest
from tests import which
from psutil.tests import get_test_subprocess
from psutil.tests import HAS_BATTERY
from psutil.tests import MEMORY_TOLERANCE
from psutil.tests import reap_children
from psutil.tests import retry_before_failing
from psutil.tests import run_test_module_by_name
from psutil.tests import sh
from psutil.tests import unittest
from psutil.tests import which


if BSD:
Expand Down
40 changes: 20 additions & 20 deletions tests/test_connections.py → psutil/tests/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@
from psutil import WINDOWS
from psutil._common import supports_ipv6
from psutil._compat import PY3
from tests import AF_UNIX
from tests import bind_socket
from tests import bind_unix_socket
from tests import check_connection_ntuple
from tests import create_sockets
from tests import get_free_port
from tests import HAS_CONNECTIONS_UNIX
from tests import pyrun
from tests import reap_children
from tests import run_test_module_by_name
from tests import safe_rmpath
from tests import skip_on_access_denied
from tests import tcp_socketpair
from tests import TESTFN
from tests import TRAVIS
from tests import unittest
from tests import unix_socket_path
from tests import unix_socketpair
from tests import wait_for_file
from psutil.tests import AF_UNIX
from psutil.tests import bind_socket
from psutil.tests import bind_unix_socket
from psutil.tests import check_connection_ntuple
from psutil.tests import create_sockets
from psutil.tests import get_free_port
from psutil.tests import HAS_CONNECTIONS_UNIX
from psutil.tests import pyrun
from psutil.tests import reap_children
from psutil.tests import run_test_module_by_name
from psutil.tests import safe_rmpath
from psutil.tests import skip_on_access_denied
from psutil.tests import tcp_socketpair
from psutil.tests import TESTFN
from psutil.tests import TRAVIS
from psutil.tests import unittest
from psutil.tests import unix_socket_path
from psutil.tests import unix_socketpair
from psutil.tests import wait_for_file


thisproc = psutil.Process()
Expand Down Expand Up @@ -471,7 +471,7 @@ def test_multi_sockets_procs(self):
fname = os.path.realpath(TESTFN) + str(i)
src = textwrap.dedent("""\
import time, os
from tests import create_sockets
from psutil.tests import create_sockets
with create_sockets():
with open('%s', 'w') as f:
f.write(str(os.getpid()))
Expand Down
Loading

0 comments on commit 2ffb0ec

Please sign in to comment.