c.library.cli: use csv module for check_library

- use the builtin csv module for check_library output
- enable the comma-escaping test in test_cli
This commit is contained in:
James Broadhead 2016-12-05 11:19:18 +00:00
parent fd70317171
commit 0dd2c54510
2 changed files with 8 additions and 5 deletions

View File

@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
Command line interface to the calibre database.
'''
import sys, os, cStringIO, re
import cStringIO, csv, os, re, sys
import unicodedata
from textwrap import TextWrapper
from optparse import OptionValueError, OptionGroup
@ -1379,9 +1379,13 @@ def _print_check_library_results(checker, check, opts):
list = getattr(checker, attr, None)
if list is None:
return
if opts.csv:
for i in list:
print check[1] + ',' + i[0] + ',' + i[1]
to_output = [(check[1], i[0], i[1]) for i in list]
csv_print = csv.writer(sys.stdout)
for line in to_output:
csv_print.writerow(line)
else:
print check[1]
for i in list:

View File

@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
'''
Test the CLI of the calibre database management tool
'''
import csv, sys
import csv
import unittest
from StringIO import StringIO
@ -88,7 +88,6 @@ class PrintCheckLibraryResultsTest(unittest.TestCase):
"""
Test more complex csv output
"""
raise unittest.SkipTest('This test fails, as csv output does not currently escape')
checker = Mock(name='checker', speck=CheckLibrary)
data = [['I, Caesar', 'second']]
opts = Mock()