test_startfile.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. import unittest
  10. from test import test_support
  11. import os
  12. from os import path
  13. from time import sleep
  14. startfile = test_support.get_attribute(os, 'startfile')
  15. class TestCase(unittest.TestCase):
  16. def test_nonexisting(self):
  17. self.assertRaises(OSError, startfile, "nonexisting.vbs")
  18. def test_nonexisting_u(self):
  19. self.assertRaises(OSError, startfile, u"nonexisting.vbs")
  20. def test_empty(self):
  21. empty = path.join(path.dirname(__file__), "empty.vbs")
  22. startfile(empty)
  23. startfile(empty, "open")
  24. # Give the child process some time to exit before we finish.
  25. # Otherwise the cleanup code will not be able to delete the cwd,
  26. # because it is still in use.
  27. sleep(0.1)
  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. sleep(0.1)
  33. def test_main():
  34. test_support.run_unittest(TestCase)
  35. if __name__=="__main__":
  36. test_main()