test_bootstrap.py 2.27 KB
Newer Older
1
# copyright 2013-2022 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
Nicola Spanti's avatar
Nicola Spanti committed
2
# contact https://www.logilab.fr -- mailto:contact@logilab.fr
Adrien Di Mascio's avatar
Adrien Di Mascio committed
3
4
5
6
7
8
9
10
11
12
13
14
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
Nicola Spanti's avatar
Nicola Spanti committed
15
# with this program. If not, see <https://www.gnu.org/licenses/>.
Adrien Di Mascio's avatar
Adrien Di Mascio committed
16

17
"""cubicweb-bootstrap automatic tests
Adrien Di Mascio's avatar
Adrien Di Mascio committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39


uncomment code below if you want to activate automatic test for your cube:

.. sourcecode:: python

    from cubicweb.devtools.testlib import AutomaticWebTest

    class AutomaticWebTest(AutomaticWebTest):
        '''provides `to_test_etypes` and/or `list_startup_views` implementation
        to limit test scope
        '''

        def to_test_etypes(self):
            '''only test views for entities of the returned types'''
            return set(('My', 'Cube', 'Entity', 'Types'))

        def list_startup_views(self):
            '''only test startup views of the returned identifiers'''
            return ('some', 'startup', 'views')
"""

40
from logilab.common.testlib import TestCase
Adrien Di Mascio's avatar
Adrien Di Mascio committed
41

42
# this will make sure cubes are in our sys.path
Nsukami Patrick's avatar
Nsukami Patrick committed
43
import cubicweb.devtools  # noqa
44

45
from cubicweb_bootstrap import monkeypatch_default_value
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63


class MonkeypatchDefaultValueTC(TestCase):
    def test_function(self):
        def func(a, b, c=0, d=None, e=False, f=()):
            return c
        self.assertEqual(func(1, 2), 0)
        monkeypatch_default_value(func, 'c', 42)
        self.assertEqual(func(1, 2), 42)

    def test_method(self):
        class Class(object):
            def meth(self, a, b, c=0, d=None, e=False, f=()):
                return c
        obj = Class()
        self.assertEqual(obj.meth(1, 2), 0)
        monkeypatch_default_value(Class.meth, 'c', 42)
        self.assertEqual(obj.meth(1, 2), 42)
Adrien Di Mascio's avatar
Adrien Di Mascio committed
64
65
66


if __name__ == '__main__':
67
68
    import unittest
    unittest.main()