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
12import os
13import platform
14import sys
15from os import path
16
17startfile = support.get_attribute(os, 'startfile')
18
19
20class TestCase(unittest.TestCase):
21    def test_nonexisting(self):
22        self.assertRaises(OSError, startfile, "nonexisting.vbs")
23
24    @unittest.skipIf(platform.win32_is_iot(), "starting files is not supported on Windows IoT Core or nanoserver")
25    def test_empty(self):
26        # We need to make sure the child process starts in a directory
27        # we're not about to delete. If we're running under -j, that
28        # means the test harness provided directory isn't a safe option.
29        # See http://bugs.python.org/issue15526 for more details
30        with support.change_cwd(path.dirname(sys.executable)):
31            empty = path.join(path.dirname(__file__), "empty.vbs")
32            startfile(empty)
33            startfile(empty, "open")
34
35if __name__ == "__main__":
36    unittest.main()
37