Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
75c9e25f
Commit
75c9e25f
authored
Nov 24, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #15204: Silence and check the 'U' mode deprecation warnings in tests.
Changed deprecation message in the fileinput module.
parent
d80a13cd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
13 deletions
+33
-13
Lib/fileinput.py
Lib/fileinput.py
+1
-1
Lib/test/test_codecs.py
Lib/test/test_codecs.py
+3
-1
Lib/test/test_fileinput.py
Lib/test/test_fileinput.py
+5
-3
Lib/test/test_io.py
Lib/test/test_io.py
+2
-1
Lib/test/test_zipfile.py
Lib/test/test_zipfile.py
+22
-7
No files found.
Lib/fileinput.py
View file @
75c9e25f
...
@@ -224,7 +224,7 @@ class FileInput:
...
@@ -224,7 +224,7 @@ class FileInput:
"'r', 'rU', 'U' and 'rb'"
)
"'r', 'rU', 'U' and 'rb'"
)
if
'U'
in
mode
:
if
'U'
in
mode
:
import
warnings
import
warnings
warnings
.
warn
(
"
Use of
'U' mode is deprecated"
,
warnings
.
warn
(
"'U' mode is deprecated"
,
DeprecationWarning
,
2
)
DeprecationWarning
,
2
)
self
.
_mode
=
mode
self
.
_mode
=
mode
if
openhook
:
if
openhook
:
...
...
Lib/test/test_codecs.py
View file @
75c9e25f
...
@@ -602,7 +602,9 @@ class UTF16Test(ReadTest, unittest.TestCase):
...
@@ -602,7 +602,9 @@ class UTF16Test(ReadTest, unittest.TestCase):
self
.
addCleanup
(
support
.
unlink
,
support
.
TESTFN
)
self
.
addCleanup
(
support
.
unlink
,
support
.
TESTFN
)
with
open
(
support
.
TESTFN
,
'wb'
)
as
fp
:
with
open
(
support
.
TESTFN
,
'wb'
)
as
fp
:
fp
.
write
(
s
)
fp
.
write
(
s
)
with
codecs
.
open
(
support
.
TESTFN
,
'U'
,
encoding
=
self
.
encoding
)
as
reader
:
with
support
.
check_warnings
((
''
,
DeprecationWarning
)):
reader
=
codecs
.
open
(
support
.
TESTFN
,
'U'
,
encoding
=
self
.
encoding
)
with
reader
:
self
.
assertEqual
(
reader
.
read
(),
s1
)
self
.
assertEqual
(
reader
.
read
(),
s1
)
class
UTF16LETest
(
ReadTest
,
unittest
.
TestCase
):
class
UTF16LETest
(
ReadTest
,
unittest
.
TestCase
):
...
...
Lib/test/test_fileinput.py
View file @
75c9e25f
...
@@ -22,7 +22,7 @@ except ImportError:
...
@@ -22,7 +22,7 @@ except ImportError:
from
io
import
StringIO
from
io
import
StringIO
from
fileinput
import
FileInput
,
hook_encoded
from
fileinput
import
FileInput
,
hook_encoded
from
test.support
import
verbose
,
TESTFN
,
run_unittest
from
test.support
import
verbose
,
TESTFN
,
run_unittest
,
check_warnings
from
test.support
import
unlink
as
safe_unlink
from
test.support
import
unlink
as
safe_unlink
...
@@ -224,8 +224,10 @@ class FileInputTests(unittest.TestCase):
...
@@ -224,8 +224,10 @@ class FileInputTests(unittest.TestCase):
try
:
try
:
# try opening in universal newline mode
# try opening in universal newline mode
t1
=
writeTmp
(
1
,
[
b"A
\
n
B
\
r
\
n
C
\
r
D"
],
mode
=
"wb"
)
t1
=
writeTmp
(
1
,
[
b"A
\
n
B
\
r
\
n
C
\
r
D"
],
mode
=
"wb"
)
fi
=
FileInput
(
files
=
t1
,
mode
=
"U"
)
with
check_warnings
((
''
,
DeprecationWarning
)):
lines
=
list
(
fi
)
fi
=
FileInput
(
files
=
t1
,
mode
=
"U"
)
with
check_warnings
((
''
,
DeprecationWarning
)):
lines
=
list
(
fi
)
self
.
assertEqual
(
lines
,
[
"A
\
n
"
,
"B
\
n
"
,
"C
\
n
"
,
"D"
])
self
.
assertEqual
(
lines
,
[
"A
\
n
"
,
"B
\
n
"
,
"C
\
n
"
,
"D"
])
finally
:
finally
:
remove_tempfiles
(
t1
)
remove_tempfiles
(
t1
)
...
...
Lib/test/test_io.py
View file @
75c9e25f
...
@@ -2777,7 +2777,8 @@ class MiscIOTest(unittest.TestCase):
...
@@ -2777,7 +2777,8 @@ class MiscIOTest(unittest.TestCase):
self
.
assertEqual
(
f
.
mode
,
"wb"
)
self
.
assertEqual
(
f
.
mode
,
"wb"
)
f
.
close
()
f
.
close
()
f
=
self
.
open
(
support
.
TESTFN
,
"U"
)
with
support
.
check_warnings
((
''
,
DeprecationWarning
)):
f
=
self
.
open
(
support
.
TESTFN
,
"U"
)
self
.
assertEqual
(
f
.
name
,
support
.
TESTFN
)
self
.
assertEqual
(
f
.
name
,
support
.
TESTFN
)
self
.
assertEqual
(
f
.
buffer
.
name
,
support
.
TESTFN
)
self
.
assertEqual
(
f
.
buffer
.
name
,
support
.
TESTFN
)
self
.
assertEqual
(
f
.
buffer
.
raw
.
name
,
support
.
TESTFN
)
self
.
assertEqual
(
f
.
buffer
.
raw
.
name
,
support
.
TESTFN
)
...
...
Lib/test/test_zipfile.py
View file @
75c9e25f
...
@@ -14,7 +14,7 @@ from random import randint, random, getrandbits
...
@@ -14,7 +14,7 @@ from random import randint, random, getrandbits
from
test.support
import
(
TESTFN
,
findfile
,
unlink
,
from
test.support
import
(
TESTFN
,
findfile
,
unlink
,
requires_zlib
,
requires_bz2
,
requires_lzma
,
requires_zlib
,
requires_bz2
,
requires_lzma
,
captured_stdout
)
captured_stdout
,
check_warnings
)
TESTFN2
=
TESTFN
+
"2"
TESTFN2
=
TESTFN
+
"2"
TESTFNDIR
=
TESTFN
+
"d"
TESTFNDIR
=
TESTFN
+
"d"
...
@@ -35,6 +35,10 @@ def get_files(test):
...
@@ -35,6 +35,10 @@ def get_files(test):
yield
f
yield
f
test
.
assertFalse
(
f
.
closed
)
test
.
assertFalse
(
f
.
closed
)
def
openU
(
zipfp
,
fn
):
with
check_warnings
((
''
,
DeprecationWarning
)):
return
zipfp
.
open
(
fn
,
'rU'
)
class
AbstractTestsWithSourceFile
:
class
AbstractTestsWithSourceFile
:
@
classmethod
@
classmethod
def
setUpClass
(
cls
):
def
setUpClass
(
cls
):
...
@@ -875,6 +879,17 @@ class OtherTests(unittest.TestCase):
...
@@ -875,6 +879,17 @@ class OtherTests(unittest.TestCase):
data
+=
zipfp
.
read
(
info
)
data
+=
zipfp
.
read
(
info
)
self
.
assertIn
(
data
,
{
b"foobar"
,
b"barfoo"
})
self
.
assertIn
(
data
,
{
b"foobar"
,
b"barfoo"
})
def
test_universal_deprecation
(
self
):
f
=
io
.
BytesIO
()
with
zipfile
.
ZipFile
(
f
,
"w"
)
as
zipfp
:
zipfp
.
writestr
(
'spam.txt'
,
b'ababagalamaga'
)
with
zipfile
.
ZipFile
(
f
,
"r"
)
as
zipfp
:
for
mode
in
'U'
,
'rU'
:
with
self
.
assertWarns
(
DeprecationWarning
):
zipopen
=
zipfp
.
open
(
'spam.txt'
,
mode
)
zipopen
.
close
()
def
test_universal_readaheads
(
self
):
def
test_universal_readaheads
(
self
):
f
=
io
.
BytesIO
()
f
=
io
.
BytesIO
()
...
@@ -884,7 +899,7 @@ class OtherTests(unittest.TestCase):
...
@@ -884,7 +899,7 @@ class OtherTests(unittest.TestCase):
data2
=
b''
data2
=
b''
with
zipfile
.
ZipFile
(
f
,
'r'
)
as
zipfp
,
\
with
zipfile
.
ZipFile
(
f
,
'r'
)
as
zipfp
,
\
zipfp
.
open
(
TESTFN
,
'rU'
)
as
zipopen
:
openU
(
zipfp
,
TESTFN
)
as
zipopen
:
for
line
in
zipopen
:
for
line
in
zipopen
:
data2
+=
line
data2
+=
line
...
@@ -1613,7 +1628,7 @@ class AbstractUniversalNewlineTests:
...
@@ -1613,7 +1628,7 @@ class AbstractUniversalNewlineTests:
# Read the ZIP archive
# Read the ZIP archive
with
zipfile
.
ZipFile
(
f
,
"r"
)
as
zipfp
:
with
zipfile
.
ZipFile
(
f
,
"r"
)
as
zipfp
:
for
sep
,
fn
in
self
.
arcfiles
.
items
():
for
sep
,
fn
in
self
.
arcfiles
.
items
():
with
zipfp
.
open
(
fn
,
"rU"
)
as
fp
:
with
openU
(
zipfp
,
fn
)
as
fp
:
zipdata
=
fp
.
read
()
zipdata
=
fp
.
read
()
self
.
assertEqual
(
self
.
arcdata
[
sep
],
zipdata
)
self
.
assertEqual
(
self
.
arcdata
[
sep
],
zipdata
)
...
@@ -1627,7 +1642,7 @@ class AbstractUniversalNewlineTests:
...
@@ -1627,7 +1642,7 @@ class AbstractUniversalNewlineTests:
# Read the ZIP archive
# Read the ZIP archive
with
zipfile
.
ZipFile
(
f
,
"r"
)
as
zipfp
:
with
zipfile
.
ZipFile
(
f
,
"r"
)
as
zipfp
:
for
sep
,
fn
in
self
.
arcfiles
.
items
():
for
sep
,
fn
in
self
.
arcfiles
.
items
():
with
zipfp
.
open
(
fn
,
"rU"
)
as
zipopen
:
with
openU
(
zipfp
,
fn
)
as
zipopen
:
data
=
b''
data
=
b''
while
True
:
while
True
:
read
=
zipopen
.
readline
()
read
=
zipopen
.
readline
()
...
@@ -1652,7 +1667,7 @@ class AbstractUniversalNewlineTests:
...
@@ -1652,7 +1667,7 @@ class AbstractUniversalNewlineTests:
# Read the ZIP archive
# Read the ZIP archive
with
zipfile
.
ZipFile
(
f
,
"r"
)
as
zipfp
:
with
zipfile
.
ZipFile
(
f
,
"r"
)
as
zipfp
:
for
sep
,
fn
in
self
.
arcfiles
.
items
():
for
sep
,
fn
in
self
.
arcfiles
.
items
():
with
zipfp
.
open
(
fn
,
"rU"
)
as
zipopen
:
with
openU
(
zipfp
,
fn
)
as
zipopen
:
for
line
in
self
.
line_gen
:
for
line
in
self
.
line_gen
:
linedata
=
zipopen
.
readline
()
linedata
=
zipopen
.
readline
()
self
.
assertEqual
(
linedata
,
line
+
b'
\
n
'
)
self
.
assertEqual
(
linedata
,
line
+
b'
\
n
'
)
...
@@ -1667,7 +1682,7 @@ class AbstractUniversalNewlineTests:
...
@@ -1667,7 +1682,7 @@ class AbstractUniversalNewlineTests:
# Read the ZIP archive
# Read the ZIP archive
with
zipfile
.
ZipFile
(
f
,
"r"
)
as
zipfp
:
with
zipfile
.
ZipFile
(
f
,
"r"
)
as
zipfp
:
for
sep
,
fn
in
self
.
arcfiles
.
items
():
for
sep
,
fn
in
self
.
arcfiles
.
items
():
with
zipfp
.
open
(
fn
,
"rU"
)
as
fp
:
with
openU
(
zipfp
,
fn
)
as
fp
:
ziplines
=
fp
.
readlines
()
ziplines
=
fp
.
readlines
()
for
line
,
zipline
in
zip
(
self
.
line_gen
,
ziplines
):
for
line
,
zipline
in
zip
(
self
.
line_gen
,
ziplines
):
self
.
assertEqual
(
zipline
,
line
+
b'
\
n
'
)
self
.
assertEqual
(
zipline
,
line
+
b'
\
n
'
)
...
@@ -1682,7 +1697,7 @@ class AbstractUniversalNewlineTests:
...
@@ -1682,7 +1697,7 @@ class AbstractUniversalNewlineTests:
# Read the ZIP archive
# Read the ZIP archive
with
zipfile
.
ZipFile
(
f
,
"r"
)
as
zipfp
:
with
zipfile
.
ZipFile
(
f
,
"r"
)
as
zipfp
:
for
sep
,
fn
in
self
.
arcfiles
.
items
():
for
sep
,
fn
in
self
.
arcfiles
.
items
():
with
zipfp
.
open
(
fn
,
"rU"
)
as
fp
:
with
openU
(
zipfp
,
fn
)
as
fp
:
for
line
,
zipline
in
zip
(
self
.
line_gen
,
fp
):
for
line
,
zipline
in
zip
(
self
.
line_gen
,
fp
):
self
.
assertEqual
(
zipline
,
line
+
b'
\
n
'
)
self
.
assertEqual
(
zipline
,
line
+
b'
\
n
'
)
...
...
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