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
7c316a18
Commit
7c316a18
authored
Mar 25, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Check that failed writerow() doesn't produce change a file.
parents
b20f905f
0b4e355b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
14 deletions
+16
-14
Lib/test/test_csv.py
Lib/test/test_csv.py
+16
-14
No files found.
Lib/test/test_csv.py
View file @
7c316a18
...
@@ -124,12 +124,19 @@ class Test_Csv(unittest.TestCase):
...
@@ -124,12 +124,19 @@ class Test_Csv(unittest.TestCase):
self
.
assertEqual
(
fileobj
.
read
(),
self
.
assertEqual
(
fileobj
.
read
(),
expect
+
writer
.
dialect
.
lineterminator
)
expect
+
writer
.
dialect
.
lineterminator
)
def
_write_error_test
(
self
,
exc
,
fields
,
**
kwargs
):
with
TemporaryFile
(
"w+"
,
newline
=
''
)
as
fileobj
:
writer
=
csv
.
writer
(
fileobj
,
**
kwargs
)
with
self
.
assertRaises
(
exc
):
writer
.
writerow
(
fields
)
fileobj
.
seek
(
0
)
self
.
assertEqual
(
fileobj
.
read
(),
''
)
def
test_write_arg_valid
(
self
):
def
test_write_arg_valid
(
self
):
self
.
assertRaises
(
csv
.
Error
,
self
.
_write_test
,
None
,
''
)
self
.
_write_error_test
(
csv
.
Error
,
None
)
self
.
_write_test
((),
''
)
self
.
_write_test
((),
''
)
self
.
_write_test
([
None
],
'""'
)
self
.
_write_test
([
None
],
'""'
)
self
.
assertRaises
(
csv
.
Error
,
self
.
_write_test
,
self
.
_write_error_test
(
csv
.
Error
,
[
None
],
quoting
=
csv
.
QUOTE_NONE
)
[
None
],
None
,
quoting
=
csv
.
QUOTE_NONE
)
# Check that exceptions are passed up the chain
# Check that exceptions are passed up the chain
class
BadList
:
class
BadList
:
def
__len__
(
self
):
def
__len__
(
self
):
...
@@ -137,11 +144,11 @@ class Test_Csv(unittest.TestCase):
...
@@ -137,11 +144,11 @@ class Test_Csv(unittest.TestCase):
def
__getitem__
(
self
,
i
):
def
__getitem__
(
self
,
i
):
if
i
>
2
:
if
i
>
2
:
raise
OSError
raise
OSError
self
.
assertRaises
(
OSError
,
self
.
_write_test
,
BadList
(),
''
)
self
.
_write_error_test
(
OSError
,
BadList
()
)
class
BadItem
:
class
BadItem
:
def
__str__
(
self
):
def
__str__
(
self
):
raise
OSError
raise
OSError
self
.
assertRaises
(
OSError
,
self
.
_write_test
,
[
BadItem
()],
''
)
self
.
_write_error_test
(
OSError
,
[
BadItem
()]
)
def
test_write_bigfield
(
self
):
def
test_write_bigfield
(
self
):
# This exercises the buffer realloc functionality
# This exercises the buffer realloc functionality
...
@@ -151,10 +158,8 @@ class Test_Csv(unittest.TestCase):
...
@@ -151,10 +158,8 @@ class Test_Csv(unittest.TestCase):
def
test_write_quoting
(
self
):
def
test_write_quoting
(
self
):
self
.
_write_test
([
'a'
,
1
,
'p,q'
],
'a,1,"p,q"'
)
self
.
_write_test
([
'a'
,
1
,
'p,q'
],
'a,1,"p,q"'
)
self
.
assertRaises
(
csv
.
Error
,
self
.
_write_error_test
(
csv
.
Error
,
[
'a'
,
1
,
'p,q'
],
self
.
_write_test
,
quoting
=
csv
.
QUOTE_NONE
)
[
'a'
,
1
,
'p,q'
],
'a,1,p,q'
,
quoting
=
csv
.
QUOTE_NONE
)
self
.
_write_test
([
'a'
,
1
,
'p,q'
],
'a,1,"p,q"'
,
self
.
_write_test
([
'a'
,
1
,
'p,q'
],
'a,1,"p,q"'
,
quoting
=
csv
.
QUOTE_MINIMAL
)
quoting
=
csv
.
QUOTE_MINIMAL
)
self
.
_write_test
([
'a'
,
1
,
'p,q'
],
'"a",1,"p,q"'
,
self
.
_write_test
([
'a'
,
1
,
'p,q'
],
'"a",1,"p,q"'
,
...
@@ -167,10 +172,8 @@ class Test_Csv(unittest.TestCase):
...
@@ -167,10 +172,8 @@ class Test_Csv(unittest.TestCase):
def
test_write_escape
(
self
):
def
test_write_escape
(
self
):
self
.
_write_test
([
'a'
,
1
,
'p,q'
],
'a,1,"p,q"'
,
self
.
_write_test
([
'a'
,
1
,
'p,q'
],
'a,1,"p,q"'
,
escapechar
=
'
\
\
'
)
escapechar
=
'
\
\
'
)
self
.
assertRaises
(
csv
.
Error
,
self
.
_write_error_test
(
csv
.
Error
,
[
'a'
,
1
,
'p,"q"'
],
self
.
_write_test
,
escapechar
=
None
,
doublequote
=
False
)
[
'a'
,
1
,
'p,"q"'
],
'a,1,"p,
\
\
"q
\
\
""'
,
escapechar
=
None
,
doublequote
=
False
)
self
.
_write_test
([
'a'
,
1
,
'p,"q"'
],
'a,1,"p,
\
\
"q
\
\
""'
,
self
.
_write_test
([
'a'
,
1
,
'p,"q"'
],
'a,1,"p,
\
\
"q
\
\
""'
,
escapechar
=
'
\
\
'
,
doublequote
=
False
)
escapechar
=
'
\
\
'
,
doublequote
=
False
)
self
.
_write_test
([
'"'
],
'""""'
,
self
.
_write_test
([
'"'
],
'""""'
,
...
@@ -1073,7 +1076,6 @@ class TestUnicode(unittest.TestCase):
...
@@ -1073,7 +1076,6 @@ class TestUnicode(unittest.TestCase):
self
.
assertEqual
(
fileobj
.
read
(),
expected
)
self
.
assertEqual
(
fileobj
.
read
(),
expected
)
def
test_main
():
def
test_main
():
mod
=
sys
.
modules
[
__name__
]
mod
=
sys
.
modules
[
__name__
]
support
.
run_unittest
(
support
.
run_unittest
(
...
...
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