~mago-contributors/mago/chromium

« back to all changes in this revision

Viewing changes to sanitychecks/gen-tests.py

  • Committer: Jean-Baptiste Lallement
  • Date: 2011-01-19 23:21:59 UTC
  • Revision ID: jean-baptiste.lallement@ubuntu.com-20110119232159-sd07rnqwe5hbksui
* Adding in window managers to blacklist
* Test the same binary only once
* More explicite test name
* Wait 3 seconds before closing the application to not stress the system too much

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
 
2
# Copyright (C) 2010 Canonical Ltd
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
""" Generate a basic test for each application listed in 
 
18
/usr/share/applications/desktop.en_US.utf8.cache
 
19
 
 
20
The basic test launches the application, wait for 3 seconds then closes it
 
21
"""
2
22
import ConfigParser
3
 
from re import sub
 
23
from re import sub, search
4
24
import os
5
25
 
6
26
DESKTOPCACHE = "/usr/share/applications/desktop.en_US.utf8.cache"
7
 
BLACKLIST = [] # List of sections to skip
 
27
 
 
28
#: List of sections to skip. This must be a valid regular expression
 
29
# We must exclude window managers to not kill ourselves
 
30
BLACKLIST = ['metacity', 'compiz', 'unity' ] 
 
31
BINARIES = []
8
32
 
9
33
config = ConfigParser.ConfigParser()
10
34
config.read( DESKTOPCACHE )
12
36
sections = config.sections()
13
37
 
14
38
teststr = ""
15
 
for section in config.sections():
16
 
    if section in BLACKLIST: continue
 
39
for section in sorted(config.sections()):
 
40
    for v in BLACKLIST:
 
41
        if search(v, section): continue
17
42
 
18
43
    try:
19
44
        binary = config.get( section, 'TryExec' )
23
48
        continue
24
49
 
25
50
    try:
26
 
        name = sub('\W', '', config.get( section, 'Name' ))
 
51
        name = sub('\W', '', config.get( section, 'Name' ).capitalize())
27
52
        terminal = config.get( section, 'Terminal' )
28
53
        categories = config.get( section, 'Categories' ).split(';')
29
54
 
30
 
        if terminal == True: continue
 
55
        # Skip Terminal applications
 
56
        if terminal == 'true': continue
31
57
    except ConfigParser.NoOptionError:
32
58
        continue
33
59
 
34
60
    binary = binary.split(' ')[0]
35
61
 
 
62
    if binary in BINARIES: continue
 
63
    BINARIES.append(binary)
 
64
 
36
65
    teststr += """
37
66
class Test%s(TestCase):
38
67
    launcher = '%s'
39
68
 
40
 
    def test_minimal(self):
 
69
    def test_%s_basic(self):
 
70
        ldtp.wait(3)
41
71
        self.assertTrue(True)
42
 
""" % (name, binary)
 
72
""" % (name, binary, sub('\W', '', os.path.basename(binary)))
43
73
 
44
74
# Generate the testcase script. You need to redirect to a file named
45
75
# test_sanitychecks.py to run it with mago
46
76
print """# This file was generated by %s
47
77
from mago import TestCase
 
78
import ldtp
48
79
import unittest
49
80
 
50
81
%s