blob: 9dce8fd6acbfca6e4b011a1e68ee5f66e30ba851 [file] [log] [blame]
Thomas Heller19fd8572006-04-04 18:31:35 +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()
8# call succeeded, but also the the script actually has run.
9
10import unittest
11from test import test_support
R. David Murray59beec32009-03-30 19:04:00 +000012import os
13from os import path
Nadeem Vawdabafc6a92011-04-19 01:35:58 +020014from time import sleep
Thomas Heller19fd8572006-04-04 18:31:35 +000015
R. David Murray3db8a342009-03-30 23:05:48 +000016startfile = test_support.get_attribute(os, 'startfile')
R. David Murray59beec32009-03-30 19:04:00 +000017
Thomas Heller19fd8572006-04-04 18:31:35 +000018
19class TestCase(unittest.TestCase):
20 def test_nonexisting(self):
Thomas Hellerb882f472006-04-04 18:52:27 +000021 self.assertRaises(OSError, startfile, "nonexisting.vbs")
Thomas Heller19fd8572006-04-04 18:31:35 +000022
23 def test_nonexisting_u(self):
Thomas Hellerb882f472006-04-04 18:52:27 +000024 self.assertRaises(OSError, startfile, u"nonexisting.vbs")
Thomas Heller19fd8572006-04-04 18:31:35 +000025
26 def test_empty(self):
Neal Norwitz9ad18bb2006-04-04 19:29:29 +000027 empty = path.join(path.dirname(__file__), "empty.vbs")
Thomas Hellerb882f472006-04-04 18:52:27 +000028 startfile(empty)
29 startfile(empty, "open")
Nadeem Vawdabafc6a92011-04-19 01:35:58 +020030 # Give the child process some time to exit before we finish.
31 # Otherwise the cleanup code will not be able to delete the cwd,
32 # because it is still in use.
33 sleep(0.1)
Thomas Heller19fd8572006-04-04 18:31:35 +000034
35 def test_empty_u(self):
Neal Norwitz9ad18bb2006-04-04 19:29:29 +000036 empty = path.join(path.dirname(__file__), "empty.vbs")
Thomas Hellerb882f472006-04-04 18:52:27 +000037 startfile(unicode(empty, "mbcs"))
38 startfile(unicode(empty, "mbcs"), "open")
Nadeem Vawdabafc6a92011-04-19 01:35:58 +020039 sleep(0.1)
Thomas Heller19fd8572006-04-04 18:31:35 +000040
41def test_main():
42 test_support.run_unittest(TestCase)
43
44if __name__=="__main__":
45 test_main()