diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-04-24 11:59:43 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-04-24 11:59:43 +0200 |
commit | 29c3ecf99c9a205ab1147afc67a512cfd650622f (patch) | |
tree | 3cba4a515205f8148eb5d436caad2f62c8f1d857 | |
parent | 10d6950d9cd4c1fcc4b913c768a51f3a53bbac21 (diff) | |
download | psutil-29c3ecf99c9a205ab1147afc67a512cfd650622f.tar.gz |
rename vars
-rw-r--r-- | psutil/tests/__init__.py | 35 | ||||
-rwxr-xr-x | psutil/tests/test_process.py | 4 | ||||
-rwxr-xr-x | psutil/tests/test_unicode.py | 20 |
3 files changed, 27 insertions, 32 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index f3358806..dbc86ec6 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -73,7 +73,7 @@ else: __all__ = [ # constants 'APPVEYOR', 'DEVNULL', 'GLOBAL_TIMEOUT', 'MEMORY_TOLERANCE', 'NO_RETRIES', - 'PYPY', 'PYTHON_EXE', 'ROOT_DIR', 'SCRIPTS_DIR', 'TESTFILE_PREFIX', + 'PYPY', 'PYTHON_EXE', 'ROOT_DIR', 'SCRIPTS_DIR', 'TESTFN_PREFIX', 'TESTFN', 'TESTFN_UNICODE', 'TOX', 'TRAVIS', 'CIRRUS', 'CI_TESTING', 'VALID_PROC_STATUSES', "HAS_CPU_AFFINITY", "HAS_CPU_FREQ", "HAS_ENVIRON", "HAS_PROC_IO_COUNTERS", @@ -138,19 +138,22 @@ if TRAVIS or APPVEYOR: # --- files -TESTFILE_PREFIX = '$testfn' +# Disambiguate TESTFN for parallel testing. if os.name == 'java': # Jython disallows @ in module names - TESTFILE_PREFIX = '$psutil-test-' + TESTFN_PREFIX = '$psutil-test-%s-' % os.getpid() else: - TESTFILE_PREFIX = '@psutil-test-' -TESTFN = os.path.join(os.path.realpath(os.getcwd()), TESTFILE_PREFIX) -# Disambiguate TESTFN for parallel testing, while letting it remain a valid -# module name. -TESTFN = TESTFN + str(os.getpid()) + TESTFN_PREFIX = '@psutil-test-%s-' % os.getpid() +TESTFN = os.path.join(os.path.realpath(os.getcwd()), TESTFN_PREFIX) +TESTFN_UNICODE = TESTFN + u("-ƒőő") +# An invalid unicode string. +if PY3: + TESTFN_INVALID_UNICODE = (TESTFN.encode('utf8') + b"f\xc0\x80").decode( + 'utf8', 'surrogateescape') +else: + TESTFN_INVALID_UNICODE = TESTFN + "f\xc0\x80" _TESTFN = TESTFN + '-internal' -TESTFN_UNICODE = TESTFN + u("-ƒőő") ASCII_FS = sys.getfilesystemencoding().lower() in ('ascii', 'us-ascii') # --- paths @@ -227,9 +230,9 @@ def cleanup_test_files(): DEVNULL.close() for name in os.listdir(u('.')): if isinstance(name, unicode): - prefix = u(TESTFILE_PREFIX) + prefix = u(TESTFN_PREFIX) else: - prefix = TESTFILE_PREFIX + prefix = TESTFN_PREFIX if name.startswith(prefix): try: safe_rmpath(name) @@ -386,7 +389,7 @@ def create_proc_children_pair(): def create_zombie_proc(): """Create a zombie process and return its PID.""" assert psutil.POSIX - unix_file = tempfile.mktemp(prefix=TESTFILE_PREFIX) if MACOS else TESTFN + unix_file = tempfile.mktemp(prefix=TESTFN_PREFIX) if MACOS else TESTFN src = textwrap.dedent("""\ import os, sys, time, socket, contextlib child_pid = os.fork() @@ -428,7 +431,7 @@ def pyrun(src, **kwds): kwds.setdefault("stdout", None) kwds.setdefault("stderr", None) with tempfile.NamedTemporaryFile( - prefix=TESTFILE_PREFIX, mode="wt", delete=False) as f: + prefix=TESTFN_PREFIX, mode="wt", delete=False) as f: _testfiles_created.add(f.name) f.write(src) f.flush() @@ -787,7 +790,7 @@ def create_exe(outpath, c_code=None): os.chmod(outpath, st.st_mode | stat.S_IEXEC) -def unique_filename(prefix=TESTFILE_PREFIX, suffix=""): +def unique_filename(prefix=TESTFN_PREFIX, suffix=""): return tempfile.mktemp(prefix=prefix, suffix=suffix) @@ -1196,7 +1199,7 @@ def is_namedtuple(x): if POSIX: @contextlib.contextmanager - def copyload_shared_lib(dst_prefix=TESTFILE_PREFIX): + def copyload_shared_lib(dst_prefix=TESTFN_PREFIX): """Ctx manager which picks up a random shared CO lib used by this process, copies it in another location and loads it in memory via ctypes. Return the new absolutized path. @@ -1216,7 +1219,7 @@ if POSIX: safe_rmpath(dst) else: @contextlib.contextmanager - def copyload_shared_lib(dst_prefix=TESTFILE_PREFIX): + def copyload_shared_lib(dst_prefix=TESTFN_PREFIX): """Ctx manager which picks up a random shared DLL lib used by this process, copies it in another location and loads it in memory via ctypes. diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 987bdf38..6744b3ca 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -61,7 +61,7 @@ from psutil.tests import safe_rmpath from psutil.tests import sh from psutil.tests import skip_on_access_denied from psutil.tests import skip_on_not_implemented -from psutil.tests import TESTFILE_PREFIX +from psutil.tests import TESTFN_PREFIX from psutil.tests import TESTFN from psutil.tests import ThreadTask from psutil.tests import TRAVIS @@ -328,7 +328,7 @@ class TestProcess(unittest.TestCase): # test writes io1 = p.io_counters() - with tempfile.TemporaryFile(prefix=TESTFILE_PREFIX) as f: + with tempfile.TemporaryFile(prefix=TESTFN_PREFIX) as f: if PY3: f.write(bytes("x" * 1000000, 'ascii')) else: diff --git a/psutil/tests/test_unicode.py b/psutil/tests/test_unicode.py index ac2d4f69..c8a9ac31 100755 --- a/psutil/tests/test_unicode.py +++ b/psutil/tests/test_unicode.py @@ -101,8 +101,8 @@ from psutil.tests import reap_children from psutil.tests import safe_mkdir from psutil.tests import safe_rmpath as _safe_rmpath from psutil.tests import skip_on_access_denied -from psutil.tests import TESTFILE_PREFIX -from psutil.tests import TESTFN +from psutil.tests import TESTFN_INVALID_UNICODE +from psutil.tests import TESTFN_PREFIX from psutil.tests import TESTFN_UNICODE from psutil.tests import TRAVIS from psutil.tests import unittest @@ -148,14 +148,6 @@ def subprocess_supports_unicode(name): reap_children() -# An invalid unicode string. -if PY3: - INVALID_NAME = (TESTFN.encode('utf8') + b"f\xc0\x80").decode( - 'utf8', 'surrogateescape') -else: - INVALID_NAME = TESTFN + "f\xc0\x80" - - # =================================================================== # FS APIs # =================================================================== @@ -255,7 +247,7 @@ class _BaseFSAPIsTests(object): def test_net_connections(self): def find_sock(cons): for conn in cons: - if os.path.basename(conn.laddr).startswith(TESTFILE_PREFIX): + if os.path.basename(conn.laddr).startswith(TESTFN_PREFIX): return conn raise ValueError("connection not found") @@ -295,7 +287,7 @@ class _BaseFSAPIsTests(object): libpaths = [normpath(x.path) for x in psutil.Process().memory_maps()] # ...just to have a clearer msg in case of failure - libpaths = [x for x in libpaths if TESTFILE_PREFIX in x] + libpaths = [x for x in libpaths if TESTFN_PREFIX in x] self.assertIn(normpath(funky_path), libpaths) for path in libpaths: self.assertIsInstance(path, str) @@ -324,11 +316,11 @@ class TestFSAPIs(_BaseFSAPIsTests, unittest.TestCase): @unittest.skipIf(PYPY and TRAVIS, "unreliable on PYPY + TRAVIS") @unittest.skipIf(MACOS and TRAVIS, "unreliable on TRAVIS") # TODO @unittest.skipIf(PYPY, "unreliable on PYPY") -@unittest.skipIf(not subprocess_supports_unicode(INVALID_NAME), +@unittest.skipIf(not subprocess_supports_unicode(TESTFN_INVALID_UNICODE), "subprocess can't deal with invalid unicode") class TestFSAPIsWithInvalidPath(_BaseFSAPIsTests, unittest.TestCase): """Test FS APIs with a funky, invalid path name.""" - funky_name = INVALID_NAME + funky_name = TESTFN_INVALID_UNICODE @classmethod def expect_exact_path_match(cls): |