/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to tests/__init__.py

  • Committer: Curtis Hovey
  • Date: 2012-02-27 21:07:38 UTC
  • mto: (776.3.1 gpush)
  • mto: This revision was merged to the branch mainline in revision 779.
  • Revision ID: sinzui.is@verizon.net-20120227210738-f5vb56xm2k2ii19j
Added show_user_warning implementation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
 
1
# Copyright (C) 2007, 2008 Jelmer Vernooij <jelmer@samba.org>
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from unittest import TestLoader, TestSuite
18
 
from bzrlib.tests import TestUtil
 
17
__all__ = [
 
18
    'load_tests',
 
19
    'MockMethod',
 
20
    'MockProperty',
 
21
    ]
19
22
 
20
23
import os
21
24
 
22
 
def test_suite():
23
 
    result = TestSuite()
24
 
 
25
 
    loader = TestUtil.TestLoader()
26
 
 
27
 
    testmod_names = [
28
 
        'test_commit',
29
 
        'test_diff',
30
 
        'test_linegraph',
31
 
        'test_preferences',
32
 
        'test_history',
33
 
        ]
34
 
 
35
 
    if os.name == 'nt':
36
 
        testmod_names.append("test_tortoise_bzr")
37
 
 
38
 
    result.addTest(loader.loadTestsFromModuleNames(["%s.%s" % (__name__, i) for i in testmod_names]))
39
 
    return result
40
 
 
 
25
 
 
26
def load_tests(basic_tests, module, loader):
 
27
    if module == 'discover':
 
28
        here = os.path.abspath(os.path.dirname(__file__))
 
29
        basic_tests.addTest(loader.discover(here))
 
30
    else:
 
31
        full_name = "%s.%s" % (__name__, module)
 
32
        basic_tests.addTest(loader.loadTestsFromModuleNames([full_name]))
 
33
    return basic_tests
 
34
 
 
35
 
 
36
class MockMethod(object):
 
37
 
 
38
    @classmethod
 
39
    def bind(klass, test_instance, obj, method_name, return_value=None):
 
40
        original_method = getattr(obj, method_name)
 
41
        test_instance.addCleanup(setattr, obj, method_name, original_method)
 
42
        setattr(obj, method_name, klass(return_value))
 
43
 
 
44
    def __init__(self, return_value=None):
 
45
        self.called = False
 
46
        self.call_count = 0
 
47
        self.args = None
 
48
        self.kwargs = None
 
49
        self.return_value = return_value
 
50
 
 
51
    def __call__(self, *args, **kwargs):
 
52
        self.called = True
 
53
        self.call_count += 1
 
54
        self.args = args
 
55
        self.kwargs = kwargs
 
56
        return self.return_value
 
57
 
 
58
 
 
59
class MockProperty(MockMethod):
 
60
 
 
61
    @classmethod
 
62
    def bind(klass, test_instance, obj, method_name, return_value=None):
 
63
        original_method = getattr(obj, method_name)
 
64
        test_instance.addCleanup(setattr, obj, method_name, original_method)
 
65
        mock = klass(return_value)
 
66
        setattr(obj, method_name, property(mock.get_value, mock.set_value))
 
67
        return mock
 
68
 
 
69
    def get_value(self, other):
 
70
        self.called = True
 
71
        return self.return_value
 
72
 
 
73
    def set_value(self, other, value):
 
74
        self.called = True
 
75
        self.return_value = value