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

Method _assert_cwd

Lib/test/test_subprocess.py:431–448  ·  view source on GitHub ↗
(self, expected_cwd, python_arg, **kwargs)

Source from the content-addressed store, hash-verified

429
430 # For use in the test_cwd* tests below.
431 def _assert_cwd(self, expected_cwd, python_arg, **kwargs):
432 # Invoke Python via Popen, and assert that (1) the call succeeds,
433 # and that (2) the current working directory of the child process
434 # matches *expected_cwd*.
435 p = subprocess.Popen([python_arg, "-c",
436 "import os, sys; "
437 "buf = sys.stdout.buffer; "
438 "buf.write(os.getcwd().encode()); "
439 "buf.flush(); "
440 "sys.exit(47)"],
441 stdout=subprocess.PIPE,
442 **kwargs)
443 self.addCleanup(p.stdout.close)
444 p.wait()
445 self.assertEqual(47, p.returncode)
446 normcase = os.path.normcase
447 self.assertEqual(normcase(expected_cwd),
448 normcase(p.stdout.read().decode()))
449
450 def test_cwd(self):
451 # Check that cwd changes the cwd for the child process.

Calls 6

waitMethod · 0.95
addCleanupMethod · 0.80
normcaseFunction · 0.50
assertEqualMethod · 0.45
decodeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected