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
133
134
135
136
137
138
|
#!/usr/bin/env python
from distutils.core import setup, Command
from os.path import splitext, basename, join as pjoin, walk
import os, sys
import glob
from unittest import TestLoader, TextTestRunner, TestSuite
from subprocess import Popen
COVERAGE_IGNORE=[
"tutorius/apilib",
"tutorius/viewer.py",
"tutorius/creator.py",
"tutorius/overlayer.py",
"tutorius/addons",
]
class TestCommand(Command):
user_options = [('coverage',
None,
'enable code coverage reporting'),
('prefix=',
'p',
'set sugar installation prefix, for dependency loading'),
('single=',
't',
'run a single test'),
]
description = 'runs tests from the test directory'
def initialize_options(self):
self._dir = os.getcwd()
self.coverage = False
self.single = False
self.prefix = None
def finalize_options(self):
if not self.prefix:
print
sys.exit(1)
def run(self):
'''
Finds all the tests modules in tests/, and runs them.
'''
prefix = os.path.join(self.prefix,'lib',
'python%d.%d'%sys.version_info[:2],
'site-packages')
sys.path.insert(1, prefix)
os.environ.setdefault('SUGAR_PREFIX', self.prefix)
# start another X server so test that manipulates the shell can mess it
# up as they wish.
# :111 should be high enough, unless we already run sugar-emulator 10
# times.
x_server = Popen(executable='Xephyr', args=['Xephyr', ':111'])
os.environ['DISPLAY'] = ':111'
if self.coverage:
import coverage
coverage.erase()
coverage.start()
loader = TestLoader()
suite = TestSuite()
if not self.single:
skipped = file('tests/skip', 'r').read().split('\n')
for t in glob.glob(pjoin(self._dir, 'tests', '*.py')):
if not t.endswith('__init__.py') and basename(t) not in skipped:
modname = '.'.join(['tests', splitext(basename(t))[0]])
mod = __import__(modname, {'sys':sys}, fromlist=[modname])
print "loading %s" % modname
suite.addTest(loader.loadTestsFromModule(mod))
else:
print "skipping %s" % t
else:
modname = '.'.join(['tests', self.single])
mod = __import__(modname, {'sys':sys}, fromlist=[modname])
print "loading %s" % modname
suite.addTest(loader.loadTestsFromModule(mod))
t = TextTestRunner(verbosity = 1)
t.run(suite)
if self.coverage:
coverage.stop()
sources = []
#To reduce report format, change to the tutorius dir before reporting
curdir = os.getcwd()
os.chdir(os.path.join(prefix, 'sugar'))
os.path.walk('tutorius',
self._listsources,
sources)
coverage.report(sources)
os.chdir(curdir)
coverage.erase()
x_server.terminate()
def _listsources(self, arg, dirname, fnames):
for name in list(fnames):
if os.path.join(dirname, name) in COVERAGE_IGNORE:
fnames.remove(name)
fnames = filter(lambda x:x.endswith('.py'), fnames)
for name in fnames:
arg.append(pjoin(dirname, name))
setup(name='Tutorius',
version='0.0',
description='Interactive tutor and Tutorial creator',
maintainer='Simon Poirier',
maintainer_email='simpoir@gmail.com',
author='Tutorius team',
author_email='sugar-narratives@googlegroups.com',
url='http://tutorius.org',
license='GPLv3',
packages=[
'sugar.tutorius',
'sugar.tutorius.uam',
'sugar.tutorius.addons',
'sugar.tutorius.apilib',
'sugar.tutorius.apilib.httplib2',
],
package_dir={
'sugar.tutorius': 'tutorius',
'sugar.tutorius.addons': 'addons',
},
cmdclass = {'test': TestCommand},
data_files=[('share/icons/sugar/scalable/actions', glob.glob('data/icons/*.svg')),
('share/icons/sugar/scalable/device', ['data/icons/tutortool.svg']),
('share/tutorius/ui', glob.glob('data/ui/*.glade')),
('share/sugar/extensions/deviceicon', glob.glob('src/extensions/*')),
]
)
# vim: set et sw=4 sts=4 ts=4:
|