mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
tests: add test.support.venv.VirtualEnvironmentMixin (#129461)
This commit is contained in:
parent
a549f43938
commit
a4722449ca
2 changed files with 14 additions and 9 deletions
|
@ -6,6 +6,7 @@ import shlex
|
||||||
import sys
|
import sys
|
||||||
import sysconfig
|
import sysconfig
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import unittest
|
||||||
import venv
|
import venv
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,3 +69,14 @@ class VirtualEnvironment:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class VirtualEnvironmentMixin:
|
||||||
|
def venv(self, name=None, **venv_create_args):
|
||||||
|
venv_name = self.id()
|
||||||
|
if name:
|
||||||
|
venv_name += f'-{name}'
|
||||||
|
return VirtualEnvironment.from_tmpdir(
|
||||||
|
prefix=f'{venv_name}-venv-',
|
||||||
|
**venv_create_args,
|
||||||
|
)
|
||||||
|
|
|
@ -20,7 +20,7 @@ from test.support import (
|
||||||
from test.support.import_helper import import_module
|
from test.support.import_helper import import_module
|
||||||
from test.support.os_helper import (TESTFN, unlink, skip_unless_symlink,
|
from test.support.os_helper import (TESTFN, unlink, skip_unless_symlink,
|
||||||
change_cwd)
|
change_cwd)
|
||||||
from test.support.venv import VirtualEnvironment
|
from test.support.venv import VirtualEnvironmentMixin
|
||||||
|
|
||||||
import sysconfig
|
import sysconfig
|
||||||
from sysconfig import (get_paths, get_platform, get_config_vars,
|
from sysconfig import (get_paths, get_platform, get_config_vars,
|
||||||
|
@ -37,7 +37,7 @@ import _sysconfig
|
||||||
HAS_USER_BASE = sysconfig._HAS_USER_BASE
|
HAS_USER_BASE = sysconfig._HAS_USER_BASE
|
||||||
|
|
||||||
|
|
||||||
class TestSysConfig(unittest.TestCase):
|
class TestSysConfig(unittest.TestCase, VirtualEnvironmentMixin):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestSysConfig, self).setUp()
|
super(TestSysConfig, self).setUp()
|
||||||
|
@ -111,13 +111,6 @@ class TestSysConfig(unittest.TestCase):
|
||||||
elif os.path.isdir(path):
|
elif os.path.isdir(path):
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
|
|
||||||
def venv(self, **venv_create_args):
|
|
||||||
return VirtualEnvironment.from_tmpdir(
|
|
||||||
prefix=f'{self.id()}-venv-',
|
|
||||||
**venv_create_args,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_path_names(self):
|
def test_get_path_names(self):
|
||||||
self.assertEqual(get_path_names(), sysconfig._SCHEME_KEYS)
|
self.assertEqual(get_path_names(), sysconfig._SCHEME_KEYS)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue