blob: 589ffa25244da99f9c9bc9f34c8f81b9510eb332 [file] [log] [blame]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001# 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()
Ezio Melotti3f5db392013-01-27 06:20:14 +02008# call succeeded, but also the script actually has run.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00009
10import unittest
Benjamin Petersonee8712c2008-05-20 21:35:26 +000011from test import support
Hai Shi598a9512020-08-07 23:18:38 +080012from test.support import os_helper
R. David Murraya21e4ca2009-03-31 23:16:50 +000013import os
Paul Monson62dfd7d2019-04-25 11:36:45 -070014import platform
Antoine Pitrou8a53dbe2012-09-16 00:12:50 +020015import sys
R. David Murraya21e4ca2009-03-31 23:16:50 +000016from os import path
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000017
R. David Murraya21e4ca2009-03-31 23:16:50 +000018startfile = support.get_attribute(os, 'startfile')
19
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000020
21class TestCase(unittest.TestCase):
22 def test_nonexisting(self):
23 self.assertRaises(OSError, startfile, "nonexisting.vbs")
24
Paul Monson62dfd7d2019-04-25 11:36:45 -070025 @unittest.skipIf(platform.win32_is_iot(), "starting files is not supported on Windows IoT Core or nanoserver")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000026 def test_empty(self):
Nick Coghlanc06c0ae2013-07-29 17:51:16 +100027 # 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
Hai Shi598a9512020-08-07 23:18:38 +080031 with os_helper.change_cwd(path.dirname(sys.executable)):
Nick Coghlanc06c0ae2013-07-29 17:51:16 +100032 empty = path.join(path.dirname(__file__), "empty.vbs")
Antoine Pitrou8a53dbe2012-09-16 00:12:50 +020033 startfile(empty)
Nick Coghlanc06c0ae2013-07-29 17:51:16 +100034 startfile(empty, "open")
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000035
Zachary Ware38c707e2015-04-13 15:00:43 -050036if __name__ == "__main__":
37 unittest.main()