Back to index

python3.2  3.2.2
Public Member Functions
test.test_csv.TestDialectRegistry Class Reference

List of all members.

Public Member Functions

def test_registry_badargs
def test_registry
def test_register_kwargs
def test_incomplete_dialect
def test_space_dialect
def compare_dialect_123
def test_dialect_apply
def test_bad_dialect

Detailed Description

Definition at line 291 of file test_csv.py.


Member Function Documentation

def test.test_csv.TestDialectRegistry.compare_dialect_123 (   self,
  expected,
  writeargs,
  kwwriteargs 
)

Definition at line 346 of file test_csv.py.

00346 
00347     def compare_dialect_123(self, expected, *writeargs, **kwwriteargs):
00348 
00349         with TemporaryFile("w+", newline='', encoding="utf-8") as fileobj:
00350 
00351             writer = csv.writer(fileobj, *writeargs, **kwwriteargs)
00352             writer.writerow([1,2,3])
00353             fileobj.seek(0)
00354             self.assertEqual(fileobj.read(), expected)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 379 of file test_csv.py.

00379 
00380     def test_bad_dialect(self):
00381         # Unknown parameter
00382         self.assertRaises(TypeError, csv.reader, [], bad_attr = 0)
00383         # Bad values
00384         self.assertRaises(TypeError, csv.reader, [], delimiter = None)
00385         self.assertRaises(TypeError, csv.reader, [], quoting = -1)
00386         self.assertRaises(TypeError, csv.reader, [], quoting = 100)

Here is the call graph for this function:

Definition at line 355 of file test_csv.py.

00355 
00356     def test_dialect_apply(self):
00357         class testA(csv.excel):
00358             delimiter = "\t"
00359         class testB(csv.excel):
00360             delimiter = ":"
00361         class testC(csv.excel):
00362             delimiter = "|"
00363         class testUni(csv.excel):
00364             delimiter = "\u039B"
00365 
00366         csv.register_dialect('testC', testC)
00367         try:
00368             self.compare_dialect_123("1,2,3\r\n")
00369             self.compare_dialect_123("1\t2\t3\r\n", testA)
00370             self.compare_dialect_123("1:2:3\r\n", dialect=testB())
00371             self.compare_dialect_123("1|2|3\r\n", dialect='testC')
00372             self.compare_dialect_123("1;2;3\r\n", dialect=testA,
00373                                      delimiter=';')
00374             self.compare_dialect_123("1\u039B2\u039B3\r\n",
00375                                      dialect=testUni)
00376 
00377         finally:
00378             csv.unregister_dialect('testC')

Here is the call graph for this function:

Definition at line 328 of file test_csv.py.

00328 
00329     def test_incomplete_dialect(self):
00330         class myexceltsv(csv.Dialect):
00331             delimiter = "\t"
00332         self.assertRaises(csv.Error, myexceltsv)

Here is the call graph for this function:

Definition at line 321 of file test_csv.py.

00321 
00322     def test_register_kwargs(self):
00323         name = 'fedcba'
00324         csv.register_dialect(name, delimiter=';')
00325         self.addCleanup(csv.unregister_dialect, name)
00326         self.assertEqual(csv.get_dialect(name).delimiter, ';')
00327         self.assertEqual([['X', 'Y', 'Z']], list(csv.reader(['X;Y;Z'], name)))

Here is the call graph for this function:

Definition at line 309 of file test_csv.py.

00309 
00310     def test_registry(self):
00311         class myexceltsv(csv.excel):
00312             delimiter = "\t"
00313         name = "myexceltsv"
00314         expected_dialects = csv.list_dialects() + [name]
00315         expected_dialects.sort()
00316         csv.register_dialect(name, myexceltsv)
00317         self.addCleanup(csv.unregister_dialect, name)
00318         self.assertEqual(csv.get_dialect(name).delimiter, '\t')
00319         got_dialects = sorted(csv.list_dialects())
00320         self.assertEqual(expected_dialects, got_dialects)

Here is the call graph for this function:

Definition at line 292 of file test_csv.py.

00292 
00293     def test_registry_badargs(self):
00294         self.assertRaises(TypeError, csv.list_dialects, None)
00295         self.assertRaises(TypeError, csv.get_dialect)
00296         self.assertRaises(csv.Error, csv.get_dialect, None)
00297         self.assertRaises(csv.Error, csv.get_dialect, "nonesuch")
00298         self.assertRaises(TypeError, csv.unregister_dialect)
00299         self.assertRaises(csv.Error, csv.unregister_dialect, None)
00300         self.assertRaises(csv.Error, csv.unregister_dialect, "nonesuch")
00301         self.assertRaises(TypeError, csv.register_dialect, None)
00302         self.assertRaises(TypeError, csv.register_dialect, None, None)
00303         self.assertRaises(TypeError, csv.register_dialect, "nonesuch", 0, 0)
00304         self.assertRaises(TypeError, csv.register_dialect, "nonesuch",
00305                           badargument=None)
00306         self.assertRaises(TypeError, csv.register_dialect, "nonesuch",
00307                           quoting=None)
00308         self.assertRaises(TypeError, csv.register_dialect, [])

Here is the call graph for this function:

Definition at line 333 of file test_csv.py.

00333 
00334     def test_space_dialect(self):
00335         class space(csv.excel):
00336             delimiter = " "
00337             quoting = csv.QUOTE_NONE
00338             escapechar = "\\"
00339 
00340         with TemporaryFile("w+") as fileobj:
00341             fileobj.write("abc def\nc1ccccc1 benzene\n")
00342             fileobj.seek(0)
00343             reader = csv.reader(fileobj, dialect=space())
00344             self.assertEqual(next(reader), ["abc", "def"])
00345             self.assertEqual(next(reader), ["c1ccccc1", "benzene"])

Here is the call graph for this function:


The documentation for this class was generated from the following file: