ยปCore Development>Code coverage>Lib/test/test_startfile.py

Python code coverage for Lib/test/test_startfile.py

#countcontent
1n/a# Ridiculously simple test of the os.startfile function for Windows.
2n/a#
3n/a# empty.vbs is an empty file (except for a comment), which does
4n/a# nothing when run with cscript or wscript.
5n/a#
6n/a# A possible improvement would be to have empty.vbs do something that
7n/a# we can detect here, to make sure that not only the os.startfile()
8n/a# call succeeded, but also the script actually has run.
9n/a
10n/aimport unittest
11n/afrom test import support
12n/aimport os
13n/aimport sys
14n/afrom os import path
15n/a
16n/astartfile = support.get_attribute(os, 'startfile')
17n/a
18n/a
19n/aclass TestCase(unittest.TestCase):
20n/a def test_nonexisting(self):
21n/a self.assertRaises(OSError, startfile, "nonexisting.vbs")
22n/a
23n/a def test_empty(self):
24n/a # We need to make sure the child process starts in a directory
25n/a # we're not about to delete. If we're running under -j, that
26n/a # means the test harness provided directory isn't a safe option.
27n/a # See http://bugs.python.org/issue15526 for more details
28n/a with support.change_cwd(path.dirname(sys.executable)):
29n/a empty = path.join(path.dirname(__file__), "empty.vbs")
30n/a startfile(empty)
31n/a startfile(empty, "open")
32n/a
33n/aif __name__ == "__main__":
34n/a unittest.main()