Merge lp:~mandel/ubuntuone-dev-tools/allow_txnamedpipes_reactor into lp:ubuntuone-dev-tools

Proposed by Manuel de la Peña
Status: Rejected
Rejected by: dobey
Proposed branch: lp:~mandel/ubuntuone-dev-tools/allow_txnamedpipes_reactor
Merge into: lp:ubuntuone-dev-tools
Diff against target: 516 lines (+368/-49)
9 files modified
bin/u1trial (+12/-46)
man/u1trial.1 (+3/-2)
setup.py (+3/-1)
ubuntuone/devtools/plugins/__init__.py (+72/-0)
ubuntuone/devtools/plugins/reactors/__init__.py (+95/-0)
ubuntuone/devtools/plugins/reactors/glib.py (+32/-0)
ubuntuone/devtools/plugins/reactors/qtreactor.py (+58/-0)
ubuntuone/devtools/plugins/reactors/txnamedpipes.py (+42/-0)
ubuntuone/devtools/tests/test_plugins.py (+51/-0)
To merge this branch: bzr merge lp:~mandel/ubuntuone-dev-tools/allow_txnamedpipes_reactor
Reviewer Review Type Date Requested Status
dobey (community) Disapprove
Roberto Alsina (community) Approve
Review via email: mp+61515@code.launchpad.net

Commit message

Provides yet an extra parameter so that the txnamedpipes reactor can be used to run the trial tests. The txnamedpipes-reactor provide an IOCP reactor implementation that allows to use named pipes to perform the IPC.

Description of the change

Provides yet an extra parameter so that the txnamedpipes reactor can be used to run the trial tests. The txnamedpipes-reactor provide an IOCP reactor implementation that allows to use named pipes to perform the IPC.

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) wrote :

+1 but really needs a review from dobey

review: Approve
Revision history for this message
dobey (dobey) wrote :

+NAMEDPIPES_REACTOR_PROJECT = 'lp:txnamedpipes'

This really should be a useful HTTP[S] URL instead. Something people can click on and get to a web page, as with the Qt reactor one.

Also, the ./run-tests now fails for me on Linux in this branch.

I think I would also prefer to have a --reactor={glib,qt,namedpipes} type of argument to specify the reactor, than constantly adding more --foo-reactor arguments for every one we add. And then also have some of them perhaps provide additional argument possibilities, such as --with-ui for the Qt reactor, so that proper things can be done there. Perhaps it is time to move the reactor handling into their own modules, so we can treat them like plug-ins and make this main code a little more generic.

review: Needs Fixing
Revision history for this message
dobey (dobey) wrote :

OK, the ./run-tests failed because the branch name is a bit long, it seems; so the path went over the filename length limit.

Revision history for this message
Manuel de la Peña (mandel) wrote :

> OK, the ./run-tests failed because the branch name is a bit long, it seems; so
> the path went over the filename length limit.

Cool, I was worried because in my machine was working.

Revision history for this message
Manuel de la Peña (mandel) wrote :

> +NAMEDPIPES_REACTOR_PROJECT = 'lp:txnamedpipes'
>
> This really should be a useful HTTP[S] URL instead. Something people can click
> on and get to a web page, as with the Qt reactor one.
>
Simple and doable. :)

> Also, the ./run-tests now fails for me on Linux in this branch.
>
> I think I would also prefer to have a --reactor={glib,qt,namedpipes} type of
> argument to specify the reactor, than constantly adding more --foo-reactor
> arguments for every one we add. And then also have some of them perhaps
> provide additional argument possibilities, such as --with-ui for the Qt
> reactor, so that proper things can be done there. Perhaps it is time to move
> the reactor handling into their own modules, so we can treat them like plug-
> ins and make this main code a little more generic.

That is a complete change in the idea. Can we add this as a bug.

Revision history for this message
dobey (dobey) wrote :

