(root)/
Python-3.12.0/
Lib/
test/
test_startfile.py
       1  # Ridiculously simple test of the os.startfile function for Windows.
       2  #
       3  # empty.vbs is an empty file (except for a comment), which does
       4  # nothing when run with cscript or wscript.
       5  #
       6  # A possible improvement would be to have empty.vbs do something that
       7  # we can detect here, to make sure that not only the os.startfile()
       8  # call succeeded, but also the script actually has run.
       9  
      10  import unittest
      11  from test import support
      12  from test.support import os_helper
      13  import os
      14  import platform
      15  import sys
      16  from os import path
      17  
      18  startfile = support.get_attribute(os, 'startfile')
      19  
      20  
      21  @unittest.skipIf(platform.win32_is_iot(), "starting files is not supported on Windows IoT Core or nanoserver")
      22  class ESC[4;38;5;81mTestCase(ESC[4;38;5;149munittestESC[4;38;5;149m.ESC[4;38;5;149mTestCase):
      23      def test_nonexisting(self):
      24          self.assertRaises(OSError, startfile, "nonexisting.vbs")
      25  
      26      def test_empty(self):
      27          # We need to make sure the child process starts in a directory
      28          # we're not about to delete. If we're running under -j, that
      29          # means the test harness provided directory isn't a safe option.
      30          # See http://bugs.python.org/issue15526 for more details
      31          with os_helper.change_cwd(path.dirname(sys.executable)):
      32              empty = path.join(path.dirname(__file__), "empty.vbs")
      33              startfile(empty)
      34              startfile(empty, "open")
      35          startfile(empty, cwd=path.dirname(sys.executable))
      36  
      37      def test_python(self):
      38          # Passing "-V" ensures that it closes quickly, though still not
      39          # quickly enough that we can run in the test directory
      40          cwd, name = path.split(sys.executable)
      41          startfile(name, arguments="-V", cwd=cwd)
      42          startfile(name, arguments="-V", cwd=cwd, show_cmd=0)
      43  
      44  if __name__ == "__main__":
      45      unittest.main()