summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorDavid Foster <david@dafoster.net>2022-05-19 14:47:16 (GMT)
committerGitHub <noreply@github.com>2022-05-19 14:47:16 (GMT)
commit30deeac64925effe46cb5f1cd091ccb4c850ce83 (patch)
tree14679d94703b68cd29fe7bed4f6de51ce5777c65 /Lib
parent6b51773afd5658e15d23ce220f66fcc39c02dcae (diff)
downloadcpython-30deeac64925effe46cb5f1cd091ccb4c850ce83.zip
cpython-30deeac64925effe46cb5f1cd091ccb4c850ce83.tar.gz
cpython-30deeac64925effe46cb5f1cd091ccb4c850ce83.tar.bz2
gh-92675: venv: Fix ensure_directories() to again accept a Path for env_dir (#92676)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_venv.py20
-rw-r--r--Lib/venv/__init__.py2
2 files changed, 18 insertions, 4 deletions
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
index 9f2ecf3..37b61a7 100644
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -8,6 +8,7 @@ Licensed to the PSF under a contributor agreement.
import ensurepip
import os
import os.path
+import pathlib
import re
import shutil
import struct
@@ -99,12 +100,23 @@ class BasicTest(BaseTest):
fn = self.get_env_file(*args)
self.assertTrue(os.path.isdir(fn))
- def test_defaults(self):
+ def test_defaults_with_str_path(self):
"""
- Test the create function with default arguments.
+ Test the create function with default arguments and a str path.
"""
rmtree(self.env_dir)
self.run_with_capture(venv.create, self.env_dir)
+ self._check_output_of_default_create()
+
+ def test_defaults_with_pathlib_path(self):
+ """
+ Test the create function with default arguments and a pathlib.Path path.
+ """
+ rmtree(self.env_dir)
+ self.run_with_capture(venv.create, pathlib.Path(self.env_dir))
+ self._check_output_of_default_create()
+
+ def _check_output_of_default_create(self):
self.isdir(self.bindir)
self.isdir(self.include)
self.isdir(*self.lib)
@@ -474,7 +486,9 @@ class BasicTest(BaseTest):
the path separator.
"""
rmtree(self.env_dir)
- self.assertRaises(ValueError, venv.create, self.env_dir + os.pathsep)
+ bad_itempath = self.env_dir + os.pathsep
+ self.assertRaises(ValueError, venv.create, bad_itempath)
+ self.assertRaises(ValueError, venv.create, pathlib.Path(bad_itempath))
@requireVenvCreate
class EnsurePipTest(BaseTest):
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py
index 7bfbadd..6032f36 100644
--- a/Lib/venv/__init__.py
+++ b/Lib/venv/__init__.py
@@ -116,7 +116,7 @@ class EnvBuilder:
elif os.path.islink(d) or os.path.isfile(d):
raise ValueError('Unable to create directory %r' % d)
- if os.pathsep in env_dir:
+ if os.pathsep in os.fspath(env_dir):
raise ValueError(f'Refusing to create a venv in {env_dir} because '
f'it contains the PATH separator {os.pathsep}.')
if os.path.exists(env_dir) and self.clear: