Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +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 |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 11 | from test import support |
R. David Murray | a21e4ca | 2009-03-31 23:16:50 +0000 | [diff] [blame^] | 12 | import os |
| 13 | from os import path |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 14 | |
R. David Murray | a21e4ca | 2009-03-31 23:16:50 +0000 | [diff] [blame^] | 15 | startfile = support.get_attribute(os, 'startfile') |
| 16 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 17 | |
| 18 | class TestCase(unittest.TestCase): |
| 19 | def test_nonexisting(self): |
| 20 | self.assertRaises(OSError, startfile, "nonexisting.vbs") |
| 21 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 22 | def test_empty(self): |
| 23 | empty = path.join(path.dirname(__file__), "empty.vbs") |
| 24 | startfile(empty) |
| 25 | startfile(empty, "open") |
| 26 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 27 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 28 | support.run_unittest(TestCase) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 29 | |
| 30 | if __name__=="__main__": |
| 31 | test_main() |