mirror of
https://github.com/python/cpython.git
synced 2024-11-24 18:34:43 +08:00
bpo-37885: venv: Don't produce unbound variable warning on deactivate (GH-15330)
Before, running deactivate from a bash shell configured to treat undefined variables as errors (`set -u`) would produce a warning: ``` $ python3 -m venv test $ source test/bin/activate (test) $ deactivate -bash: $1: unbound variable ```
This commit is contained in:
parent
3b58a70d9c
commit
5209e586b7
@ -9,6 +9,7 @@ import ensurepip
|
|||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
import struct
|
import struct
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@ -360,6 +361,25 @@ class BasicTest(BaseTest):
|
|||||||
'pool.terminate()'])
|
'pool.terminate()'])
|
||||||
self.assertEqual(out.strip(), "python".encode())
|
self.assertEqual(out.strip(), "python".encode())
|
||||||
|
|
||||||
|
@unittest.skipIf(os.name == 'nt', 'not relevant on Windows')
|
||||||
|
def test_deactivate_with_strict_bash_opts(self):
|
||||||
|
bash = shutil.which("bash")
|
||||||
|
if bash is None:
|
||||||
|
self.skipTest("bash required for this test")
|
||||||
|
rmtree(self.env_dir)
|
||||||
|
builder = venv.EnvBuilder(clear=True)
|
||||||
|
builder.create(self.env_dir)
|
||||||
|
activate = os.path.join(self.env_dir, self.bindir, "activate")
|
||||||
|
test_script = os.path.join(self.env_dir, "test_strict.sh")
|
||||||
|
with open(test_script, "w") as f:
|
||||||
|
f.write("set -euo pipefail\n"
|
||||||
|
f"source {activate}\n"
|
||||||
|
"deactivate\n")
|
||||||
|
out, err = check_output([bash, test_script])
|
||||||
|
self.assertEqual(out, "".encode())
|
||||||
|
self.assertEqual(err, "".encode())
|
||||||
|
|
||||||
|
|
||||||
@requireVenvCreate
|
@requireVenvCreate
|
||||||
class EnsurePipTest(BaseTest):
|
class EnsurePipTest(BaseTest):
|
||||||
"""Test venv module installation of pip."""
|
"""Test venv module installation of pip."""
|
||||||
|
@ -28,7 +28,7 @@ deactivate () {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
unset VIRTUAL_ENV
|
unset VIRTUAL_ENV
|
||||||
if [ ! "$1" = "nondestructive" ] ; then
|
if [ ! "${1:-}" = "nondestructive" ] ; then
|
||||||
# Self destruct!
|
# Self destruct!
|
||||||
unset -f deactivate
|
unset -f deactivate
|
||||||
fi
|
fi
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
venv: Don't generate unset variable warning on deactivate.
|
Loading…
Reference in New Issue
Block a user