These changes released with importlib_metadata 7.2.0.
-import os
import sys
import copy
import json
import shutil
import pathlib
-import tempfile
import textwrap
import functools
import contextlib
@contextlib.contextmanager
-def tempdir():
- tmpdir = tempfile.mkdtemp()
- try:
- yield pathlib.Path(tmpdir)
- finally:
- shutil.rmtree(tmpdir)
-
-
-@contextlib.contextmanager
-def save_cwd():
- orig = os.getcwd()
- try:
- yield
- finally:
- os.chdir(orig)
-
-
-@contextlib.contextmanager
-def tempdir_as_cwd():
- with tempdir() as tmp:
- with save_cwd():
- os.chdir(str(tmp))
- yield tmp
+def tmp_path():
+ """
+ Like os_helper.temp_dir, but yields a pathlib.Path.
+ """
+ with os_helper.temp_dir() as path:
+ yield pathlib.Path(path)
@contextlib.contextmanager
class SiteDir(Fixtures):
def setUp(self):
super().setUp()
- self.site_dir = self.fixtures.enter_context(tempdir())
+ self.site_dir = self.fixtures.enter_context(tmp_path())
class OnSysPath(Fixtures):
Entry points should only be exposed for the first package
on sys.path with a given name (even when normalized).
"""
- alt_site_dir = self.fixtures.enter_context(fixtures.tempdir())
+ alt_site_dir = self.fixtures.enter_context(fixtures.tmp_path())
self.fixtures.enter_context(self.add_sys_path(alt_site_dir))
alt_pkg = {
"DistInfo_pkg-1.1.0.dist-info": {
fixtures.build_files(self.make_pkg('abc'), self.site_dir)
before = list(_unique(distributions()))
- alt_site_dir = self.fixtures.enter_context(fixtures.tempdir())
+ alt_site_dir = self.fixtures.enter_context(fixtures.tmp_path())
self.fixtures.enter_context(self.add_sys_path(alt_site_dir))
fixtures.build_files(self.make_pkg('ABC'), alt_site_dir)
after = list(_unique(distributions()))
--- /dev/null
+Cleaned up fixtures for importlib.metadata tests and consolidated behavior
+with 'test.support.os_helper'.