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
cddcafaf
Kaydet (Commit)
cddcafaf
authored
Ara 23, 2012
tarafından
Andrew Svetlov
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #16045: add more unit tests for built-in int()
Patch by Chris Jerdonek.
üst
8e1e8165
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
test_builtin.py
Lib/test/test_builtin.py
+2
-0
test_int.py
Lib/test/test_int.py
+54
-0
No files found.
Lib/test/test_builtin.py
Dosyayı görüntüle @
cddcafaf
...
@@ -680,6 +680,8 @@ class BuiltinTest(unittest.TestCase):
...
@@ -680,6 +680,8 @@ class BuiltinTest(unittest.TestCase):
# Test input() later, together with raw_input
# Test input() later, together with raw_input
# test_int(): see test_int.py for int() tests.
def
test_intern
(
self
):
def
test_intern
(
self
):
self
.
assertRaises
(
TypeError
,
intern
)
self
.
assertRaises
(
TypeError
,
intern
)
# This fails if the test is run twice with a constant string,
# This fails if the test is run twice with a constant string,
...
...
Lib/test/test_int.py
Dosyayı görüntüle @
cddcafaf
import
sys
import
sys
import
unittest
import
unittest
from
test
import
test_support
from
test.test_support
import
run_unittest
,
have_unicode
from
test.test_support
import
run_unittest
,
have_unicode
import
math
import
math
...
@@ -315,6 +316,59 @@ class IntTestCases(unittest.TestCase):
...
@@ -315,6 +316,59 @@ class IntTestCases(unittest.TestCase):
self
.
assertEqual
(
int
(
float
(
2
**
54
+
10
)),
2
**
54
+
8
)
self
.
assertEqual
(
int
(
float
(
2
**
54
+
10
)),
2
**
54
+
8
)
self
.
assertEqual
(
int
(
float
(
2
**
54
+
11
)),
2
**
54
+
12
)
self
.
assertEqual
(
int
(
float
(
2
**
54
+
11
)),
2
**
54
+
12
)
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
)
def
test_valid_non_numeric_input_types_for_x
(
self
):
# Test possible valid non-numeric types for x, including subclasses
# of the allowed built-in types.
class
CustomStr
(
str
):
pass
values
=
[
'100'
,
CustomStr
(
'100'
)]
if
have_unicode
:
class
CustomUnicode
(
unicode
):
pass
values
+=
[
unicode
(
'100'
),
CustomUnicode
(
unicode
(
'100'
))]
for
x
in
values
:
msg
=
'x has value
%
s and type
%
s'
%
(
x
,
type
(
x
)
.
__name__
)
try
:
self
.
assertEquals
(
int
(
x
),
100
,
msg
=
msg
)
self
.
assertEquals
(
int
(
x
,
2
),
4
,
msg
=
msg
)
except
TypeError
,
err
:
raise
AssertionError
(
'For
%
s got TypeError:
%
s'
%
(
type
(
x
)
.
__name__
,
err
))
def
test_error_on_string_float_for_x
(
self
):
self
.
assertRaises
(
ValueError
,
int
,
'1.2'
)
def
test_error_on_bytearray_for_x
(
self
):
self
.
assertRaises
(
TypeError
,
int
,
bytearray
(
'100'
),
2
)
def
test_error_on_invalid_int_bases
(
self
):
for
base
in
[
-
1
,
1
,
1000
]:
self
.
assertRaises
(
ValueError
,
int
,
'100'
,
base
)
def
test_error_on_string_base
(
self
):
self
.
assertRaises
(
TypeError
,
int
,
100
,
base
=
'foo'
)
# Include the following because in contrast CPython raises no error
# for bad integer bases when x is not given.
self
.
assertRaises
(
TypeError
,
int
,
base
=
'foo'
)
# For example, PyPy 1.9.0 raised TypeError for these cases because it
# expects x to be a string if base is given.
@test_support.cpython_only
def
test_int_base_without_x_returns_0
(
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
)
def
test_intconversion
(
self
):
def
test_intconversion
(
self
):
# Test __int__()
# Test __int__()
class
ClassicMissingMethods
:
class
ClassicMissingMethods
:
...
...
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