Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_startfile.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 84272228d7db |
| children |
| rev | line source |
|---|---|
|
37478
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
1 # Ridiculously simple test of the os.startfile function for Windows. |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
2 # |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
3 # empty.vbs is an empty file (except for a comment), which does |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
4 # nothing when run with cscript or wscript. |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
5 # |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
6 # A possible improvement would be to have empty.vbs do something that |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
7 # we can detect here, to make sure that not only the os.startfile() |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
8 # call succeeded, but also the the script actually has run. |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
9 |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
10 import unittest |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
11 from test import test_support |
|
52456
f2c90fd05d66
Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents:
37485
diff
changeset
|
12 import os |
|
f2c90fd05d66
Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents:
37485
diff
changeset
|
13 from os import path |
|
69432
84272228d7db
Fix sporadic failure in test_startfile.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
52491
diff
changeset
|
14 from time import sleep |
|
37478
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
15 |
|
52491
f4c5e3a64be2
Change more tests to use import_module for the modules that
R. David Murray <rdmurray@bitdance.com>
parents:
52456
diff
changeset
|
16 startfile = test_support.get_attribute(os, 'startfile') |
|
52456
f2c90fd05d66
Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents:
37485
diff
changeset
|
17 |
|
37478
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
18 |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
19 class TestCase(unittest.TestCase): |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
20 def test_nonexisting(self): |
|
37480
d6ecba596e1e
Change the import statement so that the test is skipped when
Thomas Heller <theller@ctypes.org>
parents:
37478
diff
changeset
|
21 self.assertRaises(OSError, startfile, "nonexisting.vbs") |
|
37478
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
22 |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
23 def test_nonexisting_u(self): |
|
37480
d6ecba596e1e
Change the import statement so that the test is skipped when
Thomas Heller <theller@ctypes.org>
parents:
37478
diff
changeset
|
24 self.assertRaises(OSError, startfile, u"nonexisting.vbs") |
|
37478
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
25 |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
26 def test_empty(self): |
|
37485
896f9fead17e
we need os.path too for the normal run on windows
Neal Norwitz <nnorwitz@gmail.com>
parents:
37480
diff
changeset
|
27 empty = path.join(path.dirname(__file__), "empty.vbs") |
|
37480
d6ecba596e1e
Change the import statement so that the test is skipped when
Thomas Heller <theller@ctypes.org>
parents:
37478
diff
changeset
|
28 startfile(empty) |
|
d6ecba596e1e
Change the import statement so that the test is skipped when
Thomas Heller <theller@ctypes.org>
parents:
37478
diff
changeset
|
29 startfile(empty, "open") |
|
69432
84272228d7db
Fix sporadic failure in test_startfile.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
52491
diff
changeset
|
30 # Give the child process some time to exit before we finish. |
|
84272228d7db
Fix sporadic failure in test_startfile.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
52491
diff
changeset
|
31 # Otherwise the cleanup code will not be able to delete the cwd, |
|
84272228d7db
Fix sporadic failure in test_startfile.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
52491
diff
changeset
|
32 # because it is still in use. |
|
84272228d7db
Fix sporadic failure in test_startfile.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
52491
diff
changeset
|
33 sleep(0.1) |
|
37478
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
34 |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
35 def test_empty_u(self): |
|
37485
896f9fead17e
we need os.path too for the normal run on windows
Neal Norwitz <nnorwitz@gmail.com>
parents:
37480
diff
changeset
|
36 empty = path.join(path.dirname(__file__), "empty.vbs") |
|
37480
d6ecba596e1e
Change the import statement so that the test is skipped when
Thomas Heller <theller@ctypes.org>
parents:
37478
diff
changeset
|
37 startfile(unicode(empty, "mbcs")) |
|
d6ecba596e1e
Change the import statement so that the test is skipped when
Thomas Heller <theller@ctypes.org>
parents:
37478
diff
changeset
|
38 startfile(unicode(empty, "mbcs"), "open") |
|
69432
84272228d7db
Fix sporadic failure in test_startfile.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
52491
diff
changeset
|
39 sleep(0.1) |
|
37478
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
40 |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
41 def test_main(): |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
42 test_support.run_unittest(TestCase) |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
43 |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
44 if __name__=="__main__": |
|
852f1c1a89b4
Add a simple test for os.startfile().
Thomas Heller <theller@ctypes.org>
parents:
diff
changeset
|
45 test_main() |
