/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-09 03:43:01 UTC
  • mto: This revision was merged to the branch mainline in revision 776.
  • Revision ID: sinzui.is@verizon.net-20120209034301-0uwkobbb0d64ugrw
Switched from Gtk.VPaned to Gtk.Paned.new(Gtk.Orientation.VERTICAL).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
    ]
22
 
 
23
 
import os
24
 
 
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
17
 
40
18
def load_tests(basic_tests, module, loader):
41
 
    test_names = discover_test_names(module)
42
 
    basic_tests.addTest(loader.loadTestsFromModuleNames(test_names))
 
19
    testmod_names = [
 
20
        'test_annotate_config',
 
21
        'test_avatarsbox',
 
22
        'test_commit',
 
23
        'test_diff',
 
24
        'test_history',
 
25
        'test_graphcell',
 
26
        'test_linegraph',
 
27
        'test_notify',
 
28
        'test_revisionview',
 
29
        'test_treemodel',
 
30
        ]
 
31
 
 
32
    basic_tests.addTest(loader.loadTestsFromModuleNames(
 
33
            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
43
34
    return basic_tests
44
35
 
45
36
 
46
 
class MockMethod(object):
 
37
class MockMethod():
47
38
 
48
39
    @classmethod
49
 
    def bind(klass, test_instance, obj, method_name,
50
 
             return_value=None, raise_error=None, raise_on=1):
 
40
    def bind(klass, test_instance, obj, method_name):
51
41
        original_method = getattr(obj, method_name)
52
42
        test_instance.addCleanup(setattr, obj, method_name, original_method)
53
 
        setattr(obj, method_name, klass(return_value, raise_error, raise_on))
 
43
        setattr(obj, method_name, klass())
54
44
 
55
 
    def __init__(self, return_value=None, raise_error=None, raise_on=1):
 
45
    def __init__(self):
56
46
        self.called = False
57
 
        self.call_count = 0
58
47
        self.args = None
59
48
        self.kwargs = None
60
 
        self.return_value = return_value
61
 
        self.raise_error = raise_error
62
 
        self.raise_on = raise_on
63
49
 
64
50
    def __call__(self, *args, **kwargs):
65
51
        self.called = True
66
 
        self.call_count += 1
67
52
        self.args = args
68
53
        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