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
|
#!/usr/bin/python
import os
import sys
import inspect
import imp
from common.utils import configuration as cfg
### This function comes from pydoc. Cool!
def importfile(path):
"""Import a Python source file or compiled file given its path."""
magic = imp.get_magic()
file = open(path, 'r')
if file.read(len(magic)) == magic:
kind = imp.PY_COMPILED
else:
kind = imp.PY_SOURCE
file.close()
filename = os.path.basename(path)
name, ext = os.path.splitext(filename)
file = open(path, 'r')
module = None
try:
module = imp.load_module(name, file, path, (ext, 'r', kind))
except Exception, e:
print >> sys.stderr, "Ignoring %s (%s)" % (path, e)
#raise Exception ()
file.close()
return module
HEADER = """
<testdefinition version="0.1">
<suite name="tracker">
<description>Functional tests for the brilliant tracker</description> """
TEST_CASE_TMPL = """ <case name="%s" timeout="180">
<description>%s</description>
<step>%s</step>
</case>"""
FOOTER = """
</suite>
</testdefinition>"""
if (cfg.haveUpstart):
PRE_STEPS = """ <pre_steps>
<step>initctl stop xsession/tracker-writeback</step>
<step>initctl stop xsession/tracker-miner</step>
<step>initctl start xsession/tracker-stop</step>
</pre_steps>
"""
else:
PRE_STEPS = """ <pre_steps>
<step>while tracker daemon -p |grep -q '^Found process ID '; do tracker daemon -t; sleep 1; done</step>
</pre_steps>
"""
def __get_doc (obj):
if obj.__doc__:
return obj.__doc__.strip ()
else:
return "FIXME description here"
def print_as_xml (filename):
module = importfile (filename)
if not module:
return
print "\n <set name=\"%s\">" % (module.__name__)
print " <description>%s</description>" % (__get_doc (module))
print PRE_STEPS
for name, obj in inspect.getmembers (module):
if name.startswith ("Common") or name.endswith ("Template"):
continue
if (inspect.isclass (obj)
and obj.__module__ == filename[:-3]):
script = os.path.join (cfg.DATADIR, "tracker-tests", filename)
print TEST_CASE_TMPL % (name,
__get_doc (obj),
script + " " + name)
print """ <environments>
<scratchbox>true</scratchbox>
<hardware>true</hardware>
</environments>
</set>
"""
# Remove the compiled .pyc from the disk (because it looks ugly)
#
# First time a module is loaded, __file__ is the .py
# once the file is compiled, __file__ is .pyc
if module.__file__.endswith (".py"):
unlink = module.__file__ + "c"
else:
unlink = module.__file__
os.unlink (unlink)
if __name__ == "__main__":
if (len (sys.argv) < 2):
print >> sys.stderr, "pass .py tests as parameter"
sys.exit (-1)
print HEADER
map (print_as_xml, sys.argv[1:])
print FOOTER
|