forked from kartoza/GeoContextQGISPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_suite.py
70 lines (58 loc) · 1.89 KB
/
test_suite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
import os
import unittest
import qgis # NOQA For SIP API to V2 if run outside of QGIS
try:
from pip import main as pipmain
except ImportError:
from pip._internal import main as pipmain
try:
import coverage
except ImportError:
pipmain(['install', 'coverage'])
import coverage
import tempfile
from osgeo import gdal
from qgis.PyQt import Qt
from qgis.core import Qgis
def _run_tests(test_suite, package_name, with_coverage=False):
"""Core function to test a test suite."""
count = test_suite.countTestCases()
version = str(Qgis.QGIS_VERSION_INT)
version = int(version)
print('########')
print('%s tests has been discovered in %s' % (count, package_name))
print('QGIS : %s' % version)
print('Python GDAL : %s' % gdal.VersionInfo('VERSION_NUM'))
print('QT : %s' % Qt.QT_VERSION_STR)
print('Run slow tests : %s' % (not os.environ.get('ON_TRAVIS', False)))
print('########')
if with_coverage:
cov = coverage.Coverage(
source=['./'],
omit=['*/test/*', './definitions/*'],
)
cov.start()
unittest.TextTestRunner(verbosity=3, stream=sys.stdout).run(test_suite)
if with_coverage:
cov.stop()
cov.save()
report = tempfile.NamedTemporaryFile(delete=False)
cov.report(file=report)
# Produce HTML reports in the `htmlcov` folder and open index.html
# cov.html_report()
report.close()
with open(report.name, 'r') as fin:
print(fin.read())
def test_package(package='test'):
"""Test package.
This function is called by travis without arguments.
:param package: The package to test.
:type package: str
"""
test_loader = unittest.defaultTestLoader
try:
test_suite = test_loader.discover(package)
except ImportError:
test_suite = unittest.TestSuite()
_run_tests(test_suite, package)