Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
6a57dd86
Kaydet (Commit)
6a57dd86
authored
Eki 18, 2013
tarafından
Brett Cannon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #16803: Have test_importlib.test_locks use frozen and source
code.
üst
baced566
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
21 deletions
+48
-21
test_locks.py
Lib/test/test_importlib/test_locks.py
+48
-21
No files found.
Lib/test/test_importlib/test_locks.py
Dosyayı görüntüle @
6a57dd86
from
importlib
import
_bootstrap
from
.
import
util
frozen_init
,
source_init
=
util
.
import_importlib
(
'importlib'
)
frozen_bootstrap
=
frozen_init
.
_bootstrap
source_bootstrap
=
source_init
.
_bootstrap
import
sys
import
time
import
unittest
...
...
@@ -13,14 +17,9 @@ except ImportError:
else
:
from
test
import
lock_tests
LockType
=
_bootstrap
.
_ModuleLock
DeadlockError
=
_bootstrap
.
_DeadlockError
if
threading
is
not
None
:
class
ModuleLockAsRLockTests
(
lock_tests
.
RLockTests
):
locktype
=
staticmethod
(
lambda
:
LockType
(
"some_lock"
))
locktype
=
classmethod
(
lambda
cls
:
cls
.
LockType
(
"some_lock"
))
# _is_owned() unsupported
test__is_owned
=
None
...
...
@@ -34,13 +33,21 @@ if threading is not None:
# _release_save() unsupported
test_release_save_unacquired
=
None
class
Frozen_ModuleLockAsRLockTests
(
ModuleLockAsRLockTests
,
lock_tests
.
RLockTests
):
LockType
=
frozen_bootstrap
.
_ModuleLock
class
Source_ModuleLockAsRLockTests
(
ModuleLockAsRLockTests
,
lock_tests
.
RLockTests
):
LockType
=
source_bootstrap
.
_ModuleLock
else
:
class
ModuleLockAsRLockTests
(
unittest
.
TestCase
):
class
Frozen_
ModuleLockAsRLockTests
(
unittest
.
TestCase
):
pass
class
Source_ModuleLockAsRLockTests
(
unittest
.
TestCase
):
pass
@unittest.skipUnless
(
threading
,
"threads needed for this test"
)
class
DeadlockAvoidanceTests
(
unittest
.
TestCase
)
:
class
DeadlockAvoidanceTests
:
def
setUp
(
self
):
try
:
...
...
@@ -55,7 +62,7 @@ class DeadlockAvoidanceTests(unittest.TestCase):
def
run_deadlock_avoidance_test
(
self
,
create_deadlock
):
NLOCKS
=
10
locks
=
[
LockType
(
str
(
i
))
for
i
in
range
(
NLOCKS
)]
locks
=
[
self
.
LockType
(
str
(
i
))
for
i
in
range
(
NLOCKS
)]
pairs
=
[(
locks
[
i
],
locks
[(
i
+
1
)
%
NLOCKS
])
for
i
in
range
(
NLOCKS
)]
if
create_deadlock
:
NTHREADS
=
NLOCKS
...
...
@@ -67,7 +74,7 @@ class DeadlockAvoidanceTests(unittest.TestCase):
"""Try to acquire the lock. Return True on success, False on deadlock."""
try
:
lock
.
acquire
()
except
DeadlockError
:
except
self
.
DeadlockError
:
return
False
else
:
return
True
...
...
@@ -99,30 +106,50 @@ class DeadlockAvoidanceTests(unittest.TestCase):
self
.
assertEqual
(
results
.
count
((
True
,
False
)),
0
)
self
.
assertEqual
(
results
.
count
((
True
,
True
)),
len
(
results
))
@unittest.skipUnless
(
threading
,
"threads needed for this test"
)
class
Frozen_DeadlockAvoidanceTests
(
DeadlockAvoidanceTests
,
unittest
.
TestCase
):
LockType
=
frozen_bootstrap
.
_ModuleLock
DeadlockError
=
frozen_bootstrap
.
_DeadlockError
@unittest.skipUnless
(
threading
,
"threads needed for this test"
)
class
Source_DeadlockAvoidanceTests
(
DeadlockAvoidanceTests
,
unittest
.
TestCase
):
LockType
=
source_bootstrap
.
_ModuleLock
DeadlockError
=
source_bootstrap
.
_DeadlockError
class
LifetimeTests
(
unittest
.
TestCase
):
class
LifetimeTests
:
def
test_lock_lifetime
(
self
):
name
=
"xyzzy"
self
.
assertNotIn
(
name
,
_
bootstrap
.
_module_locks
)
lock
=
_
bootstrap
.
_get_module_lock
(
name
)
self
.
assertIn
(
name
,
_
bootstrap
.
_module_locks
)
self
.
assertNotIn
(
name
,
self
.
bootstrap
.
_module_locks
)
lock
=
self
.
bootstrap
.
_get_module_lock
(
name
)
self
.
assertIn
(
name
,
self
.
bootstrap
.
_module_locks
)
wr
=
weakref
.
ref
(
lock
)
del
lock
support
.
gc_collect
()
self
.
assertNotIn
(
name
,
_
bootstrap
.
_module_locks
)
self
.
assertNotIn
(
name
,
self
.
bootstrap
.
_module_locks
)
self
.
assertIsNone
(
wr
())
def
test_all_locks
(
self
):
support
.
gc_collect
()
self
.
assertEqual
(
0
,
len
(
_bootstrap
.
_module_locks
),
_bootstrap
.
_module_locks
)
self
.
assertEqual
(
0
,
len
(
self
.
bootstrap
.
_module_locks
),
self
.
bootstrap
.
_module_locks
)
class
Frozen_LifetimeTests
(
LifetimeTests
,
unittest
.
TestCase
):
bootstrap
=
frozen_bootstrap
class
Source_LifetimeTests
(
LifetimeTests
,
unittest
.
TestCase
):
bootstrap
=
source_bootstrap
@support.reap_threads
def
test_main
():
support
.
run_unittest
(
ModuleLockAsRLockTests
,
DeadlockAvoidanceTests
,
LifetimeTests
)
support
.
run_unittest
(
Frozen_ModuleLockAsRLockTests
,
Source_ModuleLockAsRLockTests
,
Frozen_DeadlockAvoidanceTests
,
Source_DeadlockAvoidanceTests
,
Frozen_LifetimeTests
,
Source_LifetimeTests
)
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment