Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions
test.test_subprocess.Win32ProcessTestCase Class Reference
Inheritance diagram for test.test_subprocess.Win32ProcessTestCase:
Inheritance graph
[legend]
Collaboration diagram for test.test_subprocess.Win32ProcessTestCase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_startupinfo
def test_creationflags
def test_invalid_args
def test_close_fds
def test_shell_sequence
def test_shell_string
def test_call_string
def test_send_signal
def test_kill
def test_terminate
def setUp
def tearDown
def assertStderrEqual

Private Member Functions

def _kill_process

Detailed Description

Definition at line 1399 of file test_subprocess.py.


Member Function Documentation

def test.test_subprocess.Win32ProcessTestCase._kill_process (   self,
  method,
  args 
) [private]

Definition at line 1469 of file test_subprocess.py.

01469 
01470     def _kill_process(self, method, *args):
01471         # Some win32 buildbot raises EOFError if stdin is inherited
01472         p = subprocess.Popen([sys.executable, "-c", """if 1:
01473                              import sys, time
01474                              sys.stdout.write('x\\n')
01475                              sys.stdout.flush()
01476                              time.sleep(30)
01477                              """],
01478                              stdin=subprocess.PIPE,
01479                              stdout=subprocess.PIPE,
01480                              stderr=subprocess.PIPE)
01481         self.addCleanup(p.stdout.close)
01482         self.addCleanup(p.stderr.close)
01483         self.addCleanup(p.stdin.close)
01484         # Wait for the interpreter to be completely initialized before
01485         # sending any signal.
01486         p.stdout.read(1)
01487         getattr(p, method)(*args)
01488         _, stderr = p.communicate()
01489         self.assertStderrEqual(stderr, b'')
01490         returncode = p.wait()
01491         self.assertNotEqual(returncode, 0)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_subprocess.BaseTestCase.assertStderrEqual (   self,
  stderr,
  expected,
  msg = None 
) [inherited]

Definition at line 56 of file test_subprocess.py.

00056 
00057     def assertStderrEqual(self, stderr, expected, msg=None):
00058         # In a debug build, stuff like "[6580 refs]" is printed to stderr at
00059         # shutdown time.  That frustrates tests trying to check stderr produced
00060         # from a spawned Python process.
00061         actual = support.strip_python_stderr(stderr)
00062         self.assertEqual(actual, expected, msg)
00063 

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_subprocess.BaseTestCase.setUp (   self) [inherited]

Reimplemented in test.test_subprocess.CommandsWithSpaces, and test.test_subprocess.ProcessTestCaseNoPoll.

Definition at line 45 of file test_subprocess.py.

00045 
00046     def setUp(self):
00047         # Try to minimize the number of children we have so this test
00048         # doesn't crash on some buildbots (Alphas in particular).
00049         support.reap_children()

Here is the caller graph for this function:

def test.test_subprocess.BaseTestCase.tearDown (   self) [inherited]

Reimplemented in test.test_subprocess.CommandsWithSpaces, and test.test_subprocess.ProcessTestCaseNoPoll.

Definition at line 50 of file test_subprocess.py.

00050 
00051     def tearDown(self):
00052         for inst in subprocess._active:
00053             inst.wait()
00054         subprocess._cleanup()
00055         self.assertFalse(subprocess._active, "subprocess._active not empty")

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1463 of file test_subprocess.py.

01463 
01464     def test_call_string(self):
01465         # call() function with string argument on Windows
01466         rc = subprocess.call(sys.executable +
01467                              ' -c "import sys; sys.exit(47)"')
01468         self.assertEqual(rc, 47)

Here is the call graph for this function:

Definition at line 1436 of file test_subprocess.py.

01436 
01437     def test_close_fds(self):
01438         # close file descriptors
01439         rc = subprocess.call([sys.executable, "-c",
01440                               "import sys; sys.exit(47)"],
01441                               close_fds=True)
01442         self.assertEqual(rc, 47)

