3 from test
import test_support
6 class LockTests(unittest
.TestCase
):
8 """Very basic test of import lock functions."""
10 def verify_lock_state(self
, expected
):
11 self
.assertEqual(imp
.lock_held(), expected
,
12 "expected imp.lock_held() to be %r" % expected
)
16 # The import lock may already be held, e.g. if the test suite is run
17 # via "import test.autotest".
18 lock_held_at_start
= imp
.lock_held()
19 self
.verify_lock_state(lock_held_at_start
)
21 for i
in range(LOOPS
):
23 self
.verify_lock_state(True)
25 for i
in range(LOOPS
):
28 # The original state should be restored now.
29 self
.verify_lock_state(lock_held_at_start
)
31 if not lock_held_at_start
:
37 self
.fail("release_lock() without lock should raise "
40 class ReloadTests(unittest
.TestCase
):
42 """Very basic tests to make sure that imp.reload() operates just like
45 def test_source(self
):
46 # XXX (ncoghlan): It would be nice to use test_support.CleanImport
47 # here, but that breaks because the os module registers some
48 # handlers in copy_reg on import. Since CleanImport doesn't
49 # revert that registration, the module is left in a broken
50 # state after reversion. Reinitialising the module contents
51 # and just reverting os.environ to its previous state is an OK
53 with test_support
.EnvironmentVarGuard():
57 def test_extension(self
):
58 with test_support
.CleanImport('time'):
62 def test_builtin(self
):
63 with test_support
.CleanImport('marshal'):
77 tests
.append(LockTests
)
78 test_support
.run_unittest(*tests
)
80 if __name__
== "__main__":