Victor Stinner diagnosed on #12167 that some reference leaks came from
util._path_created, a set used for caching; there are two tests that
cause additions to this set, so now they clear it in tearDown, avoiding
17 refleaks. (My tests show that it’s necessary to clear the set in
only one test, clearing it in both does not stop more refleaks, but
there’s no harm in doing it.)
It is not possible to unload a module written in C, so use a subprocess to run
the tests on the module compiled by test_build_ext(). Using a subprocess, we
don't have to unload the module, save/restore sys.path, and the test can be run
more than once.
This commit fixes also an access error on rmtree() on Windows: because the
module was not really unloaded, it was not possible to remove the temporary
directory (it is not possible to remove a directory on Windows if it still
contains an open file).
- Use different Metadata objects to write and read a PKG-INFO (METADATA)
file, to make sure the tested values come from the file
- No need to restore methods on an instance after monkey-patching them:
the methods are still the same on the class
- Harmonize dedent calls
packaging.tests.support.TempdirManager: removing the current directory is not
allowed on Windows or Solaris. Store the current directory and restore it
before removing the temporary directory (which is used as the working directory
during the tests).
The two public functions in database default to sys.path if the given
*paths* argument is None; the private functions don’t have default
values for their arguments anymore, which is fine as the public
functions that call them pass their arguments down. Likewise in
install, the functions will pass down their *paths* arguments down to
database functions.
A one-line unneeded function in install was removed instead of being
changed, and the few remaining tests that used brute-force restoration
of sys.path have been cleaned up to use sys.path.remove.
packaging.util.check_environ will define HOME and PLAT if they don’t exist; for
some reason, it does not define PLAT when running the tests from a checkout (so
no regrtest warning) but does when running from an installed Python.
Cleaning up the envvar in test_dist fixes the warning on my machine, but I
suspect that a test runner using a different order to run files or running them
in parallel may have PLAT defined in its environment because of another test.
Quite a lot of code ends up calling check_environ; maybe we should just clean
up PLAT in every test. For now I’m doing this simple fix, we’ll see if we get
bug reports.
The code does not write checksum or file length for .pyc and .pyo in the RECORD
file, in compliance with PEP 376, but the test forgot to take .pyo into
account. This was not caught because there were no .pyo in the checkout, but
after installing there are .pyo files created by compileall, and the test picks
them up.
The example C extension used the “three.fast_taunt” name, but no “three” parent
was defined in the setup.cfg. This did not cause a failure nor even print a
warning, we may want to change that.
I’m afraid my docstring is not as clear as it should be, but I can’t
find a concise way of describing what the code does. Suggestions for
improvements welcome.
wrap_text was removed in favor of standard textwrap but the removal of the
function was lost in a bad merge; a change in sdist mysteriously disappeared.
This change also makes sure the logger handlers are not alterated after an
installation. That also fixes the remaining environment alteration issue in
test_packaging.