~jamesodhunt/ubuntu-system-image/system-image-server-remove-slash-android-for-ubuntu-core

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
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (C) 2013 Canonical Ltd.
# Author: Stéphane Graber <stgraber@ubuntu.com>

# This program 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; version 3 of the License.
#
# This program 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/>.

# Dependencies:
#  - python2 (>= 2.7): python-gpgme, python-coverage
#  - python3 (>= 3.2): python3-gpgme

import glob
import os
import re
import shutil
import sys
import unittest

coverage = True
try:
    from coverage import coverage
    cov = coverage()
    cov.start()
except ImportError:
    print("No coverage report, make sure python-coverage is installed")
    coverage = False

sys.path.insert(0, 'lib')

if len(sys.argv) > 1:
    test_filter = sys.argv[1]
else:
    test_filter = ''

tests = [t[:-3] for t in os.listdir('tests')
         if t.startswith('test_') and t.endswith('.py') and
         re.search(test_filter, t)]
tests.sort()
suite = unittest.TestLoader().loadTestsFromNames(tests)
res = unittest.TextTestRunner(verbosity=2).run(suite)

if coverage:
    if os.path.exists('tests/coverage'):
        shutil.rmtree('tests/coverage')
    cov.stop()
    cov.html_report(include=glob.glob("lib/systemimage/*.py"),
                    directory='tests/coverage')
    print("")
    cov.report(include=glob.glob("lib/systemimage/*.py"))