2009-02-25 14:23:03 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# gPodder - A media aggregator and podcast client
|
2018-01-28 19:39:53 +01:00
|
|
|
# Copyright (c) 2005-2018 The gPodder Team
|
2009-02-25 14:23:03 +01:00
|
|
|
#
|
|
|
|
# gPodder is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# gPodder is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
# Run Doctests and Unittests for gPodder modules
|
|
|
|
# 2009-02-25 Thomas Perl <thp@gpodder.org>
|
|
|
|
|
|
|
|
|
|
|
|
import doctest
|
2009-03-24 15:42:39 +01:00
|
|
|
import sys
|
2018-07-24 11:08:10 +02:00
|
|
|
import unittest
|
2009-02-25 14:23:03 +01:00
|
|
|
|
2009-03-24 19:53:19 +01:00
|
|
|
try:
|
2010-05-17 18:26:13 +02:00
|
|
|
# Unused here locally, but we import it to be able to give an early
|
|
|
|
# warning about this missing dependency in order to avoid bogus errors.
|
2009-03-24 19:53:19 +01:00
|
|
|
import minimock
|
2016-11-21 23:13:46 +01:00
|
|
|
except ImportError as e:
|
|
|
|
print("""
|
2009-03-24 19:53:19 +01:00
|
|
|
Error: Unit tests require the "minimock" module (python-minimock).
|
|
|
|
Please install it before running the unit tests.
|
2016-11-21 23:13:46 +01:00
|
|
|
""", file=sys.stderr)
|
2009-03-24 19:53:19 +01:00
|
|
|
sys.exit(2)
|
|
|
|
|
2013-02-12 12:54:12 +01:00
|
|
|
# Main package and test package (for modules in main package)
|
2009-02-25 14:23:03 +01:00
|
|
|
package = 'gpodder'
|
2013-02-12 12:54:12 +01:00
|
|
|
test_package = '.'.join((package, 'test'))
|
2009-02-25 14:23:03 +01:00
|
|
|
|
|
|
|
suite = unittest.TestSuite()
|
2013-02-12 12:54:12 +01:00
|
|
|
coverage_modules = []
|
|
|
|
|
|
|
|
|
|
|
|
# Modules (in gpodder) for which doctests exist
|
|
|
|
# ex: Doctests embedded in "gpodder.util", coverage reported for "gpodder.util"
|
|
|
|
doctest_modules = ['util', 'jsonconfig']
|
|
|
|
|
|
|
|
for module in doctest_modules:
|
|
|
|
doctest_mod = __import__('.'.join((package, module)), fromlist=[module])
|
|
|
|
|
|
|
|
suite.addTest(doctest.DocTestSuite(doctest_mod))
|
|
|
|
coverage_modules.append(doctest_mod)
|
|
|
|
|
|
|
|
|
|
|
|
# Modules (in gpodder) for which unit tests (in gpodder.test) exist
|
|
|
|
# ex: Tests are in "gpodder.test.model", coverage reported for "gpodder.model"
|
|
|
|
test_modules = ['model']
|
|
|
|
|
|
|
|
for module in test_modules:
|
|
|
|
test_mod = __import__('.'.join((test_package, module)), fromlist=[module])
|
|
|
|
coverage_mod = __import__('.'.join((package, module)), fromlist=[module])
|
|
|
|
|
|
|
|
suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(test_mod))
|
|
|
|
coverage_modules.append(coverage_mod)
|
2009-02-25 14:23:03 +01:00
|
|
|
|
2013-02-12 13:03:49 +01:00
|
|
|
try:
|
|
|
|
# If you want a HTML-based test report, install HTMLTestRunner from:
|
|
|
|
# http://tungwaiyip.info/software/HTMLTestRunner.html
|
|
|
|
import HTMLTestRunner
|
|
|
|
REPORT_FILENAME = 'test_report.html'
|
|
|
|
runner = HTMLTestRunner.HTMLTestRunner(stream=open(REPORT_FILENAME, 'w'))
|
2016-11-21 23:13:46 +01:00
|
|
|
print("""
|
2013-02-12 13:03:49 +01:00
|
|
|
HTML Test Report will be written to %s
|
2016-11-21 23:13:46 +01:00
|
|
|
""" % REPORT_FILENAME)
|
2013-02-12 13:03:49 +01:00
|
|
|
except ImportError:
|
|
|
|
runner = unittest.TextTestRunner(verbosity=2)
|
2009-03-24 15:42:39 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
import coverage
|
|
|
|
except ImportError:
|
|
|
|
coverage = None
|
|
|
|
|
2011-07-15 17:38:23 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
if coverage is not None:
|
2015-12-01 21:38:22 +01:00
|
|
|
cov = coverage.Coverage()
|
|
|
|
cov.erase()
|
|
|
|
cov.start()
|
2011-07-15 17:38:23 +02:00
|
|
|
|
|
|
|
result = runner.run(suite)
|
|
|
|
|
|
|
|
if not result.wasSuccessful():
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if coverage is not None:
|
2015-12-01 21:38:22 +01:00
|
|
|
cov.stop()
|
|
|
|
cov.report(coverage_modules)
|
|
|
|
cov.erase()
|
2011-07-15 17:38:23 +02:00
|
|
|
else:
|
2016-11-21 23:13:46 +01:00
|
|
|
print("""
|
2011-07-15 17:38:23 +02:00
|
|
|
No coverage reporting done (Python module "coverage" is missing)
|
|
|
|
Please install the python-coverage package to get coverage reporting.
|
2016-11-21 23:13:46 +01:00
|
|
|
""", file=sys.stderr)
|