Lines Matching refs:csv
11 import csv
29 self.assertRaises(csv.Error, ctor, arg, 'foo')
37 quoting=csv.QUOTE_ALL, quotechar='')
39 quoting=csv.QUOTE_ALL, quotechar=None)
42 self._test_arg_valid(csv.reader, [])
45 self._test_arg_valid(csv.writer, StringIO())
55 self.assertEqual(obj.dialect.quoting, csv.QUOTE_MINIMAL)
66 self._test_default_attrs(csv.reader, [])
69 self._test_default_attrs(csv.writer, StringIO())
75 quoting=csv.QUOTE_NONE, skipinitialspace=True,
83 self.assertEqual(obj.dialect.quoting, csv.QUOTE_NONE)
88 self._test_kw_attrs(csv.reader, [])
91 self._test_kw_attrs(csv.writer, StringIO())
101 quoting=csv.QUOTE_ALL
111 self.assertEqual(obj.dialect.quoting, csv.QUOTE_ALL)
116 self._test_dialect_attrs(csv.reader, [])
119 self._test_dialect_attrs(csv.writer, StringIO())
126 writer = csv.writer(fileobj, **kwargs)
139 writer = csv.writer(fileobj, **kwargs)
149 self._write_error_test(csv.Error, None)
152 self._write_error_test(csv.Error, [None], quoting = csv.QUOTE_NONE)
174 self._write_error_test(csv.Error, ['a',1,'p,q'],
175 quoting = csv.QUOTE_NONE)
177 quoting = csv.QUOTE_MINIMAL)
179 quoting = csv.QUOTE_NONNUMERIC)
181 quoting = csv.QUOTE_ALL)
183 quoting = csv.QUOTE_ALL)
188 self._write_error_test(csv.Error, ['a',1,'p,"q"'],
193 escapechar='\\', quoting = csv.QUOTE_MINIMAL)
195 escapechar='\\', quoting = csv.QUOTE_MINIMAL,
198 escapechar='\\', quoting = csv.QUOTE_NONE)
200 escapechar='\\', quoting = csv.QUOTE_NONE)
206 writer = csv.writer(BrokenFile())
211 writer = csv.writer(fileobj)
225 c = csv.writer(f, quoting=csv.QUOTE_NONNUMERIC)
228 c = csv.reader(f, quoting=csv.QUOTE_NONNUMERIC)
233 reader = csv.reader(input, **kwargs)
240 self.assertRaises(csv.Error, self._read_test,
243 self.assertRaises(csv.Error, self._read_test,
252 self.assertRaises(csv.Error, self._read_test, ['a,b\rc,d'], [])
253 self.assertRaises(csv.Error, self._read_test, ['a,b\nc,d'], [])
254 self.assertRaises(csv.Error, self._read_test, ['a,b\r\nc,d'], [])
260 self.assertRaises(csv.Error, self._read_test, ['a,"'], [], strict=True)
261 self.assertRaises(csv.Error, self._read_test, ['"a'], [], strict=True)
262 self.assertRaises(csv.Error, self._read_test,
278 quoting=csv.QUOTE_NONE, escapechar='\\')
281 quoting=csv.QUOTE_NONNUMERIC)
285 quoting=csv.QUOTE_NONNUMERIC)
290 limit = csv.field_size_limit()
296 csv.field_size_limit(size)
298 self.assertEqual(csv.field_size_limit(), size)
299 csv.field_size_limit(size-1)
300 self.assertRaises(csv.Error, self._read_test, [bigline], [])
301 self.assertRaises(TypeError, csv.field_size_limit, None)
302 self.assertRaises(TypeError, csv.field_size_limit, 1, None)
304 csv.field_size_limit(limit)
307 for r in (csv.reader(['line,1', 'line,2', 'line,3']),
308 csv.DictReader(['line,1', 'line,2', 'line,3'],
324 writer = csv.writer(fileobj)
329 for i, row in enumerate(csv.reader(fileobj)):
337 self.assertRaises(TypeError, csv.list_dialects, None)
338 self.assertRaises(TypeError, csv.get_dialect)
339 self.assertRaises(csv.Error, csv.get_dialect, None)
340 self.assertRaises(csv.Error, csv.get_dialect, "nonesuch")
341 self.assertRaises(TypeError, csv.unregister_dialect)
342 self.assertRaises(csv.Error, csv.unregister_dialect, None)
343 self.assertRaises(csv.Error, csv.unregister_dialect, "nonesuch")
344 self.assertRaises(TypeError, csv.register_dialect, None)
345 self.assertRaises(TypeError, csv.register_dialect, None, None)
346 self.assertRaises(TypeError, csv.register_dialect, "nonesuch", 0, 0)
347 self.assertRaises(TypeError, csv.register_dialect, "nonesuch",
349 self.assertRaises(TypeError, csv.register_dialect, "nonesuch",
351 self.assertRaises(TypeError, csv.register_dialect, [])
354 class myexceltsv(csv.excel):
357 expected_dialects = csv.list_dialects() + [name]
359 csv.register_dialect(name, myexceltsv)
360 self.addCleanup(csv.unregister_dialect, name)
361 self.assertEqual(csv.get_dialect(name).delimiter, '\t')
362 got_dialects = sorted(csv.list_dialects())
367 csv.register_dialect(name, delimiter=';')
368 self.addCleanup(csv.unregister_dialect, name)
369 self.assertEqual(csv.get_dialect(name).delimiter, ';')
370 self.assertEqual([['X', 'Y', 'Z']], list(csv.reader(['X;Y;Z'], name)))
373 class myexceltsv(csv.Dialect):
375 self.assertRaises(csv.Error, myexceltsv)
378 class space(csv.excel):
380 quoting = csv.QUOTE_NONE
388 rdr = csv.reader(fileobj, dialect=space())
396 class testA(csv.excel):
398 class testB(csv.excel):
400 class testC(csv.excel):
403 csv.register_dialect('testC', testC)
408 writer = csv.writer(fileobj)
419 writer = csv.writer(fileobj, testA)
430 writer = csv.writer(fileobj, dialect=testB())
441 writer = csv.writer(fileobj, dialect='testC')
452 writer = csv.writer(fileobj, dialect=testA, delimiter=';')
461 csv.unregister_dialect('testC')
465 self.assertRaises(TypeError, csv.reader, [], bad_attr = 0)
467 self.assertRaises(TypeError, csv.reader, [], delimiter = None)
468 self.assertRaises(TypeError, csv.reader, [], quoting = -1)
469 self.assertRaises(TypeError, csv.reader, [], quoting = 100)
490 reader = csv.reader(fileobj, dialect = self.dialect)
501 writer = csv.writer(fileobj, dialect = self.dialect)
606 class EscapedExcel(csv.excel):
607 quoting = csv.QUOTE_NONE
619 class QuotedEscapedExcel(csv.excel):
620 quoting = csv.QUOTE_NONNUMERIC
639 writer = csv.DictWriter(fileobj, fieldnames = ["f1", "f2", "f3"])
653 self.assertRaises(TypeError, csv.DictWriter, fileobj)
659 writer = csv.DictWriter(fileobj, fieldnames = ["f1", "f2", "f3"])
678 reader = csv.DictReader(fileobj,
691 reader = csv.DictReader(fileobj)
706 reader = csv.DictReader(f, fieldnames=csv.reader(f).next())
720 reader = csv.DictReader(f)
735 reader = csv.DictReader(fileobj,
749 reader = csv.DictReader(fileobj,
763 reader = csv.DictReader(fileobj, restkey="_rest")
777 reader = csv.DictReader(fileobj,
796 reader = csv.DictReader(sample,
805 reader = csv.DictReader(["1,2,abc,4,5,6\r\n","\r\n",
814 reader = csv.DictReader(["1;2;abc;4;5;6\r\n"],
829 writer = csv.writer(fileobj, dialect="excel")
845 writer = csv.writer(fileobj, dialect="excel")
861 writer = csv.writer(fileobj, dialect="excel")
876 writer = csv.writer(fileobj, dialect="excel")
887 class mydialect(csv.Dialect):
893 quoting = csv.QUOTE_NONE
895 self.assertEqual(d.quoting, csv.QUOTE_NONE)
898 self.assertRaises(csv.Error, mydialect)
901 mydialect.quoting = csv.QUOTE_ALL
904 self.assertEqual(d.quoting, csv.QUOTE_ALL)
909 with self.assertRaises(csv.Error) as cm:
915 with self.assertRaises(csv.Error) as cm:
921 class mydialect(csv.Dialect):
927 quoting = csv.QUOTE_NONE
932 with self.assertRaises(csv.Error) as cm:
938 with self.assertRaises(csv.Error) as cm:
944 with self.assertRaises(csv.Error) as cm:
950 with self.assertRaises(csv.Error) as cm:
956 class mydialect(csv.Dialect):
962 quoting = csv.QUOTE_NONE
971 with self.assertRaises(csv.Error) as cm:
1028 sniffer = csv.Sniffer()
1034 sniffer = csv.Sniffer()
1040 sniffer = csv.Sniffer()
1049 sniffer = csv.Sniffer()
1061 sniffer = csv.Sniffer()
1087 sniffer = csv.Sniffer()
1114 csv.reader(["a,b,c\r\n"])
1115 csv.reader(["a,b,c\r\n"])
1116 csv.reader(["a,b,c\r\n"])
1130 csv.writer(s)
1131 csv.writer(s)
1132 csv.writer(s)
1146 rdr = csv.reader(rows)
1163 writer = csv.writer(s)