Thomas Heller | 19fd857 | 2006-04-04 18:31:35 +0000 | [diff] [blame] | 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 the script actually has run. |
| 9 | |
| 10 | import unittest |
| 11 | from test import test_support |
R. David Murray | 59beec3 | 2009-03-30 19:04:00 +0000 | [diff] [blame] | 12 | import os |
| 13 | from os import path |
Thomas Heller | 19fd857 | 2006-04-04 18:31:35 +0000 | [diff] [blame] | 14 | |
R. David Murray | 3db8a34 | 2009-03-30 23:05:48 +0000 | [diff] [blame] | 15 | startfile = test_support.get_attribute(os, 'startfile') |
R. David Murray | 59beec3 | 2009-03-30 19:04:00 +0000 | [diff] [blame] | 16 | |
Thomas Heller | 19fd857 | 2006-04-04 18:31:35 +0000 | [diff] [blame] | 17 | |
| 18 | class TestCase(unittest.TestCase): |
| 19 | def test_nonexisting(self): |
Thomas Heller | b882f47 | 2006-04-04 18:52:27 +0000 | [diff] [blame] | 20 | self.assertRaises(OSError, startfile, "nonexisting.vbs") |
Thomas Heller | 19fd857 | 2006-04-04 18:31:35 +0000 | [diff] [blame] | 21 | |
| 22 | def test_nonexisting_u(self): |
Thomas Heller | b882f47 | 2006-04-04 18:52:27 +0000 | [diff] [blame] | 23 | self.assertRaises(OSError, startfile, u"nonexisting.vbs") |
Thomas Heller | 19fd857 | 2006-04-04 18:31:35 +0000 | [diff] [blame] | 24 | |
| 25 | def test_empty(self): |
Neal Norwitz | 9ad18bb | 2006-04-04 19:29:29 +0000 | [diff] [blame] | 26 | empty = path.join(path.dirname(__file__), "empty.vbs") |
Thomas Heller | b882f47 | 2006-04-04 18:52:27 +0000 | [diff] [blame] | 27 | startfile(empty) |
| 28 | startfile(empty, "open") |
Thomas Heller | 19fd857 | 2006-04-04 18:31:35 +0000 | [diff] [blame] | 29 | |
| 30 | def test_empty_u(self): |
Neal Norwitz | 9ad18bb | 2006-04-04 19:29:29 +0000 | [diff] [blame] | 31 | empty = path.join(path.dirname(__file__), "empty.vbs") |
Thomas Heller | b882f47 | 2006-04-04 18:52:27 +0000 | [diff] [blame] | 32 | startfile(unicode(empty, "mbcs")) |
| 33 | startfile(unicode(empty, "mbcs"), "open") |
Thomas Heller | 19fd857 | 2006-04-04 18:31:35 +0000 | [diff] [blame] | 34 | |
| 35 | def test_main(): |
| 36 | test_support.run_unittest(TestCase) |
| 37 | |
| 38 | if __name__=="__main__": |
| 39 | test_main() |