MCPcopy Index your code
hub / github.com/python/cpython / test_special_chars_bash

Method test_special_chars_bash

Lib/test/test_venv.py:503–525  ·  view source on GitHub ↗

Test that the template strings are quoted properly (bash)

(self)

Source from the content-addressed store, hash-verified

501 # gh-124651: test quoted strings
502 @unittest.skipIf(os.name == 'nt', 'contains invalid characters on Windows')
503 def test_special_chars_bash(self):
504 """
505 Test that the template strings are quoted properly (bash)
506 """
507 rmtree(self.env_dir)
508 bash = shutil.which('bash')
509 if bash is None:
510 self.skipTest('bash required for this test')
511 env_name = '"\';&&$e|\'"'
512 env_dir = os.path.join(os.path.realpath(self.env_dir), env_name)
513 builder = venv.EnvBuilder(clear=True)
514 builder.create(env_dir)
515 activate = os.path.join(env_dir, self.bindir, 'activate')
516 test_script = os.path.join(self.env_dir, 'test_special_chars.sh')
517 with open(test_script, "w") as f:
518 f.write(f'source {shlex.quote(activate)}\n'
519 'python -c \'import sys; print(sys.executable)\'\n'
520 'python -c \'import os; print(os.environ["VIRTUAL_ENV"])\'\n'
521 'deactivate\n')
522 out, err = check_output([bash, test_script])
523 lines = out.splitlines()
524 self.assertTrue(env_name.encode() in lines[0])
525 self.assertEndsWith(lines[1], env_name.encode())
526
527 # gh-124651: test quoted strings
528 @unittest.skipIf(os.name == 'nt', 'contains invalid characters on Windows')

Callers

nothing calls this directly

Calls 13

rmtreeFunction · 0.90
skipTestMethod · 0.80
quoteMethod · 0.80
assertTrueMethod · 0.80
assertEndsWithMethod · 0.80
check_outputFunction · 0.70
openFunction · 0.50
joinMethod · 0.45
realpathMethod · 0.45
createMethod · 0.45
writeMethod · 0.45
splitlinesMethod · 0.45

Tested by

no test coverage detected