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
4b61d0fa
Kaydet (Commit)
4b61d0fa
authored
Ara 23, 2012
tarafından
Andrew Svetlov
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #16045: add more unit tests for built-in int()
Patch by Chris Jerdonek.
üst
2909d6b4
8e42e8a0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
2 deletions
+44
-2
test_builtin.py
Lib/test/test_builtin.py
+2
-0
test_int.py
Lib/test/test_int.py
+42
-2
No files found.
Lib/test/test_builtin.py
Dosyayı görüntüle @
4b61d0fa
...
...
@@ -1177,6 +1177,8 @@ class BuiltinTest(unittest.TestCase):
# Check stdin/stdout error handler is used when invoking GNU readline
self
.
check_input_tty
(
"prompté"
,
b
"quux
\xe9
"
,
"ascii"
)
# test_int(): see test_int.py for tests of built-in function int().
def
test_repr
(
self
):
self
.
assertEqual
(
repr
(
''
),
'
\'\'
'
)
self
.
assertEqual
(
repr
(
0
),
'0'
)
...
...
Lib/test/test_int.py
Dosyayı görüntüle @
4b61d0fa
import
sys
import
unittest
from
test
.support
import
run_unittes
t
from
test
import
suppor
t
L
=
[
(
'0'
,
0
),
...
...
@@ -221,6 +221,46 @@ class IntTestCases(unittest.TestCase):
self
.
assertEqual
(
int
(
'2br45qc'
,
35
),
4294967297
)
self
.
assertEqual
(
int
(
'1z141z5'
,
36
),
4294967297
)
def
test_no_args
(
self
):
self
.
assertEquals
(
int
(),
0
)
def
test_keyword_args
(
self
):
# Test invoking int() using keyword arguments.
self
.
assertEquals
(
int
(
x
=
1.2
),
1
)
self
.
assertEquals
(
int
(
'100'
,
base
=
2
),
4
)
self
.
assertEquals
(
int
(
x
=
'100'
,
base
=
2
),
4
)
# For example, PyPy 1.9.0 raised TypeError for these cases because it
# expects x to be a string if base is given.
@support.cpython_only
def
test_base_arg_with_no_x_arg
(
self
):
self
.
assertEquals
(
int
(
base
=
6
),
0
)
# Even invalid bases don't raise an exception.
self
.
assertEquals
(
int
(
base
=
1
),
0
)
self
.
assertEquals
(
int
(
base
=
1000
),
0
)
self
.
assertEquals
(
int
(
base
=
'foo'
),
0
)
def
test_non_numeric_input_types
(
self
):
# Test possible non-numeric types for the argument x, including
# subclasses of the explicitly documented accepted types.
class
CustomStr
(
str
):
pass
class
CustomBytes
(
bytes
):
pass
class
CustomByteArray
(
bytearray
):
pass
values
=
[
b
'100'
,
bytearray
(
b
'100'
),
CustomStr
(
'100'
),
CustomBytes
(
b
'100'
),
CustomByteArray
(
b
'100'
)]
for
x
in
values
:
msg
=
'x has type
%
s'
%
type
(
x
)
.
__name__
self
.
assertEquals
(
int
(
x
),
100
,
msg
=
msg
)
self
.
assertEquals
(
int
(
x
,
2
),
4
,
msg
=
msg
)
def
test_string_float
(
self
):
self
.
assertRaises
(
ValueError
,
int
,
'1.2'
)
def
test_intconversion
(
self
):
# Test __int__()
class
ClassicMissingMethods
:
...
...
@@ -328,7 +368,7 @@ class IntTestCases(unittest.TestCase):
self
.
fail
(
"Expected int(
%
r) to raise a ValueError"
,
s
)
def
test_main
():
run_unittest
(
IntTestCases
)
support
.
run_unittest
(
IntTestCases
)
if
__name__
==
"__main__"
:
test_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