• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
10import unittest
11from test import support
12from test.support import os_helper
13import os
14import platform
15import sys
16from os import path
17
18startfile = 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")
22class TestCase(unittest.TestCase):
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
44if __name__ == "__main__":
45    unittest.main()
46