summaryrefslogtreecommitdiff
path: root/Lib/test/test_csv.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-12-11 22:31:09 -0800
committerRaymond Hettinger <python@rcn.com>2011-12-11 22:31:09 -0800
commitf537702732f9107da701794782bb9f037edb1200 (patch)
tree95b6bbb3d46b2d218864f2d4305a628c0fecff46 /Lib/test/test_csv.py
parent8b59c23a54a053673c07c6939cccef096d856103 (diff)
downloadcpython-git-f537702732f9107da701794782bb9f037edb1200.tar.gz
Issue #13573: The csv.writer now uses the repr() for floats rather than str().
Diffstat (limited to 'Lib/test/test_csv.py')
-rw-r--r--Lib/test/test_csv.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py
index 7b16e2db64..681cfd8e85 100644
--- a/Lib/test/test_csv.py
+++ b/Lib/test/test_csv.py
@@ -207,6 +207,18 @@ class Test_Csv(unittest.TestCase):
fileobj.close()
os.unlink(name)
+ def test_write_float(self):
+ # Issue 13573: loss of precision because csv.writer
+ # uses str() for floats instead of repr()
+ orig_row = [1.234567890123, 1.0/7.0, 'abc']
+ f = StringIO()
+ c = csv.writer(f, quoting=csv.QUOTE_NONNUMERIC)
+ c.writerow(orig_row)
+ f.seek(0)
+ c = csv.reader(f, quoting=csv.QUOTE_NONNUMERIC)
+ new_row = next(c)
+ self.assertEqual(orig_row, new_row)
+
def _read_test(self, input, expect, **kwargs):
reader = csv.reader(input, **kwargs)
result = list(reader)
@@ -784,7 +796,7 @@ class TestArrayWrites(unittest.TestCase):
try:
writer = csv.writer(fileobj, dialect="excel")
writer.writerow(a)
- expected = ",".join([str(i) for i in a])+"\r\n"
+ expected = ",".join([repr(i) for i in a])+"\r\n"
fileobj.seek(0)
self.assertEqual(fileobj.read(), expected)
finally:
@@ -800,7 +812,7 @@ class TestArrayWrites(unittest.TestCase):
try:
writer = csv.writer(fileobj, dialect="excel")
writer.writerow(a)
- expected = ",".join([str(i) for i in a])+"\r\n"
+ expected = ",".join([repr(i) for i in a])+"\r\n"
fileobj.seek(0)
self.assertEqual(fileobj.read(), expected)
finally: