6
# Copyright (C) 2008 Ross Light
8
# This file is part of zfilenet.
10
# zfilenet is free software: you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation, either version 3 of the License, or
13
# (at your option) any later version.
15
# zfilenet is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU General Public License for more details.
20
# You should have received a copy of the GNU General Public License
21
# along with zfilenet. If not, see <http://www.gnu.org/licenses/>.
24
"""pinet unit tests"""
26
from __future__ import absolute_import
28
from . import dispatch
30
__author__ = 'Ross Light'
31
__date__ = 'November 9, 2007'
34
class Handler(object):
38
def my_private_method(self):
43
self.data.append(eggs)
46
def test_method_exposure():
47
"""Method publicity test"""
49
result = dispatch.get_exposed_methods(handler)
50
assert result == {'spam': handler.spam}, "Invalid exposure dictionary"
52
def test_dispatcher():
53
"""Dispatcher accuracy test"""
54
def _my_great_func(a, b):
57
dispatcher = dispatch.Dispatcher()
58
dispatcher.register_function(_my_great_func, 'add')
59
dispatcher.register_object(handler, 'ns')
60
ideal = {'add': (_my_great_func, False),
61
'ns.spam': (handler.spam, False),}
62
assert dispatcher.functions == ideal, "Wrong functions"
63
assert dispatcher.dispatch(None, 'add', (2, 2)) == 4, "Adding invalid"
64
assert dispatcher.dispatch(None, 'add', {'a': 2, 'b': 2}) == 4, \
66
assert dispatcher.dispatch(None, 'ns.spam', ('foo',)) == 'foo', \
67
"Handler not returning"
68
assert handler.data == ['foo'], "Handler not called"
70
dispatcher.dispatch(None, 'subtract', ())
71
except dispatch.MethodNotFound:
74
raise AssertionError("Calling fake methods")