home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 July / maximum-cd-2011-07.iso / DiscContents / LibO_3.3.2_Win_x86_install_multi.exe / libreoffice1.cab / test_startfile.py < prev    next >
Encoding:
Python Source  |  2011-03-15  |  1.2 KB  |  38 lines

  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
  12.  
  13. # use this form so that the test is skipped when startfile is not available:
  14. from os import startfile, path
  15.  
  16. class TestCase(unittest.TestCase):
  17.     def test_nonexisting(self):
  18.         self.assertRaises(OSError, startfile, "nonexisting.vbs")
  19.  
  20.     def test_nonexisting_u(self):
  21.         self.assertRaises(OSError, startfile, u"nonexisting.vbs")
  22.  
  23.     def test_empty(self):
  24.         empty = path.join(path.dirname(__file__), "empty.vbs")
  25.         startfile(empty)
  26.         startfile(empty, "open")
  27.  
  28.     def test_empty_u(self):
  29.         empty = path.join(path.dirname(__file__), "empty.vbs")
  30.         startfile(unicode(empty, "mbcs"))
  31.         startfile(unicode(empty, "mbcs"), "open")
  32.  
  33. def test_main():
  34.     test_support.run_unittest(TestCase)
  35.  
  36. if __name__=="__main__":
  37.     test_main()
  38.