|
1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
16 # You should have received a copy of the GNU Lesser General Public License along |
|
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
18 """unit tests for cubicweb.devtools.fill module |
|
19 |
|
20 """ |
|
21 import re |
|
22 |
|
23 from logilab.common.testlib import TestCase, unittest_main |
|
24 |
|
25 from cubicweb.devtools.fill import ValueGenerator, _ValueGenerator |
|
26 |
|
27 ISODATE_SRE = re.compile('(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})$') |
|
28 |
|
29 |
|
30 class AutoExtendableTC(TestCase): |
|
31 |
|
32 def setUp(self): |
|
33 self.attrvalues = dir(_ValueGenerator) |
|
34 |
|
35 def tearDown(self): |
|
36 attrvalues = set(dir(_ValueGenerator)) |
|
37 for attrname in attrvalues - set(self.attrvalues): |
|
38 delattr(_ValueGenerator, attrname) |
|
39 |
|
40 |
|
41 def test_autoextend(self): |
|
42 self.assertNotIn('generate_server', dir(ValueGenerator)) |
|
43 class MyValueGenerator(ValueGenerator): |
|
44 def generate_server(self, index): |
|
45 return attrname |
|
46 self.assertIn('generate_server', dir(ValueGenerator)) |
|
47 |
|
48 |
|
49 def test_bad_signature_detection(self): |
|
50 self.assertNotIn('generate_server', dir(ValueGenerator)) |
|
51 try: |
|
52 class MyValueGenerator(ValueGenerator): |
|
53 def generate_server(self): |
|
54 pass |
|
55 except TypeError: |
|
56 self.assertNotIn('generate_server', dir(ValueGenerator)) |
|
57 else: |
|
58 self.fail('TypeError not raised') |
|
59 |
|
60 |
|
61 def test_signature_extension(self): |
|
62 self.assertNotIn('generate_server', dir(ValueGenerator)) |
|
63 class MyValueGenerator(ValueGenerator): |
|
64 def generate_server(self, index, foo): |
|
65 pass |
|
66 self.assertIn('generate_server', dir(ValueGenerator)) |
|
67 |
|
68 |
|
69 if __name__ == '__main__': |
|
70 unittest_main() |