annotate src/test/helpers.py @ 604:16a9affc49cf

plugin export command: first draft this plugin allow to export the stdin/stdout/stderr of a process to a contact
author Goffi <goffi@goffi.org>
date Fri, 22 Feb 2013 00:22:50 +0100
parents 65821b3fa7ab
children 84a6e83157c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
335
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
Goffi <goffi@goffi.org>
parents:
diff changeset
3
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
Goffi <goffi@goffi.org>
parents:
diff changeset
5 SAT: a jabber client
572
ca13633d3b6b dates update
Goffi <goffi@goffi.org>
parents: 512
diff changeset
6 Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
335
Goffi <goffi@goffi.org>
parents:
diff changeset
7
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
480
2a072735e459 Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents: 459
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
335
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
Goffi <goffi@goffi.org>
parents:
diff changeset
12
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
480
2a072735e459 Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents: 459
diff changeset
16 GNU Affero General Public License for more details.
335
Goffi <goffi@goffi.org>
parents:
diff changeset
17
480
2a072735e459 Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents: 459
diff changeset
18 You should have received a copy of the GNU Affero General Public License
335
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
Goffi <goffi@goffi.org>
parents:
diff changeset
21
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import __builtin__
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from twisted.words.protocols.jabber.jid import JID
Goffi <goffi@goffi.org>
parents:
diff changeset
24
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
25 TEST_JID_STR = u"test@example.org/SàT"
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
26 TEST_JID = JID(u"test@example.org/SàT")
335
Goffi <goffi@goffi.org>
parents:
diff changeset
27 TEST_PROFILE = 'test_profile'
Goffi <goffi@goffi.org>
parents:
diff changeset
28
591
65821b3fa7ab Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
29
335
Goffi <goffi@goffi.org>
parents:
diff changeset
30 class DifferentArgsException(Exception):
Goffi <goffi@goffi.org>
parents:
diff changeset
31 pass
Goffi <goffi@goffi.org>
parents:
diff changeset
32
591
65821b3fa7ab Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
33
335
Goffi <goffi@goffi.org>
parents:
diff changeset
34 class FakeSAT(object):
Goffi <goffi@goffi.org>
parents:
diff changeset
35 """Class to simulate a SAT instance"""
Goffi <goffi@goffi.org>
parents:
diff changeset
36
Goffi <goffi@goffi.org>
parents:
diff changeset
37 def __init__(self):
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.bridge = FakeBridge()
Goffi <goffi@goffi.org>
parents:
diff changeset
39 self.memory = FakeMemory()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
40 self.trigger = FakeTriggerManager()
335
Goffi <goffi@goffi.org>
parents:
diff changeset
41
Goffi <goffi@goffi.org>
parents:
diff changeset
42
Goffi <goffi@goffi.org>
parents:
diff changeset
43 class FakeBridge(object):
Goffi <goffi@goffi.org>
parents:
diff changeset
44 """Class to simulate and test bridge calls"""
Goffi <goffi@goffi.org>
parents:
diff changeset
45
Goffi <goffi@goffi.org>
parents:
diff changeset
46 def expectCall(self, name, *check_args, **check_kwargs):
Goffi <goffi@goffi.org>
parents:
diff changeset
47 def checkCall(*args, **kwargs):
Goffi <goffi@goffi.org>
parents:
diff changeset
48 if args != check_args or kwargs != check_kwargs:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 print "\n\n--------------------"
Goffi <goffi@goffi.org>
parents:
diff changeset
50 print "Args are not equals:"
Goffi <goffi@goffi.org>
parents:
diff changeset
51 print "args\n----\n%s (sent)\n%s (wanted)" % (args, check_args)
Goffi <goffi@goffi.org>
parents:
diff changeset
52 print "kwargs\n------\n%s (sent)\n%s (wanted)" % (kwargs, check_kwargs)
Goffi <goffi@goffi.org>
parents:
diff changeset
53 print "--------------------\n\n"
Goffi <goffi@goffi.org>
parents:
diff changeset
54 raise DifferentArgsException
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
55
335
Goffi <goffi@goffi.org>
parents:
diff changeset
56 setattr(self, name, checkCall)
Goffi <goffi@goffi.org>
parents:
diff changeset
57
Goffi <goffi@goffi.org>
parents:
diff changeset
58
Goffi <goffi@goffi.org>
parents:
diff changeset
59 class FakeMemory(object):
Goffi <goffi@goffi.org>
parents:
diff changeset
60 """Class to simulate and test memory object"""
Goffi <goffi@goffi.org>
parents:
diff changeset
61
Goffi <goffi@goffi.org>
parents:
diff changeset
62 def getProfileName(self, profile_key):
Goffi <goffi@goffi.org>
parents:
diff changeset
63 return profile_key
Goffi <goffi@goffi.org>
parents:
diff changeset
64
512
862c0d6ab974 core, bridge, quick_frontend: MUC private messages history management:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
65 def addToHistory(self, from_jid, to_jid, message, _type='chat', timestamp=None, profile=None):
335
Goffi <goffi@goffi.org>
parents:
diff changeset
66 pass
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
67
335
Goffi <goffi@goffi.org>
parents:
diff changeset
68 def addContact(self, contact_jid, attributes, groups, profile_key='@DEFAULT@'):
Goffi <goffi@goffi.org>
parents:
diff changeset
69 pass
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
70
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
71 def setPresenceStatus(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'):
335
Goffi <goffi@goffi.org>
parents:
diff changeset
72 pass
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
73
335
Goffi <goffi@goffi.org>
parents:
diff changeset
74 def addWaitingSub(self, type, contact_jid, profile_key):
Goffi <goffi@goffi.org>
parents:
diff changeset
75 pass
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
76
335
Goffi <goffi@goffi.org>
parents:
diff changeset
77 def delWaitingSub(self, contact_jid, profile_key):
Goffi <goffi@goffi.org>
parents:
diff changeset
78 pass
Goffi <goffi@goffi.org>
parents:
diff changeset
79
591
65821b3fa7ab Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
80
335
Goffi <goffi@goffi.org>
parents:
diff changeset
81 class FakeTriggerManager(object):
Goffi <goffi@goffi.org>
parents:
diff changeset
82
Goffi <goffi@goffi.org>
parents:
diff changeset
83 def add(self, point_name, callback):
Goffi <goffi@goffi.org>
parents:
diff changeset
84 pass
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
85
335
Goffi <goffi@goffi.org>
parents:
diff changeset
86 def point(self, point_name, *args, **kwargs):
Goffi <goffi@goffi.org>
parents:
diff changeset
87 """We always return true to continue the action"""
Goffi <goffi@goffi.org>
parents:
diff changeset
88 return True
Goffi <goffi@goffi.org>
parents:
diff changeset
89
591
65821b3fa7ab Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
90
335
Goffi <goffi@goffi.org>
parents:
diff changeset
91 class FakeParent(object):
Goffi <goffi@goffi.org>
parents:
diff changeset
92 def __init__(self):
Goffi <goffi@goffi.org>
parents:
diff changeset
93 self.profile = 'test_profile'
Goffi <goffi@goffi.org>
parents:
diff changeset
94 self.jid = TEST_JID
Goffi <goffi@goffi.org>
parents:
diff changeset
95
591
65821b3fa7ab Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
96
335
Goffi <goffi@goffi.org>
parents:
diff changeset
97 def _(text):
Goffi <goffi@goffi.org>
parents:
diff changeset
98 return text
Goffi <goffi@goffi.org>
parents:
diff changeset
99
Goffi <goffi@goffi.org>
parents:
diff changeset
100 __builtin__.__dict__['_'] = _