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
d351827b
Kaydet (Commit)
d351827b
authored
Mar 14, 2016
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #20556: Used specific assert methods in threading tests.
üst
aac1dd04
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
19 deletions
+19
-19
test_dummy_thread.py
Lib/test/test_dummy_thread.py
+8
-8
test_threading.py
Lib/test/test_threading.py
+10
-10
test_threading_local.py
Lib/test/test_threading_local.py
+1
-1
No files found.
Lib/test/test_dummy_thread.py
Dosyayı görüntüle @
d351827b
...
@@ -24,14 +24,14 @@ class LockTests(unittest.TestCase):
...
@@ -24,14 +24,14 @@ class LockTests(unittest.TestCase):
def
test_initlock
(
self
):
def
test_initlock
(
self
):
#Make sure locks start locked
#Make sure locks start locked
self
.
assert
True
(
not
self
.
lock
.
locked
(),
self
.
assert
False
(
self
.
lock
.
locked
(),
"Lock object is not initialized unlocked."
)
"Lock object is not initialized unlocked."
)
def
test_release
(
self
):
def
test_release
(
self
):
# Test self.lock.release()
# Test self.lock.release()
self
.
lock
.
acquire
()
self
.
lock
.
acquire
()
self
.
lock
.
release
()
self
.
lock
.
release
()
self
.
assert
True
(
not
self
.
lock
.
locked
(),
self
.
assert
False
(
self
.
lock
.
locked
(),
"Lock object did not release properly."
)
"Lock object did not release properly."
)
def
test_improper_release
(
self
):
def
test_improper_release
(
self
):
...
@@ -46,7 +46,7 @@ class LockTests(unittest.TestCase):
...
@@ -46,7 +46,7 @@ class LockTests(unittest.TestCase):
def
test_cond_acquire_fail
(
self
):
def
test_cond_acquire_fail
(
self
):
#Test acquiring locked lock returns False
#Test acquiring locked lock returns False
self
.
lock
.
acquire
(
0
)
self
.
lock
.
acquire
(
0
)
self
.
assert
True
(
not
self
.
lock
.
acquire
(
0
),
self
.
assert
False
(
self
.
lock
.
acquire
(
0
),
"Conditional acquiring of a locked lock incorrectly "
"Conditional acquiring of a locked lock incorrectly "
"succeeded."
)
"succeeded."
)
...
@@ -58,9 +58,9 @@ class LockTests(unittest.TestCase):
...
@@ -58,9 +58,9 @@ class LockTests(unittest.TestCase):
def
test_uncond_acquire_return_val
(
self
):
def
test_uncond_acquire_return_val
(
self
):
#Make sure that an unconditional locking returns True.
#Make sure that an unconditional locking returns True.
self
.
assert
True
(
self
.
lock
.
acquire
(
1
)
is
True
,
self
.
assert
Is
(
self
.
lock
.
acquire
(
1
),
True
,
"Unconditional locking did not return True."
)
"Unconditional locking did not return True."
)
self
.
assert
True
(
self
.
lock
.
acquire
()
is
True
)
self
.
assert
Is
(
self
.
lock
.
acquire
(),
True
)
def
test_uncond_acquire_blocking
(
self
):
def
test_uncond_acquire_blocking
(
self
):
#Make sure that unconditional acquiring of a locked lock blocks.
#Make sure that unconditional acquiring of a locked lock blocks.
...
@@ -80,7 +80,7 @@ class LockTests(unittest.TestCase):
...
@@ -80,7 +80,7 @@ class LockTests(unittest.TestCase):
end_time
=
int
(
time
.
time
())
end_time
=
int
(
time
.
time
())
if
test_support
.
verbose
:
if
test_support
.
verbose
:
print
"done"
print
"done"
self
.
assert
True
((
end_time
-
start_time
)
>=
DELAY
,
self
.
assert
GreaterEqual
(
end_time
-
start_time
,
DELAY
,
"Blocking by unconditional acquiring failed."
)
"Blocking by unconditional acquiring failed."
)
class
MiscTests
(
unittest
.
TestCase
):
class
MiscTests
(
unittest
.
TestCase
):
...
@@ -94,7 +94,7 @@ class MiscTests(unittest.TestCase):
...
@@ -94,7 +94,7 @@ class MiscTests(unittest.TestCase):
#Test sanity of _thread.get_ident()
#Test sanity of _thread.get_ident()
self
.
assertIsInstance
(
_thread
.
get_ident
(),
int
,
self
.
assertIsInstance
(
_thread
.
get_ident
(),
int
,
"_thread.get_ident() returned a non-integer"
)
"_thread.get_ident() returned a non-integer"
)
self
.
assert
True
(
_thread
.
get_ident
()
!=
0
,
self
.
assert
NotEqual
(
_thread
.
get_ident
(),
0
,
"_thread.get_ident() returned 0"
)
"_thread.get_ident() returned 0"
)
def
test_LockType
(
self
):
def
test_LockType
(
self
):
...
@@ -164,7 +164,7 @@ class ThreadTests(unittest.TestCase):
...
@@ -164,7 +164,7 @@ class ThreadTests(unittest.TestCase):
time
.
sleep
(
DELAY
)
time
.
sleep
(
DELAY
)
if
test_support
.
verbose
:
if
test_support
.
verbose
:
print
'done'
print
'done'
self
.
assert
True
(
testing_queue
.
qsize
()
==
thread_count
,
self
.
assert
Equal
(
testing_queue
.
qsize
(),
thread_count
,
"Not all
%
s threads executed properly after
%
s sec."
%
"Not all
%
s threads executed properly after
%
s sec."
%
(
thread_count
,
DELAY
))
(
thread_count
,
DELAY
))
...
...
Lib/test/test_threading.py
Dosyayı görüntüle @
d351827b
...
@@ -51,7 +51,7 @@ class TestThread(threading.Thread):
...
@@ -51,7 +51,7 @@ class TestThread(threading.Thread):
self
.
nrunning
.
inc
()
self
.
nrunning
.
inc
()
if
verbose
:
if
verbose
:
print
self
.
nrunning
.
get
(),
'tasks are running'
print
self
.
nrunning
.
get
(),
'tasks are running'
self
.
testcase
.
assert
True
(
self
.
nrunning
.
get
()
<=
3
)
self
.
testcase
.
assert
LessEqual
(
self
.
nrunning
.
get
(),
3
)
time
.
sleep
(
delay
)
time
.
sleep
(
delay
)
if
verbose
:
if
verbose
:
...
@@ -59,7 +59,7 @@ class TestThread(threading.Thread):
...
@@ -59,7 +59,7 @@ class TestThread(threading.Thread):
with
self
.
mutex
:
with
self
.
mutex
:
self
.
nrunning
.
dec
()
self
.
nrunning
.
dec
()
self
.
testcase
.
assert
True
(
self
.
nrunning
.
get
()
>=
0
)
self
.
testcase
.
assert
GreaterEqual
(
self
.
nrunning
.
get
(),
0
)
if
verbose
:
if
verbose
:
print
'
%
s is finished.
%
d tasks are running'
%
(
print
'
%
s is finished.
%
d tasks are running'
%
(
self
.
name
,
self
.
nrunning
.
get
())
self
.
name
,
self
.
nrunning
.
get
())
...
@@ -92,25 +92,25 @@ class ThreadTests(BaseTestCase):
...
@@ -92,25 +92,25 @@ class ThreadTests(BaseTestCase):
for
i
in
range
(
NUMTASKS
):
for
i
in
range
(
NUMTASKS
):
t
=
TestThread
(
"<thread
%
d>"
%
i
,
self
,
sema
,
mutex
,
numrunning
)
t
=
TestThread
(
"<thread
%
d>"
%
i
,
self
,
sema
,
mutex
,
numrunning
)
threads
.
append
(
t
)
threads
.
append
(
t
)
self
.
assert
Equal
(
t
.
ident
,
None
)
self
.
assert
IsNone
(
t
.
ident
)
self
.
assert
True
(
re
.
match
(
'<TestThread
\
(.*, initial
\
)>'
,
repr
(
t
))
)
self
.
assert
RegexpMatches
(
repr
(
t
),
r'^<TestThread\(.*, initial\)>$'
)
t
.
start
()
t
.
start
()
if
verbose
:
if
verbose
:
print
'waiting for all tasks to complete'
print
'waiting for all tasks to complete'
for
t
in
threads
:
for
t
in
threads
:
t
.
join
(
NUMTASKS
)
t
.
join
(
NUMTASKS
)
self
.
assert
True
(
not
t
.
is_alive
())
self
.
assert
False
(
t
.
is_alive
())
self
.
assertNotEqual
(
t
.
ident
,
0
)
self
.
assertNotEqual
(
t
.
ident
,
0
)
self
.
assert
False
(
t
.
ident
is
None
)
self
.
assert
IsNotNone
(
t
.
ident
)
self
.
assert
True
(
re
.
match
(
'<TestThread
\
(.*,
\
w+ -?
\
d+
\
)>'
,
repr
(
t
))
)
self
.
assert
RegexpMatches
(
repr
(
t
),
r'^<TestThread\(.*, \w+ -?\d+\)>$'
)
if
verbose
:
if
verbose
:
print
'all tasks done'
print
'all tasks done'
self
.
assertEqual
(
numrunning
.
get
(),
0
)
self
.
assertEqual
(
numrunning
.
get
(),
0
)
def
test_ident_of_no_threading_threads
(
self
):
def
test_ident_of_no_threading_threads
(
self
):
# The ident still must work for the main thread and dummy threads.
# The ident still must work for the main thread and dummy threads.
self
.
assert
False
(
threading
.
currentThread
()
.
ident
is
None
)
self
.
assert
IsNotNone
(
threading
.
currentThread
()
.
ident
)
def
f
():
def
f
():
ident
.
append
(
threading
.
currentThread
()
.
ident
)
ident
.
append
(
threading
.
currentThread
()
.
ident
)
done
.
set
()
done
.
set
()
...
@@ -118,7 +118,7 @@ class ThreadTests(BaseTestCase):
...
@@ -118,7 +118,7 @@ class ThreadTests(BaseTestCase):
ident
=
[]
ident
=
[]
thread
.
start_new_thread
(
f
,
())
thread
.
start_new_thread
(
f
,
())
done
.
wait
()
done
.
wait
()
self
.
assert
False
(
ident
[
0
]
is
None
)
self
.
assert
IsNotNone
(
ident
[
0
]
)
# Kill the "immortal" _DummyThread
# Kill the "immortal" _DummyThread
del
threading
.
_active
[
ident
[
0
]]
del
threading
.
_active
[
ident
[
0
]]
...
@@ -236,7 +236,7 @@ class ThreadTests(BaseTestCase):
...
@@ -236,7 +236,7 @@ class ThreadTests(BaseTestCase):
self
.
assertTrue
(
ret
)
self
.
assertTrue
(
ret
)
if
verbose
:
if
verbose
:
print
" verifying worker hasn't exited"
print
" verifying worker hasn't exited"
self
.
assert
True
(
not
t
.
finished
)
self
.
assert
False
(
t
.
finished
)
if
verbose
:
if
verbose
:
print
" attempting to raise asynch exception in worker"
print
" attempting to raise asynch exception in worker"
result
=
set_async_exc
(
ctypes
.
c_long
(
t
.
id
),
exception
)
result
=
set_async_exc
(
ctypes
.
c_long
(
t
.
id
),
exception
)
...
...
Lib/test/test_threading_local.py
Dosyayı görüntüle @
d351827b
...
@@ -196,7 +196,7 @@ class ThreadLocalTest(unittest.TestCase, BaseLocalTest):
...
@@ -196,7 +196,7 @@ class ThreadLocalTest(unittest.TestCase, BaseLocalTest):
wr
=
weakref
.
ref
(
x
)
wr
=
weakref
.
ref
(
x
)
del
x
del
x
gc
.
collect
()
gc
.
collect
()
self
.
assertIs
(
wr
(),
None
)
self
.
assertIs
None
(
wr
()
)
class
PyThreadingLocalTest
(
unittest
.
TestCase
,
BaseLocalTest
):
class
PyThreadingLocalTest
(
unittest
.
TestCase
,
BaseLocalTest
):
_local
=
_threading_local
.
local
_local
=
_threading_local
.
local
...
...
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