On Tue, 2011-05-24 at 07:41 +0000, Manuel de la Pena wrote:
> > I think I would also prefer to have a --reactor={glib,qt,namedpipes} type of
> > argument to specify the reactor, than constantly adding more --foo-reactor
> > arguments for every one we add. And then also have some of them perhaps
> > provide additional argument possibilities, such as --with-ui for the Qt
> > reactor, so that proper things can be done there. Perhaps it is time to move
> > the reactor handling into their own modules, so we can treat them like plug-
> > ins and make this main code a little more generic.
>
> That is a complete change in the idea. Can we add this as a bug.
>

I realize that. But I don't want to file a bug, land this as-is, and
then start using this everywhere as it is now, only to either break it
soon, or just end up having it never get changed. I think we should fix
it now, and avoid such possibilities.

31. By Manuel de la Peña

Added a way to allow the addition of new reactors by adding 'plugins'

32. By Manuel de la Peña

Merged with the previous state of the branch.

33. By Manuel de la Peña

Removed left behind code.

Revision history for this message
dobey (dobey) wrote :

I'm going to go ahead and reject this, due to the complexity here, and as I've made a simpler branch which accomplishes what we need:

https://code.launchpad.net/~dobey/ubuntuone-dev-tools/fukishima/+merge/62506

review: Disapprove

Unmerged revisions

35. By Manuel de la Peña

Added tests for the plugins.

34. By Manuel de la Peña

Fixed license. Merged with trunk.

33. By Manuel de la Peña

Removed left behind code.

32. By Manuel de la Peña

Merged with the previous state of the branch.

31. By Manuel de la Peña

Added a way to allow the addition of new reactors by adding 'plugins'

30. By Manuel de la Peña

