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
bc14efbd
Kaydet (Commit)
bc14efbd
authored
May 08, 2007
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make the StringIO test pass.
The buffer object now special-cases Unicode when concatenating. Sigh.
üst
cfe5f20f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
23 deletions
+36
-23
test_StringIO.py
Lib/test/test_StringIO.py
+25
-21
bufferobject.c
Objects/bufferobject.c
+11
-2
No files found.
Lib/test/test_StringIO.py
Dosyayı görüntüle @
bc14efbd
# Tests StringIO and cStringIO
# Tests StringIO and cStringIO
import
sys
import
unittest
import
unittest
import
StringIO
import
StringIO
import
cStringIO
import
cStringIO
import
types
from
test
import
test_support
from
test
import
test_support
class
TestGenericStringIO
(
unittest
.
TestCase
)
:
class
TestGenericStringIO
:
# use a class variable MODULE to define which module is being tested
# use a class variable MODULE to define which module is being tested
# Line of data to test as string
# Line of data to test as string
...
@@ -71,7 +71,7 @@ class TestGenericStringIO(unittest.TestCase):
...
@@ -71,7 +71,7 @@ class TestGenericStringIO(unittest.TestCase):
self
.
assertEqual
(
f
.
closed
,
False
)
self
.
assertEqual
(
f
.
closed
,
False
)
f
.
close
()
f
.
close
()
self
.
assertEqual
(
f
.
closed
,
True
)
self
.
assertEqual
(
f
.
closed
,
True
)
f
=
self
.
MODULE
.
StringIO
(
"abc"
)
f
=
self
.
MODULE
.
StringIO
(
self
.
constructor
(
"abc"
)
)
self
.
assertEqual
(
f
.
closed
,
False
)
self
.
assertEqual
(
f
.
closed
,
False
)
f
.
close
()
f
.
close
()
self
.
assertEqual
(
f
.
closed
,
True
)
self
.
assertEqual
(
f
.
closed
,
True
)
...
@@ -98,7 +98,7 @@ class TestGenericStringIO(unittest.TestCase):
...
@@ -98,7 +98,7 @@ class TestGenericStringIO(unittest.TestCase):
self
.
_fp
.
close
()
self
.
_fp
.
close
()
self
.
assertRaises
(
ValueError
,
next
,
self
.
_fp
)
self
.
assertRaises
(
ValueError
,
next
,
self
.
_fp
)
class
TestStringIO
(
TestGenericStringIO
):
class
TestStringIO
(
TestGenericStringIO
,
unittest
.
TestCase
):
MODULE
=
StringIO
MODULE
=
StringIO
def
test_unicode
(
self
):
def
test_unicode
(
self
):
...
@@ -116,10 +116,11 @@ class TestStringIO(TestGenericStringIO):
...
@@ -116,10 +116,11 @@ class TestStringIO(TestGenericStringIO):
f
.
write
(
str
(
self
.
_line
[
52
]))
f
.
write
(
str
(
self
.
_line
[
52
]))
s
=
f
.
getvalue
()
s
=
f
.
getvalue
()
self
.
assertEqual
(
s
,
str
(
'abcuvwxyz!'
))
self
.
assertEqual
(
s
,
str
(
'abcuvwxyz!'
))
self
.
assertEqual
(
type
(
s
),
types
.
UnicodeType
)
self
.
assertEqual
(
type
(
s
),
str
)
class
TestcStringIO
(
TestGenericStringIO
):
class
TestcStringIO
(
TestGenericStringIO
,
unittest
.
TestCase
):
MODULE
=
cStringIO
MODULE
=
cStringIO
constructor
=
str8
def
test_unicode
(
self
):
def
test_unicode
(
self
):
...
@@ -133,36 +134,39 @@ class TestcStringIO(TestGenericStringIO):
...
@@ -133,36 +134,39 @@ class TestcStringIO(TestGenericStringIO):
f
.
write
(
str
(
self
.
_line
[:
5
]))
f
.
write
(
str
(
self
.
_line
[:
5
]))
s
=
f
.
getvalue
()
s
=
f
.
getvalue
()
self
.
assertEqual
(
s
,
'abcde'
)
self
.
assertEqual
(
s
,
'abcde'
)
self
.
assertEqual
(
type
(
s
),
types
.
StringType
)
self
.
assertEqual
(
type
(
s
),
str8
)
f
=
self
.
MODULE
.
StringIO
(
str
(
self
.
_line
[:
5
]))
f
=
self
.
MODULE
.
StringIO
(
str
(
self
.
_line
[:
5
]))
s
=
f
.
getvalue
()
s
=
f
.
getvalue
()
self
.
assertEqual
(
s
,
'abcde'
)
self
.
assertEqual
(
s
,
'abcde'
)
self
.
assertEqual
(
type
(
s
),
types
.
StringType
)
self
.
assertEqual
(
type
(
s
),
str8
)
self
.
assertRaises
(
UnicodeEncodeError
,
self
.
MODULE
.
StringIO
,
str
(
'
\xf4
'
,
'latin-1'
))
import
sys
# XXX This no longer fails -- the default encoding is always UTF-8.
if
sys
.
platform
.
startswith
(
'java'
):
##self.assertRaises(UnicodeDecodeError, self.MODULE.StringIO, '\xf4')
# Jython doesn't have a buffer object, so we just do a useless
# fake of the buffer tests.
buffer
=
str
class
TestBufferStringIO
(
TestStringIO
):
class
TestBufferStringIO
(
TestStringIO
):
constructor
=
buffer
def
constructor
(
self
,
s
):
return
buffer
(
str8
(
s
))
class
TestBuffercStringIO
(
TestcStringIO
):
class
TestBuffercStringIO
(
TestcStringIO
):
constructor
=
buffer
def
constructor
(
self
,
s
):
return
buffer
(
str8
(
s
))
def
test_main
():
def
test_main
():
test_support
.
run_unittest
(
classes
=
[
TestStringIO
,
TestStringIO
,
TestcStringIO
,
TestcStringIO
,
]
if
not
sys
.
platform
.
startswith
(
'java'
):
classes
.
extend
([
TestBufferStringIO
,
TestBufferStringIO
,
TestBuffercStringIO
TestBuffercStringIO
)
])
test_support
.
run_unittest
(
*
classes
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
test_
main
()
unittest
.
main
()
Objects/bufferobject.c
Dosyayı görüntüle @
bc14efbd
...
@@ -424,15 +424,24 @@ buffer_concat(PyBufferObject *self, PyObject *other)
...
@@ -424,15 +424,24 @@ buffer_concat(PyBufferObject *self, PyObject *other)
return
NULL
;
return
NULL
;
/* optimize special case */
/* optimize special case */
/* XXX bad idea type-wise */
if
(
size
==
0
)
if
(
size
==
0
)
{
{
Py_INCREF
(
other
);
Py_INCREF
(
other
);
return
other
;
return
other
;
}
}
if
(
(
count
=
(
*
pb
->
bf_getreadbuffer
)(
other
,
0
,
&
ptr2
))
<
0
)
if
(
PyUnicode_Check
(
other
))
{
return
NULL
;
/* XXX HACK */
if
(
(
count
=
(
*
pb
->
bf_getcharbuffer
)(
other
,
0
,
&
ptr2
))
<
0
)
return
NULL
;
}
else
{
if
(
(
count
=
(
*
pb
->
bf_getreadbuffer
)(
other
,
0
,
&
ptr2
))
<
0
)
return
NULL
;
}
/* XXX Should return a bytes object, really */
ob
=
PyString_FromStringAndSize
(
NULL
,
size
+
count
);
ob
=
PyString_FromStringAndSize
(
NULL
,
size
+
count
);
if
(
ob
==
NULL
)
if
(
ob
==
NULL
)
return
NULL
;
return
NULL
;
...
...
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