/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: Vincent Ladeuil
  • Date: 2008-05-05 18:16:46 UTC
  • mto: (487.1.1 gtk)
  • mto: This revision was merged to the branch mainline in revision 490.
  • Revision ID: v.ladeuil+lp@free.fr-20080505181646-n95l8ltw2u6jtr26
Fix bug #187283 fix replacing _() by _i18n().

* genpot.sh 
Remove duplication. Add the ability to specify the genrated pot
file on command-line for debugging purposes.

* po/olive-gtk.pot:
Regenerated.

* __init__.py, branch.py, branchview/treeview.py, checkout.py,
commit.py, conflicts.py, diff.py, errors.py, initialize.py,
merge.py, nautilus-bzr.py, olive/__init__.py, olive/add.py,
olive/bookmark.py, olive/guifiles.py, olive/info.py,
olive/menu.py, olive/mkdir.py, olive/move.py, olive/remove.py,
olive/rename.py, push.py, revbrowser.py, status.py, tags.py:
Replace all calls to _() by calls to _i18n(), the latter being
defined in __init__.py and imported in the other modules from
there. This fix the problem encountered countless times when
running bzr selftest and getting silly error messages about
boolean not being callables.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008 Jelmer Vernooij <jelmer@samba.org>
 
1
# Copyright (C) 2007 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
 
__all__ = [
18
 
    'load_tests',
19
 
    'MockMethod',
20
 
    'MockProperty',
21
 
    ]
 
17
from unittest import TestLoader, TestSuite
 
18
from bzrlib.tests import TestUtil
22
19
 
23
20
import os
24
21
 
25
 
 
26
 
def discover_test_names(module_or_name):
27
 
    if isinstance(module_or_name, basestring):
28
 
        match = module_or_name
29
 
    else:
30
 
        match = ''
31
 
    file_names = os.listdir(os.path.dirname(__file__))
32
 
    test_names = set()
33
 
    for file_name in file_names:
34
 
        name, ext = os.path.splitext(file_name)
35
 
        if name.startswith('test_') and ext == '.py' and match in name:
36
 
            test_names.add("%s.%s" % (__name__, name))
37
 
    return test_names
38
 
 
39
 
 
40
 
def load_tests(basic_tests, module, loader):
41
 
    test_names = discover_test_names(module)
42
 
    basic_tests.addTest(loader.loadTestsFromModuleNames(test_names))
43
 
    return basic_tests
44
 
 
45
 
 
46
 
class MockMethod(object):
47
 
 
48
 
    @classmethod
49
 
    def bind(klass, test_instance, obj, method_name,
50
 
             return_value=None, raise_error=None, raise_on=1):
51
 
        original_method = getattr(obj, method_name)
52
 
        test_instance.addCleanup(setattr, obj, method_name, original_method)
53
 
        setattr(obj, method_name, klass(return_value, raise_error, raise_on))
54
 
 
55
 
    def __init__(self, return_value=None, raise_error=None, raise_on=1):
56
 
        self.called = False
57
 
        self.call_count = 0
58
 
        self.args = None
59
 
        self.kwargs = None
60
 
        self.return_value = return_value
61
 
        self.raise_error = raise_error
62
 
        self.raise_on = raise_on
63
 
 
64
 
    def __call__(self, *args, **kwargs):
65
 
        self.called = True
66
 
        self.call_count += 1
67
 
        self.args = args
68
 
        self.kwargs = kwargs
69
 
        if self.raise_error is not None and self.call_count == self.raise_on:
70
 
            raise self.raise_error
71
 
        return self.return_value
72
 
 
73
 
 
74
 
class MockProperty(MockMethod):
75
 
 
76
 
    @classmethod
77
 
    def bind(klass, test_instance, obj, method_name, return_value=None):
78
 
        original_method = getattr(obj, method_name)
79
 
        test_instance.addCleanup(setattr, obj, method_name, original_method)
80
 
        mock = klass(return_value)
81
 
        setattr(obj, method_name, property(mock.get_value, mock.set_value))
82
 
        return mock
83
 
 
84
 
    def get_value(self, other):
85
 
        self.called = True
86
 
        return self.return_value
87
 
 
88
 
    def set_value(self, other, value):
89
 
        self.called = True
90
 
        self.return_value = value
 
22
def test_suite():
 
23
    result = TestSuite()
 
24
 
 
25
    loader = TestUtil.TestLoader()
 
26
 
 
27
    testmod_names = [
 
28
        'test_commit',
 
29
        'test_diff',
 
30
        'test_preferences',
 
31
        'test_history',
 
32
        ]
 
33
 
 
34
    if os.name == 'nt':
 
35
        testmod_names.append("test_tortoise_bzr")
 
36
 
 
37
    result.addTest(loader.loadTestsFromModuleNames(["%s.%s" % (__name__, i) for i in testmod_names]))
 
38
    return result
 
39