Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_imp.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 23b452ac1a50 |
| children | 6768b2350c57 |
| rev | line source |
|---|---|
|
28857
68c6186dc1a1
Rewrote. As reported on c.l.py, when the test suite is run via
Tim Peters <tim.peters@gmail.com>
parents:
27923
diff
changeset
|
1 import imp |
|
39979
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
2 import unittest |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
3 from test import test_support |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
4 |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
5 |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
6 class LockTests(unittest.TestCase): |
| 27853 | 7 |
|
39979
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
8 """Very basic test of import lock functions.""" |
| 27853 | 9 |
|
39979
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
10 def verify_lock_state(self, expected): |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
11 self.failUnlessEqual(imp.lock_held(), expected, |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
12 "expected imp.lock_held() to be %r" % expected) |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
13 def testLock(self): |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
14 LOOPS = 50 |
| 27853 | 15 |
|
39979
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
16 # The import lock may already be held, e.g. if the test suite is run |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
17 # via "import test.autotest". |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
18 lock_held_at_start = imp.lock_held() |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
19 self.verify_lock_state(lock_held_at_start) |
|
28857
68c6186dc1a1
Rewrote. As reported on c.l.py, when the test suite is run via
Tim Peters <tim.peters@gmail.com>
parents:
27923
diff
changeset
|
20 |
|
39979
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
21 for i in range(LOOPS): |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
22 imp.acquire_lock() |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
23 self.verify_lock_state(True) |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
24 |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
25 for i in range(LOOPS): |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
26 imp.release_lock() |
| 27853 | 27 |
|
39979
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
28 # The original state should be restored now. |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
29 self.verify_lock_state(lock_held_at_start) |
|
28857
68c6186dc1a1
Rewrote. As reported on c.l.py, when the test suite is run via
Tim Peters <tim.peters@gmail.com>
parents:
27923
diff
changeset
|
30 |
|
39979
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
31 if not lock_held_at_start: |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
32 try: |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
33 imp.release_lock() |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
34 except RuntimeError: |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
35 pass |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
36 else: |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
37 self.fail("release_lock() without lock should raise " |
|
9e35b62ed4d2
Convert test_imp over to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
34188
diff
changeset
|
38 "RuntimeError") |
| 27853 | 39 |
|
48189
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
40 class ReloadTests(unittest.TestCase): |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
41 |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
42 """Very basic tests to make sure that imp.reload() operates just like |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
43 reload().""" |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
44 |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
45 def test_source(self): |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
46 import os |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
47 imp.reload(os) |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
48 |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
49 def test_extension(self): |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
50 import time |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
51 imp.reload(time) |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
52 |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
53 def test_builtin(self): |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
54 import marshal |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
55 imp.reload(marshal) |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
56 |
|
53ade9e68b56
Add imp.reload(). This to help with transitioning to 3.0 the reload() built-in
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
57 |
|
27912
c5ebacbba0be
Actually run these tests from regrtest.py.
Neal Norwitz <nnorwitz@gmail.com>
parents:
27853
diff
changeset
|
58 def test_main(): |
|
49097
23b452ac1a50
Issue #3806: LockTests in test_imp should be skipped when thread is not available.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
48189
diff
changeset
|
59 tests = [ |
|
23b452ac1a50
Issue #3806: LockTests in test_imp should be skipped when thread is not available.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
48189
diff
changeset
|
60 ReloadTests, |
|
23b452ac1a50
Issue #3806: LockTests in test_imp should be skipped when thread is not available.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
48189
diff
changeset
|
61 ] |
|
23b452ac1a50
Issue #3806: LockTests in test_imp should be skipped when thread is not available.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
48189
diff
changeset
|
62 try: |
|
23b452ac1a50
Issue #3806: LockTests in test_imp should be skipped when thread is not available.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
48189
diff
changeset
|
63 import thread |
|
23b452ac1a50
Issue #3806: LockTests in test_imp should be skipped when thread is not available.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
48189
diff
changeset
|
64 except ImportError: |
|
23b452ac1a50
Issue #3806: LockTests in test_imp should be skipped when thread is not available.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
48189
diff
changeset
|
65 pass |
|
23b452ac1a50
Issue #3806: LockTests in test_imp should be skipped when thread is not available.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
48189
diff
changeset
|
66 else: |
|
23b452ac1a50
Issue #3806: LockTests in test_imp should be skipped when thread is not available.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
48189
diff
changeset
|
67 tests.append(LockTests) |
|
23b452ac1a50
Issue #3806: LockTests in test_imp should be skipped when thread is not available.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
48189
diff
changeset
|
68 test_support.run_unittest(*tests) |
|
27912
c5ebacbba0be
Actually run these tests from regrtest.py.
Neal Norwitz <nnorwitz@gmail.com>
parents:
27853
diff
changeset
|
69 |
| 27853 | 70 if __name__ == "__main__": |
|
27912
c5ebacbba0be
Actually run these tests from regrtest.py.
Neal Norwitz <nnorwitz@gmail.com>
parents:
27853
diff
changeset
|
71 test_main() |
