mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Get rid of mock
Shaves several seconds of the CI builds
This commit is contained in:
parent
438d331e86
commit
1371f6c858
@ -25,8 +25,6 @@ before_install:
|
|||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo mkdir -p $SWBASE && sudo chown $USER $SWBASE; fi
|
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo mkdir -p $SWBASE && sudo chown $USER $SWBASE; fi
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl https://download.calibre-ebook.com/travis/sw-osx.tar.bz2 | tar xj -C $SWBASE; fi
|
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl https://download.calibre-ebook.com/travis/sw-osx.tar.bz2 | tar xj -C $SWBASE; fi
|
||||||
- npm install --no-optional rapydscript-ng && echo $PATH && which rapydscript && rapydscript --version
|
- npm install --no-optional rapydscript-ng && echo $PATH && which rapydscript && rapydscript --version
|
||||||
- python $SW/bin/easy_install --user "pip==9.0.1"
|
|
||||||
- pip install --user -r requirements.txt
|
|
||||||
- python setup.py bootstrap --ephemeral
|
- python setup.py bootstrap --ephemeral
|
||||||
|
|
||||||
script: python setup.py test
|
script: python setup.py test
|
||||||
|
@ -20,8 +20,6 @@ platform:
|
|||||||
|
|
||||||
before_build:
|
before_build:
|
||||||
- C:\Python35-x64\python.exe setup/win-ci.py sw
|
- C:\Python35-x64\python.exe setup/win-ci.py sw
|
||||||
- C:\sw\private\python\easy_install.exe --user "pip==9.0.1"
|
|
||||||
- C:\sw\private\python\pip install --user -r requirements.txt
|
|
||||||
|
|
||||||
build_script:
|
build_script:
|
||||||
- C:\sw\private\python\python.exe setup/win-ci.py build
|
- C:\sw\private\python\python.exe setup/win-ci.py build
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
# Note, this file is work-in-progress, and is partial only.
|
|
||||||
mock==2.0.0
|
|
@ -267,6 +267,8 @@ class DevNull(object):
|
|||||||
|
|
||||||
def write(self, msg):
|
def write(self, msg):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
NULL = DevNull()
|
NULL = DevNull()
|
||||||
|
|
||||||
|
|
||||||
@ -1362,7 +1364,6 @@ def command_check_library(args, dbpath):
|
|||||||
else:
|
else:
|
||||||
exts = [f.strip() for f in opts.exts.split(',') if f.strip()]
|
exts = [f.strip() for f in opts.exts.split(',') if f.strip()]
|
||||||
|
|
||||||
|
|
||||||
if not LibraryDatabase.exists_at(dbpath):
|
if not LibraryDatabase.exists_at(dbpath):
|
||||||
prints('No library found at', dbpath, file=sys.stderr)
|
prints('No library found at', dbpath, file=sys.stderr)
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
@ -1371,25 +1372,25 @@ def command_check_library(args, dbpath):
|
|||||||
checker = CheckLibrary(dbpath, db)
|
checker = CheckLibrary(dbpath, db)
|
||||||
checker.scan_library(names, exts)
|
checker.scan_library(names, exts)
|
||||||
for check in checks:
|
for check in checks:
|
||||||
_print_check_library_results(checker, check, opts)
|
_print_check_library_results(checker, check, as_csv=opts.csv)
|
||||||
|
|
||||||
|
|
||||||
def _print_check_library_results(checker, check, opts):
|
def _print_check_library_results(checker, check, as_csv=False, out=sys.stdout):
|
||||||
attr = check[0]
|
attr = check[0]
|
||||||
list = getattr(checker, attr, None)
|
list = getattr(checker, attr, None)
|
||||||
if list is None:
|
if list is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if opts.csv:
|
if as_csv:
|
||||||
to_output = [(check[1], i[0], i[1]) for i in list]
|
to_output = [(check[1], i[0], i[1]) for i in list]
|
||||||
csv_print = csv.writer(sys.stdout)
|
csv_print = csv.writer(out)
|
||||||
for line in to_output:
|
for line in to_output:
|
||||||
csv_print.writerow(line)
|
csv_print.writerow(line)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print check[1]
|
print >>out, check[1]
|
||||||
for i in list:
|
for i in list:
|
||||||
print ' %-40.40s - %-40.40s'%(i[0], i[1])
|
print >>out, ' %-40.40s - %-40.40s'%(i[0], i[1])
|
||||||
|
|
||||||
|
|
||||||
def restore_database_option_parser():
|
def restore_database_option_parser():
|
||||||
@ -1648,6 +1649,7 @@ language, for example: {0}
|
|||||||
help=_('The maximum number of results to return. Default is all results.'))
|
help=_('The maximum number of results to return. Default is all results.'))
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
COMMANDS = ('list', 'add', 'remove', 'add_format', 'remove_format',
|
COMMANDS = ('list', 'add', 'remove', 'add_format', 'remove_format',
|
||||||
'show_metadata', 'set_metadata', 'export', 'catalog',
|
'show_metadata', 'set_metadata', 'export', 'catalog',
|
||||||
'saved_searches', 'add_custom_column', 'custom_columns',
|
'saved_searches', 'add_custom_column', 'custom_columns',
|
||||||
@ -1706,5 +1708,6 @@ def main(args=sys.argv):
|
|||||||
|
|
||||||
return command(args[2:], dbpath)
|
return command(args[2:], dbpath)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
@ -11,53 +11,49 @@ Test the CLI of the calibre database management tool
|
|||||||
'''
|
'''
|
||||||
import csv
|
import csv
|
||||||
import unittest
|
import unittest
|
||||||
from StringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
from mock import Mock, patch
|
|
||||||
|
|
||||||
from calibre.library.check_library import CheckLibrary
|
|
||||||
from calibre.library.cli import _print_check_library_results
|
from calibre.library.cli import _print_check_library_results
|
||||||
|
|
||||||
|
|
||||||
|
class Checker(object):
|
||||||
|
|
||||||
|
def __init__(self, kw):
|
||||||
|
for k, v in kw.iteritems():
|
||||||
|
setattr(self, k, v)
|
||||||
|
|
||||||
|
|
||||||
class PrintCheckLibraryResultsTest(unittest.TestCase):
|
class PrintCheckLibraryResultsTest(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
Asserts the format of the output to the CLI to avoid regressions
|
Asserts the format of the output to the CLI to avoid regressions
|
||||||
"""
|
"""
|
||||||
check_machine_name = 'dummy_check'
|
|
||||||
check_human_name = 'Dummy Check'
|
|
||||||
check = (check_machine_name, check_human_name, True, False)
|
|
||||||
|
|
||||||
@patch('sys.stdout', new_callable=StringIO)
|
check = ('dummy_check', 'Dummy Check')
|
||||||
def test_prints_nothing_if_no_errors(self, mock_stdout):
|
|
||||||
checker = Mock(name='checker', spec=CheckLibrary)
|
|
||||||
setattr(checker, self.check_machine_name, None)
|
|
||||||
opts = Mock()
|
|
||||||
|
|
||||||
opts.csv = False
|
def test_prints_nothing_if_no_errors(self):
|
||||||
_print_check_library_results(checker, self.check, opts)
|
stdout = StringIO()
|
||||||
self.assertEqual(mock_stdout.getvalue(), '')
|
checker = Checker(dict.fromkeys(self.check))
|
||||||
|
_print_check_library_results(checker, self.check, as_csv=False, out=stdout)
|
||||||
|
self.assertEqual(stdout.getvalue(), '')
|
||||||
|
_print_check_library_results(checker, self.check, as_csv=True, out=stdout)
|
||||||
|
self.assertEqual(stdout.getvalue(), '')
|
||||||
|
|
||||||
opts.csv = True
|
def test_human_readable_output(self):
|
||||||
_print_check_library_results(checker, self.check, opts)
|
|
||||||
self.assertEqual(mock_stdout.getvalue(), '')
|
|
||||||
|
|
||||||
@patch('sys.stdout', new_callable=StringIO)
|
|
||||||
def test_human_readable_output(self, mock_stdout):
|
|
||||||
"""
|
"""
|
||||||
Basic check of the human-readable output.
|
Basic check of the human-readable output.
|
||||||
|
|
||||||
Does not test: the full line format, truncation
|
Does not test: the full line format, truncation
|
||||||
"""
|
"""
|
||||||
checker = Mock(name='checker', speck=CheckLibrary)
|
|
||||||
data = [['first', 'second']]
|
data = [['first', 'second']]
|
||||||
opts = Mock()
|
checker = Checker(dict.fromkeys(self.check))
|
||||||
opts.csv = False
|
setattr(checker, self.check[0], data)
|
||||||
setattr(checker, self.check_machine_name, data)
|
stdout = StringIO()
|
||||||
_print_check_library_results(checker, self.check, opts)
|
_print_check_library_results(checker, self.check, out=stdout, as_csv=False)
|
||||||
|
|
||||||
result = mock_stdout.getvalue().split('\n')
|
result = stdout.getvalue().split('\n')
|
||||||
self.assertEqual(len(result), len(data)+2)
|
self.assertEqual(len(result), len(data)+2)
|
||||||
self.assertEqual(result[0], self.check_human_name)
|
self.assertEqual(result[0], self.check[1])
|
||||||
|
|
||||||
result_first = result[1].split('-')[0].strip()
|
result_first = result[1].split('-')[0].strip()
|
||||||
result_second = result[1].split('-')[1].strip()
|
result_second = result[1].split('-')[1].strip()
|
||||||
@ -67,37 +63,33 @@ class PrintCheckLibraryResultsTest(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(result[-1], '')
|
self.assertEqual(result[-1], '')
|
||||||
|
|
||||||
@patch('sys.stdout', new_callable=StringIO)
|
def test_basic_csv_output(self):
|
||||||
def test_basic_csv_output(self, mock_stdout):
|
|
||||||
"""
|
"""
|
||||||
Test simple csv output
|
Test simple csv output
|
||||||
"""
|
"""
|
||||||
checker = Mock(name='checker', speck=CheckLibrary)
|
|
||||||
data = [['first', 'second']]
|
data = [['first', 'second']]
|
||||||
opts = Mock()
|
checker = Checker(dict.fromkeys(self.check))
|
||||||
opts.csv = True
|
setattr(checker, self.check[0], data)
|
||||||
setattr(checker, self.check_machine_name, data)
|
stdout = StringIO()
|
||||||
_print_check_library_results(checker, self.check, opts)
|
_print_check_library_results(checker, self.check, as_csv=True, out=stdout)
|
||||||
|
|
||||||
result = mock_stdout.getvalue().split('\n')
|
result = stdout.getvalue().split('\n')
|
||||||
parsed_result = [l for l in csv.reader(result) if l]
|
parsed_result = [l for l in csv.reader(result) if l]
|
||||||
self.assertEqual(parsed_result, [[self.check_human_name, data[0][0], data[0][1]]])
|
self.assertEqual(parsed_result, [[self.check[1], data[0][0], data[0][1]]])
|
||||||
|
|
||||||
@patch('sys.stdout', new_callable=StringIO)
|
def test_escaped_csv_output(self):
|
||||||
def test_escaped_csv_output(self, mock_stdout):
|
|
||||||
"""
|
"""
|
||||||
Test more complex csv output
|
Test more complex csv output
|
||||||
"""
|
"""
|
||||||
checker = Mock(name='checker', speck=CheckLibrary)
|
|
||||||
data = [['I, Caesar', 'second']]
|
data = [['I, Caesar', 'second']]
|
||||||
opts = Mock()
|
checker = Checker(dict.fromkeys(self.check))
|
||||||
opts.csv = True
|
setattr(checker, self.check[0], data)
|
||||||
setattr(checker, self.check_machine_name, data)
|
stdout = StringIO()
|
||||||
_print_check_library_results(checker, self.check, opts)
|
_print_check_library_results(checker, self.check, as_csv=True, out=stdout)
|
||||||
|
|
||||||
result = mock_stdout.getvalue().split('\n')
|
result = stdout.getvalue().split('\n')
|
||||||
parsed_result = [l for l in csv.reader(result) if l]
|
parsed_result = [l for l in csv.reader(result) if l]
|
||||||
self.assertEqual(parsed_result, [[self.check_human_name, data[0][0], data[0][1]]])
|
self.assertEqual(parsed_result, [[self.check[1], data[0][0], data[0][1]]])
|
||||||
|
|
||||||
|
|
||||||
def find_tests():
|
def find_tests():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user