blob: 61212ad42fd411048b4ec9c6566a502578da1256 [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()
Ezio Melottid2b49262013-01-27 06:20:14 +02008# call succeeded, but also the script actually has run.
Thomas Heller19fd8572006-04-04 18:31:35 +00009
10import unittest
11from test import test_support
R. David Murray59beec32009-03-30 19:04:00 +000012import os
Victor Stinner3837d972017-05-11 01:23:19 +020013import sys
R. David Murray59beec32009-03-30 19:04:00 +000014from os import path
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
Victor Stinner3837d972017-05-11 01:23:19 +020026 def check_empty(self, empty):
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 test_support.change_cwd(path.dirname(sys.executable)):
32 startfile(empty)
33 startfile(empty, "open")
34
Thomas Heller19fd8572006-04-04 18:31:35 +000035 def test_empty(self):
Neal Norwitz9ad18bb2006-04-04 19:29:29 +000036 empty = path.join(path.dirname(__file__), "empty.vbs")
Victor Stinner3837d972017-05-11 01:23:19 +020037 self.check_empty(empty)
Thomas Heller19fd8572006-04-04 18:31:35 +000038
Victor Stinner3837d972017-05-11 01:23:19 +020039 def test_empty_unicode(self):
Neal Norwitz9ad18bb2006-04-04 19:29:29 +000040 empty = path.join(path.dirname(__file__), "empty.vbs")
Victor Stinner3837d972017-05-11 01:23:19 +020041 empty = unicode(empty, "mbcs")
42 self.check_empty(empty)
Thomas Heller19fd8572006-04-04 18:31:35 +000043
44def test_main():
45 test_support.run_unittest(TestCase)
46
47if __name__=="__main__":
48 test_main()