Home | History | Annotate | Download | only in test
      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 script actually has run.
      9 
     10 import unittest
     11 from test import test_support
     12 import os
     13 import sys
     14 from os import path
     15 
     16 startfile = test_support.get_attribute(os, 'startfile')
     17 
     18 
     19 class TestCase(unittest.TestCase):
     20     def test_nonexisting(self):
     21         self.assertRaises(OSError, startfile, "nonexisting.vbs")
     22 
     23     def test_nonexisting_u(self):
     24         self.assertRaises(OSError, startfile, u"nonexisting.vbs")
     25 
     26     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 
     35     def test_empty(self):
     36         empty = path.join(path.dirname(__file__), "empty.vbs")
     37         self.check_empty(empty)
     38 
     39     def test_empty_unicode(self):
     40         empty = path.join(path.dirname(__file__), "empty.vbs")
     41         empty = unicode(empty, "mbcs")
     42         self.check_empty(empty)
     43 
     44 def test_main():
     45     test_support.run_unittest(TestCase)
     46 
     47 if __name__=="__main__":
     48     test_main()
     49