Added support to the namedpipes reactor so that it can be used on windows.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/u1trial'
2--- bin/u1trial 2011-04-13 14:37:14 +0000
3+++ bin/u1trial 2011-05-26 11:15:58 +0000
4@@ -30,10 +30,9 @@
5
6 from twisted.trial.runner import TrialRunner
7
8-QTREACTOR_URL = 'https://github.com/ghtdak/qtreactor'
9-
10 sys.path.insert(0, os.path.abspath("."))
11
12+
13 def _is_in_ignored_path(testcase, paths):
14 """Return if the testcase is in one of the ignored paths."""
15 for ignored_path in paths:
16@@ -41,47 +40,11 @@
17 return True
18 return False
19
20-def _install_reactor(qt_reactor=None):
21- """Install the correct reactor according to the platform."""
22- # the select reactor seems to be the most stable one in darwin
23- # and win32, we will just install a reactor for windows and use
24- # the default one for the other platforms.
25- platform = sys.platform
26- if not qt_reactor and platform not in ['win32', 'darwin']:
27- # install the glib2reactor before any import of the reactor to avoid
28- # using the default SelectReactor and be able to run the dbus tests
29- from twisted.internet import glib2reactor
30- glib2reactor.install()
31- elif qt_reactor:
32- # install the qtreactor so that we can start a qapplication in the
33- # tests to work with
34- if qt_reactor == 'ui':
35- from PyQt4.QtGui import QApplication
36- # pylint: disable=W0612
37- app = QApplication(sys.argv)
38- # pylint: enable=W0612
39- elif qt_reactor != 'no-ui':
40- # gave the wrong value
41- print 'Invalid option "%s" passed to --qtreactor' % qt_reactor
42- exit(1)
43- try:
44- # pylint: disable=W0511, F0401
45- from qtreactor import qt4reactor
46- # pylint: enable=W0511
47- qt4reactor.install()
48- except ImportError:
49- print 'The qtreactor python module is ' +\
50- 'required. You can find it at: %s' % QTREACTOR_URL
51- exit(1)
52
53 class TestRunner(TrialRunner):
54 """The test runner implementation."""
55
56- def __init__(self, force_gc=False, qt_reactor=None):
57- # install the correct reactor according to the platform, do
58- # this to ensure that we can instantiate the best reactor per
59- # platform
60- _install_reactor(qt_reactor)
61+ def __init__(self, force_gc=False):
62 from twisted.trial.reporter import TreeReporter
63
64 # set $HOME to the _trial_temp dir, to avoid breaking user files
65@@ -249,6 +212,7 @@
66 def main():
67 """Do the deed."""
68 from optparse import OptionParser
69+ from ubuntuone.devtools.plugins import load_plugins, configure_plugins
70 usage = '%prog [options] path'
71 parser = OptionParser(usage=usage)
72 parser.add_option("-t", "--test", dest="test",
73@@ -268,12 +232,14 @@
74 parser.add_option("--force-gc", action="store_true", dest="force_gc",
75 default=False, help="Run gc.collect() before and after "
76 "each test case.")
77- parser.add_option("--qt-reactor", type="string", dest="qt_reactor",
78- default=None, help="Run the tests using the qtreactor."
79- + "There are two available modes. 'ui' for those tests "
80- + "that will show UI and 'no-ui' for those that won't.",
81- metavar="MODE")
82+
83+ # load the diff plugins installed in the system
84+ plugins = load_plugins(parser, set())
85 (options, args) = parser.parse_args()
86+ # allow the plugins to be configured
87+ configure_plugins(plugins, options, args)
88+
89+ # let the plugins reacto to the options
90 if args:
91 testpath = args[0]
92 if not os.path.exists(testpath):
93@@ -282,8 +248,8 @@
94 else:
95 parser.print_help()
96 sys.exit(2)
97- TestRunner(force_gc=options.force_gc, qt_reactor=options.qt_reactor).run(
98- testpath, options)
99+
100+ TestRunner(force_gc=options.force_gc).run(testpath, options)
101
102 if __name__ == '__main__':
103 main()
104
105=== modified file 'man/u1trial.1'
106--- man/u1trial.1 2011-03-31 16:42:40 +0000
107+++ man/u1trial.1 2011-05-26 11:15:58 +0000
108@@ -35,8 +35,9 @@
109 .TP
110 \fB\-\-qt-reactor\fR=MODE\fR
111 Run the tests using the qtreactor. There are two available modes. 'ui'
112-for those tests that will show UI and 'no-ui' for those that won't.",
113-
114+for those tests that will show UI and 'no-ui' for those that won't.
115+\fB\-\-namedpipes-reactor\fR
116+Run the tests using the txnamedpipes reactor.
117
118 .SH AUTHOR
119 This manual page was written by Rodney Dawes <rodney.dawes@canonical.com>.
120
121=== modified file 'setup.py'
122--- setup.py 2011-02-11 20:42:28 +0000
123+++ setup.py 2011-05-26 11:15:58 +0000
124@@ -50,7 +50,9 @@
125 url='http://launchpad.net/ubuntuone-dev-tools',
126 packages=['ubuntuone',
127 'ubuntuone.devtools',
128- 'ubuntuone.devtools.services'],
129+ 'ubuntuone.devtools.services',
130+ 'ubuntuone.devtools.plugins',
131+ 'ubuntuone.devtools.plugins.reactors'],
132 extra_path='ubuntuone-dev-tools',
133 scripts=['bin/u1lint',
134 'bin/u1trial',
135
136=== added directory 'ubuntuone/devtools/plugins'
137=== added file 'ubuntuone/devtools/plugins/__init__.py'
138--- ubuntuone/devtools/plugins/__init__.py 1970-01-01 00:00:00 +0000
139+++ ubuntuone/devtools/plugins/__init__.py 2011-05-26 11:15:58 +0000
140@@ -0,0 +1,72 @@
141+# -*- coding: utf-8 -*-
142+
143+# Author: Manuel de la Pena manuel@canonical.com
144+#
145+# Copyright 2010-2011 Canonical Ltd.
146+#
147+# This program is free software: you can redistribute it and/or modify it
148+# under the terms of the GNU General Public License version 3, as published
149+# by the Free Software Foundation.
150+#
151+# This program is distributed in the hope that it will be useful, but
152+# WITHOUT ANY WARRANTY; without even the implied warranties of
153+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
154+# PURPOSE. See the GNU General Public License for more details.
155+#
156+# You should have received a copy of the GNU General Public License along
157+# with this program. If not, see <http://www.gnu.org/licenses/>
158+"""Basic plugins operations."""
159+
160+
161+import os
162+import logging
163+
164+DEVTOOLS_PLUGIN_PATHS = [os.path.join(os.path.dirname(__file__))]
165+
166+
167+def load_plugins(options, blocking_semaphores):
168+ """Load the desktopcouch application plug-ins.
169+
170+ The blocking_semaphores set is OPTIONALLY mutated by any plugin to signal
171+ that the service is not ready until a plugin has finished its asynchronous
172+ operations. Plugins may add a distinguishing object to the set, and it
173+ must remove what it adds when it is finished.
174+
175+ options -- The options set that is used to display extra arguments
176+ according to the plugin.
177+ blocking_semaphores -- the set() of semaphores, which we will mutate
178+ """
179+ plugin_names = set()
180+ for path in DEVTOOLS_PLUGIN_PATHS:
181+ try:
182+ for _file in os.listdir(path):
183+ file_abspath = os.path.abspath(os.path.join(path, _file))
184+ if _file == '__init__':
185+ continue
186+ elif os.path.isdir(file_abspath) and\
187+ os.path.exists(os.path.join(file_abspath, '__init__.py')):
188+ plugin_names.add(os.path.join(
189+ 'ubuntuone', 'devtools', 'plugins', _file))
190+ elif _file.endswith('.py') and _file != '__init__.py':
191+ plugin_names.add(os.path.join(
192+ 'ubuntuone', 'devtools', 'plugins', _file))
193+ except OSError:
194+ continue
195+ plugin_modules = set()
196+ for name in plugin_names:
197+ modpath = name.replace(os.path.sep, '.')
198+ if name.endswith('.py'):
199+ modpath = modpath[:-3]
200+ try:
201+ plugin = __import__(modpath, None, None, [''])
202+ plugin_modules.add(plugin)
203+ plugin.plugin_init(options, blocking_semaphores)
204+ except (ImportError, AttributeError):
205+ logging.warning('Failed to load plug-in: %s', modpath)
206+ return plugin_modules
207+
208+
209+def configure_plugins(loaded_plugins, options, args):
210+ """Configure the different plugins."""
211+ for plugin in loaded_plugins:
212+ plugin.plugin_options(options, args)
213
214=== added directory 'ubuntuone/devtools/plugins/reactors'
215=== added file 'ubuntuone/devtools/plugins/reactors/__init__.py'
216--- ubuntuone/devtools/plugins/reactors/__init__.py 1970-01-01 00:00:00 +0000
217+++ ubuntuone/devtools/plugins/reactors/__init__.py 2011-05-26 11:15:58 +0000
218@@ -0,0 +1,95 @@
219+# -*- coding: utf-8 -*-
220+
221+# Author: Manuel de la Pena manuel@canonical.com
222+#
223+# Copyright 2009-2010 Canonical Ltd.
224+#
225+# This program is free software: you can redistribute it and/or modify it
226+# under the terms of the GNU General Public License version 3, as published
227+# by the Free Software Foundation.
228+#
229+# This program is distributed in the hope that it will be useful, but
230+# WITHOUT ANY WARRANTY; without even the implied warranties of
231+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
232+# PURPOSE. See the GNU General Public License for more details.
233+#
234+# You should have received a copy of the GNU General Public License along
235+# with this program. If not, see <http://www.gnu.org/licenses/>.
236+"""Plugin that allows diff reactors to be used."""
237+
238+
239+import logging
240+import os
241+
242+REACTORS_PLUGIN_PATHS = [os.path.join(os.path.dirname(__file__))]
243+PLUGIN_NAME = __name__
244+
245+
246+def plugin_init(options, blocking_semaphores):
247+ """Set up the signal handler for pairing with Ubuntu One."""
248+ logging.info('Loading reactor plugins.')
249+ # Signal that we are critical for desktopcouch usage, and the server
250+ # must not begin until we are finished. We are responsible for
251+ # removing this item from the list.
252+ logging.info('adding %s to to blocking semaphore list', PLUGIN_NAME)
253+ blocking_semaphores.add(PLUGIN_NAME)
254+ reactor_names = set()
255+ reactor_names.add('glib')
256+ load_reactors(options, reactor_names)
257+ options.add_option('-r', '--reactor', type='string', dest='reactor',
258+ default='glib', help='Run the tests using the '
259+ + 'specified reactor. The installed reactors are %s' %
260+ reactor_names, metavar="REACTOR")
261+ blocking_semaphores.discard(PLUGIN_NAME)
262+
263+
264+def plugin_options(options, args):
265+ """React to the options passed by the user."""
266+ reactors_names = set()
267+ for path in REACTORS_PLUGIN_PATHS:
268+ try:
269+ for _file in os.listdir(path):
270+ if _file == '__init__':
271+ continue
272+ elif _file.endswith('.py') and _file != '__init__.py':
273+ reactors_names.add(os.path.join('ubuntuone', 'devtools',
274+ 'plugins', 'reactors', _file))
275+ except OSError:
276+ continue
277+
278+ for name in reactors_names:
279+ modpath = name.replace(os.path.sep, '.')[:-3]
280+ try:
281+ reactor = __import__(modpath, None, None, [''])
282+ if options.reactor == reactor.REACTOR_NAME:
283+ reactor.process_options(options)
284+ except (ImportError, AttributeError):
285+ logging.warning('Failed to load plug-in: %s', modpath)
286+
287+
288+def load_reactors(options, reactor_names):
289+ """Load the installed reactors in the system.
290+
291+ options -- The options set that is used to display extra arguments
292+ according to the plugin.
293+ reactor_names -- the set() that contains all the diff reactors.
294+ """
295+ reactors_names = set()
296+ for path in REACTORS_PLUGIN_PATHS:
297+ try:
298+ for _file in os.listdir(path):
299+ if _file == '__init__':
300+ continue
301+ elif _file.endswith('.py') and _file != '__init__.py':
302+ reactors_names.add(os.path.join('ubuntuone', 'devtools',
303+ 'plugins', 'reactors', _file))
304+ except OSError:
305+ continue
306+
307+ for name in reactors_names:
308+ modpath = name.replace(os.path.sep, '.')[:-3]
309+ try:
310+ reactor = __import__(modpath, None, None, [''])
311+ reactor.reactor_init(options, reactor_names)
312+ except (ImportError, AttributeError):
313+ logging.warning('Failed to load plug-in: %s', modpath)
314
315=== added file 'ubuntuone/devtools/plugins/reactors/glib.py'
316--- ubuntuone/devtools/plugins/reactors/glib.py 1970-01-01 00:00:00 +0000
317+++ ubuntuone/devtools/plugins/reactors/glib.py 2011-05-26 11:15:58 +0000
318@@ -0,0 +1,32 @@
319+# -*- coding: utf-8 -*-
320+
321+# Author: Manuel de la Pena manuel@canonical.com
322+#
323+# Copyright 2010-2011 Canonical Ltd.
324+#
325+# This program is free software: you can redistribute it and/or modify it
326+# under the terms of the GNU General Public License version 3, as published
327+# by the Free Software Foundation.
328+#
329+# This program is distributed in the hope that it will be useful, but
330+# WITHOUT ANY WARRANTY; without even the implied warranties of
331+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
332+# PURPOSE. See the GNU General Public License for more details.
333+#
334+# You should have received a copy of the GNU General Public License along
335+# with this program. If not, see <http://www.gnu.org/licenses/>.
336+"""Use the glib reactor to run the tests."""
337+
338+REACTOR_NAME = __name__[__name__.rfind('.') + 1:]
339+
340+
341+def reactor_init(options, reactor_names):
342+ """Init the required data so that the reactor can be choosen."""
343+ # not much to be done, lets just add the name to the list
344+ reactor_names.add(REACTOR_NAME)
345+
346+
347+def process_options(options):
348+ """Process the options provide by the user to perform the actions."""
349+ from twisted.internet import glib2reactor
350+ glib2reactor.install()
351
352=== added file 'ubuntuone/devtools/plugins/reactors/qtreactor.py'
353--- ubuntuone/devtools/plugins/reactors/qtreactor.py 1970-01-01 00:00:00 +0000
354+++ ubuntuone/devtools/plugins/reactors/qtreactor.py 2011-05-26 11:15:58 +0000
355@@ -0,0 +1,58 @@
356+# -*- coding: utf-8 -*-
357+
358+# Author: Manuel de la Pena manuel@canonical.com
359+#
360+# Copyright 2010-2011 Canonical Ltd.
361+#
362+# This program is free software: you can redistribute it and/or modify it
363+# under the terms of the GNU General Public License version 3, as published
364+# by the Free Software Foundation.
365+#
366+# This program is distributed in the hope that it will be useful, but
367+# WITHOUT ANY WARRANTY; without even the implied warranties of
368+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
369+# PURPOSE. See the GNU General Public License for more details.
370+#
371+# You should have received a copy of the GNU General Public License along
372+# with this program. If not, see <http://www.gnu.org/licenses/>
373+"""Use the qt reactor to run the tests."""
374+
375+
376+import logging
377+import sys
378+
379+QTREACTOR_URL = 'https://github.com/ghtdak/qtreactor'
380+REACTOR_NAME = __name__[__name__.rfind('.') + 1:]
381+
382+
383+def reactor_init(options, reactor_names):
384+ """Init the required data so that the reactor can be choosen."""
385+ # only provide the reacto if we can import it, otherwhise ignore it
386+ try:
387+ # pylint: disable=W0511, F0401
388+ # XXX: Don't know why but the reactor cannot be imported using
389+ # from txnamedpipes import reactor
390+ __import__('qtreactor.qt4reactor', None, None, [''])
391+ # pylint: enable=W0511
392+ reactor_names.add(REACTOR_NAME)
393+ options.add_option('--qt-ui', action='store_true', dest='qt_ui',
394+ default=False, help='State if the Qt reactor '
395+ + 'should be ran with ui support.')
396+ except ImportError:
397+ logging.info('The qtreactor python module is required. You can find '
398+ + 'it at: %s' % QTREACTOR_URL)
399+
400+
401+def process_options(options):
402+ """Process the options provide by the user to perform the actions."""
403+ # install the qtreactor so that we can start a qapplication in the
404+ # tests to work with
405+ if options.qt_ui:
406+ from PyQt4.QtGui import QApplication
407+ # pylint: disable=W0612
408+ app = QApplication(sys.argv)
409+ # pylint: enable=W0612
410+ # pylint: disable=W0511, F0401
411+ reactor = __import__('qtreactor.qt4reactor', None, None, [''])
412+ # pylint: enable=W0511
413+ reactor.install()
414
415=== added file 'ubuntuone/devtools/plugins/reactors/txnamedpipes.py'
416--- ubuntuone/devtools/plugins/reactors/txnamedpipes.py 1970-01-01 00:00:00 +0000
417+++ ubuntuone/devtools/plugins/reactors/txnamedpipes.py 2011-05-26 11:15:58 +0000
418@@ -0,0 +1,42 @@
419+# -*- coding: utf-8 -*-
420+
421+# Author: Manuel de la Pena manuel@canonical.com
422+#
423+# Copyright 2010-2011 Canonical Ltd.
424+#
425+# This program is free software: you can redistribute it and/or modify it
426+# under the terms of the GNU General Public License version 3, as published
427+# by the Free Software Foundation.
428+#
429+# This program is distributed in the hope that it will be useful, but
430+# WITHOUT ANY WARRANTY; without even the implied warranties of
431+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
432+# PURPOSE. See the GNU General Public License for more details.
433+#
434+# You should have received a copy of the GNU General Public License along
435+# with this program. If not, see <http://www.gnu.org/licenses/>.
436+"""Use the txnamedpipes reactor."""
437+
438+
439+import logging
440+
441+NAMEDPIPES_REACTOR_URL = 'https://launchpad.net/txnamedpipes'
442+REACTOR_NAME = __name__[__name__.rfind('.') + 1:]
443+
444+
445+def reactor_init(options, reactor_names):
446+ """Init the required data so that the reactor can be choosen."""
447+ try:
448+ # Don't know why but the reactor cannot be imported using
449+ # from txnamedpipes import reactor
450+ __import__('txnamedpipes.reactor', None, None, [''])
451+ reactor_names.add(REACTOR_NAME)
452+ except ImportError:
453+ logging.info('The txnamedpipes python module is required. You can'
454+ + ' find it at: %s' % NAMEDPIPES_REACTOR_URL)
455+
456+
457+def process_options(options):
458+ """Process the options provide by the user to perform the actions."""
459+ reactor = __import__('txnamedpipes.reactor', None, None, [''])
460+ reactor.install()
461
462=== added file 'ubuntuone/devtools/tests/test_plugins.py'
463--- ubuntuone/devtools/tests/test_plugins.py 1970-01-01 00:00:00 +0000
464+++ ubuntuone/devtools/tests/test_plugins.py 2011-05-26 11:15:58 +0000
465@@ -0,0 +1,51 @@
466+# -*- coding: utf-8 -*-
467+
468+# Author: Manuel de la Pena manuel@canonical.com
469+#
470+# Copyright 2009-2010 Canonical Ltd.
471+#
472+# This program is free software: you can redistribute it and/or modify it
473+# under the terms of the GNU General Public License version 3, as published
474+# by the Free Software Foundation.
475+#
476+# This program is distributed in the hope that it will be useful, but
477+# WITHOUT ANY WARRANTY; without even the implied warranties of
478+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
479+# PURPOSE. See the GNU General Public License for more details.
480+#
481+# You should have received a copy of the GNU General Public License along
482+# with this program. If not, see <http://www.gnu.org/licenses/>.
483+"""Test the plugins."""
484+
485+import os
486+
487+from ubuntuone.devtools import plugins
488+from unittest import TestCase
489+
490+
491+class TestPlugins(TestCase):
492+ """Test the loading of the plugins."""
493+
494+ def setUp(self):
495+ """Set the diff tests."""
496+ super(TestPlugins, self).setUp()
497+ self.options = None
498+ self.blockers = set()
499+ self._imported = None
500+
501+ def test_load_plugins(self):
502+ """Test that plugins are loaded."""
503+ plugins.DEVTOOLS_PLUGIN_PATHS = [os.path.join(
504+ os.path.dirname(__file__))]
505+
506+ def _fake_import(name, *args, **kwargs):
507+ """Fake import method."""
508+ modname = name.replace('.plugins.', '.tests.')
509+ if modname == __name__:
510+ self._imported = modname
511+
512+ old_import = __import__
513+ __builtins__['__import__'] = _fake_import
514+ plugins.load_plugins(self.options, self.blockers)
515+ __builtins__['__import__'] = old_import
516+ self.assertEqual(self._imported, __name__)

Subscribers

People subscribed via source and target branches

to all changes: