author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 21 Sep 2009 11:41:17 +0200 | |
branch | stable |
changeset 3334 | 8d831c02da9a |
parent 1977 | 606923dff11b |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
1 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
7 |
""" |
0 | 8 |
from logilab.common.testlib import TestCase, unittest_main |
9 |
||
10 |
import cubicwebfs |
|
11 |
import sre |
|
12 |
||
13 |
def spec_parser(filename) : |
|
14 |
""" |
|
15 |
extract tests from specification |
|
16 |
""" |
|
17 |
sections = [] |
|
18 |
buffer = "" |
|
19 |
in_section = False |
|
20 |
for line in file(filename) : |
|
21 |
if line.startswith('Test::'): |
|
22 |
in_section = True |
|
23 |
buffer = "" |
|
24 |
elif in_section : |
|
25 |
if line.startswith(" ") or not line.strip() : |
|
26 |
buffer += line.lstrip() |
|
27 |
else : |
|
28 |
sections.append(buffer) |
|
29 |
in_section = False |
|
30 |
tests = [] |
|
31 |
for section in sections : |
|
32 |
subsections = [t for t in section.strip().split('$ ls') if t] |
|
33 |
for subsection in subsections : |
|
34 |
path, results = subsection.splitlines()[0], subsection.splitlines()[1:] |
|
35 |
path = path.strip() |
|
36 |
items = set([i for i in sre.split('[\t\n]', '\n'.join(results)) if i]) |
|
37 |
tests.append((path, items)) |
|
38 |
return tests |
|
39 |
||
40 |
tests = spec_parser("cubicwebfs-spec.txt") |
|
41 |
||
42 |
class monTC(TestCase) : |
|
43 |
pass |
|
44 |
||
45 |
for index, (path, results) in enumerate(tests) : |
|
46 |
def f(self, p=path, r=results) : |
|
47 |
res = set(cubicwebfs.ls(p)) |
|
48 |
self.assertEqual(r, res) #, 'en trop %s\nmanque %s' % (r-results,results-r)) |
|
49 |
f.__doc__ = "%s %s"%(index,path) |
|
50 |
setattr(monTC,'test_%s'%index,f) |
|
51 |
||
52 |
if __name__ == '__main__': |
|
53 |
unittest_main() |