Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/commands/check
blob: 66e1ed5e9921f637b4bdd87cd43375e0ee0fb0fb (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/python -u

import argparse
import os
import shutil
import sys

import common

from devbot import run
from devbot import check
from devbot import command
from devbot import system
from devbot import build

def _get_profile():
    profile_path = os.path.expanduser("~/.sugar/uitests")
    shutil.rmtree(profile_path, ignore_errors=True)
    return profile_path


def _get_test_path(name):
    return os.path.join(common.base_dir, "tests", "sugar", name)


def _get_python_scripts():
    shebang = "#!/usr/bin/python"
    dirs = ["commands", "tools"]
    scripts = []

    for dir_name in dirs:
        dir_path = os.path.join(common.base_dir, dir_name)
        for name in os.listdir(dir_path):
            script_path = os.path.join(dir_path, name)
            with open(script_path) as f:
                if f.read(len(shebang)) == shebang:
                    scripts.append(script_path)

    return scripts


def _run_pep8():
    args = ["pep8"]

    for dir_name in ["devbot", "tests"]:
        args.append(os.path.join(common.base_dir, dir_name))

    args.extend(_get_python_scripts())

    command.run(args)


def _run_pylint():
    args = ["pylint", "--reports=n", "--disable=C,W,R,E,F", "--enable=W0611"]
    args.append(os.path.join(common.base_dir, "devbot"))
    args.extend(_get_python_scripts())

    command.run(args)


def _run_unittests():
    tests_tmp = os.path.join(common.base_dir, "tests", "tmp")
    try:
        os.mkdir(tests_tmp)
    except OSError:
        pass

    os.environ["TESTS_TMP"] = tests_tmp
    os.environ["PYTHONPATH"] = common.base_dir
    os.chdir(os.path.join(common.base_dir, "tests", "devbot"))

    command.run(["python", "-m", "unittest", "discover"])

    shutil.rmtree(tests_tmp, ignore_errors=True)


def _check_devbot():
    print "* Checking devbot"

    try:
        _run_pep8()
        _run_pylint()
        _run_unittests()
    except subprocess.CalledProcessError:
        return False


def _check_ui():
    print "* Checking UI"

    profile_path = _get_profile()
    result = run.run_test("sugar-runner", _get_test_path("shell.py"))
    run.collect_logs(os.path.join(profile_path, "logs"))

    return result


def _check_modules():
    return check.check()


parser = argparse.ArgumentParser()
parser.add_argument("module", nargs="?", help="name of the module to test")
args = parser.parse_args()

common.setup(log_name="check")

os.environ["SUGAR_LOGGER_LEVEL"] = "debug"
os.environ["SUGAR_PROFILE"] = "uitests"
os.environ["GTK_MODULES"] = "gail:atk-bridge"

if args.module:
    if not check.check_one(args.module):
        sys.exit(1)
else:
    if not system.check(lazy=True):
        sys.exit(1)

    if not build.pull(lazy=True):
        sys.exit(1)

    if not build.build():
        sys.exit(1)

    if not _check_devbot():
        sys.exit(1)

    if not _check_modules():
        sys.exit(1)

    if not _check_ui():
        sys.exit(1)