Here is the call graph for this function:

Definition at line 1416 of file test_subprocess.py.

01416 
01417     def test_creationflags(self):
01418         # creationflags argument
01419         CREATE_NEW_CONSOLE = 16
01420         sys.stderr.write("    a DOS box should flash briefly ...\n")
01421         subprocess.call(sys.executable +
01422                         ' -c "import time; time.sleep(0.25)"',
01423                         creationflags=CREATE_NEW_CONSOLE)

Here is the call graph for this function:

Definition at line 1424 of file test_subprocess.py.

01424 
01425     def test_invalid_args(self):
01426         # invalid arguments should raise ValueError
01427         self.assertRaises(ValueError, subprocess.call,
01428                           [sys.executable, "-c",
01429                            "import sys; sys.exit(47)"],
01430                           preexec_fn=lambda: 1)
01431         self.assertRaises(ValueError, subprocess.call,
01432                           [sys.executable, "-c",
01433                            "import sys; sys.exit(47)"],
01434                           stdout=subprocess.PIPE,
01435                           close_fds=True)

Here is the call graph for this function:

Definition at line 1495 of file test_subprocess.py.

01495 
01496     def test_kill(self):
01497         self._kill_process('kill')

Here is the call graph for this function:

Definition at line 1492 of file test_subprocess.py.

01492 
01493     def test_send_signal(self):
01494         self._kill_process('send_signal', signal.SIGTERM)

Here is the call graph for this function:

Definition at line 1443 of file test_subprocess.py.

01443 
01444     def test_shell_sequence(self):
01445         # Run command through the shell (sequence)
01446         newenv = os.environ.copy()
01447         newenv["FRUIT"] = "physalis"
01448         p = subprocess.Popen(["set"], shell=1,
01449                              stdout=subprocess.PIPE,
01450                              env=newenv)
01451         self.addCleanup(p.stdout.close)
01452         self.assertIn(b"physalis", p.stdout.read())

Here is the call graph for this function:

Definition at line 1453 of file test_subprocess.py.

01453 
01454     def test_shell_string(self):
01455         # Run command through the shell (string)
01456         newenv = os.environ.copy()
01457         newenv["FRUIT"] = "physalis"
01458         p = subprocess.Popen("set", shell=1,
01459                              stdout=subprocess.PIPE,
01460                              env=newenv)
01461         self.addCleanup(p.stdout.close)
01462         self.assertIn(b"physalis", p.stdout.read())

Here is the call graph for this function:

Definition at line 1401 of file test_subprocess.py.

01401 
01402     def test_startupinfo(self):
01403         # startupinfo argument
01404         # We uses hardcoded constants, because we do not want to
01405         # depend on win32all.
01406         STARTF_USESHOWWINDOW = 1
01407         SW_MAXIMIZE = 3
01408         startupinfo = subprocess.STARTUPINFO()
01409         startupinfo.dwFlags = STARTF_USESHOWWINDOW
01410         startupinfo.wShowWindow = SW_MAXIMIZE
01411         # Since Python is a console process, it won't be affected
01412         # by wShowWindow, but the argument should be silently
01413         # ignored
01414         subprocess.call([sys.executable, "-c", "import sys; sys.exit(0)"],
01415                         startupinfo=startupinfo)

Here is the call graph for this function:

Definition at line 1498 of file test_subprocess.py.

01498 
01499     def test_terminate(self):
01500         self._kill_process('terminate')
01501 
01502 
01503 # The module says:
01504 #   "NB This only works (and is only relevant) for UNIX."
01505 #
01506 # Actually, getoutput should work on any platform with an os.popen, but
01507 # I'll take the comment as given, and skip this suite.
@unittest.skipUnless(os.name == 'posix', "only relevant for UNIX")

Here is the call graph for this function:


The documentation for this class was generated from the following file: