bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
1 |
# Copyright (C) 2005-2012, 2016 Canonical Ltd, 2017 Breezy developers
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
|
750
by Martin Pool
- stubbed-out tests for python plugins |
3 |
# This program is free software; you can redistribute it and/or modify
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
|
750
by Martin Pool
- stubbed-out tests for python plugins |
8 |
# This program is distributed in the hope that it will be useful,
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
|
2052.3.1
by John Arbash Meinel
Add tests to cleanup the copyright of all source files |
12 |
#
|
|
750
by Martin Pool
- stubbed-out tests for python plugins |
13 |
# You should have received a copy of the GNU General Public License
|
14 |
# along with this program; if not, write to the Free Software
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
750
by Martin Pool
- stubbed-out tests for python plugins |
16 |
|
17 |
"""Tests for plugins"""
|
|
18 |
||
|
6791.2.3
by Jelmer Vernooij
Fix more imports. |
19 |
try: |
20 |
from importlib.util import module_from_spec |
|
21 |
except ImportError: # python < 3 |
|
22 |
from imp import new_module as module_from_spec |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
23 |
import importlib |
|
2967.4.5
by Daniel Watkins
Added test for badly-named plugins. |
24 |
import logging |
|
1185.16.83
by mbp at sourcefrog
- notes on testability of plugins |
25 |
import os |
|
2256.2.2
by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not |
26 |
import sys |
|
750
by Martin Pool
- stubbed-out tests for python plugins |
27 |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
28 |
import breezy |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
29 |
from .. import ( |
|
5268.5.1
by Vincent Ladeuil
Reproduce bug #591215. |
30 |
errors, |
|
4628.2.2
by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH. |
31 |
osutils, |
32 |
plugin, |
|
33 |
tests, |
|
|
5086.1.8
by Vincent Ladeuil
Fix warnings during autoload, add doc and a NEWS entry. |
34 |
trace, |
|
4628.2.2
by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH. |
35 |
)
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
36 |
from ..sixish import ( |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
37 |
PY3, |
38 |
StringIO, |
|
39 |
viewkeys, |
|
|
6621.22.2
by Martin
Use BytesIO or StringIO from bzrlib.sixish |
40 |
)
|
|
1141
by Martin Pool
- rename FunctionalTest to TestCaseInTempDir |
41 |
|
|
1185.16.83
by mbp at sourcefrog
- notes on testability of plugins |
42 |
|
|
1492
by Robert Collins
Support decoration of commands. |
43 |
# TODO: Write a test for plugin decoration of commands.
|
|
1515
by Robert Collins
* Plugins with the same name in different directories in the bzr plugin |
44 |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
45 |
invalidate_caches = getattr(importlib, "invalidate_caches", lambda: None) |
46 |
||
47 |
||
|
5616.7.10
by Martin Pool
Clean up describe_plugins to sort loaded and unloaded plugins together. |
48 |
class BaseTestPlugins(tests.TestCaseInTempDir): |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
49 |
"""TestCase that isolates plugin imports and cleans up on completion.""" |
50 |
||
51 |
def setUp(self): |
|
52 |
super(BaseTestPlugins, self).setUp() |
|
53 |
self.module_name = "breezy.testingplugins" |
|
54 |
self.module_prefix = self.module_name + "." |
|
|
6791.2.3
by Jelmer Vernooij
Fix more imports. |
55 |
self.module = module_from_spec(self.module_name) |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
56 |
|
57 |
self.overrideAttr(plugin, "_MODULE_PREFIX", self.module_prefix) |
|
58 |
self.overrideAttr(breezy, "testingplugins", self.module) |
|
59 |
||
60 |
sys.modules[self.module_name] = self.module |
|
61 |
self.addCleanup(self._unregister_all) |
|
62 |
self.addCleanup(self._unregister_finder) |
|
63 |
||
64 |
invalidate_caches() |
|
65 |
||
66 |
def reset(self): |
|
67 |
"""Remove all global testing state and clean up module.""" |
|
68 |
# GZ 2017-06-02: Ideally don't do this, write new test or generate
|
|
69 |
# bytecode by other mechanism.
|
|
70 |
self.log("resetting plugin testing context") |
|
71 |
self._unregister_all() |
|
72 |
self._unregister_finder() |
|
73 |
sys.modules[self.module_name] = self.module |
|
74 |
for name in list(self.module.__dict__): |
|
75 |
if name[:2] != '__': |
|
76 |
delattr(self.module, name) |
|
77 |
invalidate_caches() |
|
78 |
self.plugins = None |
|
79 |
||
80 |
def update_module_paths(self, paths): |
|
81 |
paths = plugin.extend_path(paths, self.module_name) |
|
82 |
self.module.__path__ = paths |
|
83 |
self.log("using %r", paths) |
|
84 |
return paths |
|
85 |
||
86 |
def load_with_paths(self, paths): |
|
87 |
self.log("loading plugins!") |
|
88 |
plugin.load_plugins(self.update_module_paths(paths), state=self) |
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
89 |
|
|
5086.5.8
by Vincent Ladeuil
Make sure we can load from a non-standard directory name. |
90 |
def create_plugin(self, name, source=None, dir='.', file_name=None): |
91 |
if source is None: |
|
92 |
source = '''\ |
|
93 |
"""This is the doc for %s""" |
|
94 |
''' % (name) |
|
|
5086.1.6
by Vincent Ladeuil
Crude fix for bug #411413. |
95 |
if file_name is None: |
96 |
file_name = name + '.py' |
|
97 |
# 'source' must not fail to load
|
|
|
5086.1.7
by Vincent Ladeuil
Cleaner fix for bug #411413. |
98 |
path = osutils.pathjoin(dir, file_name) |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
99 |
with open(path, 'w') as f: |
|
5086.1.6
by Vincent Ladeuil
Crude fix for bug #411413. |
100 |
f.write(source + '\n') |
101 |
||
|
5086.5.8
by Vincent Ladeuil
Make sure we can load from a non-standard directory name. |
102 |
def create_plugin_package(self, name, dir=None, source=None): |
103 |
if dir is None: |
|
104 |
dir = name |
|
105 |
if source is None: |
|
106 |
source = '''\ |
|
107 |
"""This is the doc for %s""" |
|
108 |
dir_source = '%s' |
|
109 |
''' % (name, dir) |
|
110 |
os.makedirs(dir) |
|
111 |
self.create_plugin(name, source, dir, |
|
|
5086.1.6
by Vincent Ladeuil
Crude fix for bug #411413. |
112 |
file_name='__init__.py') |
113 |
||
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
114 |
def promote_cache(self, directory): |
115 |
"""Move bytecode files out of __pycache__ in given directory.""" |
|
116 |
cache_dir = os.path.join(directory, '__pycache__') |
|
117 |
if os.path.isdir(cache_dir): |
|
118 |
for name in os.listdir(cache_dir): |
|
119 |
magicless_name = '.'.join(name.split('.')[0::name.count('.')]) |
|
120 |
rel = osutils.relpath(self.test_dir, cache_dir) |
|
121 |
self.log("moving %s in %s to %s", name, rel, magicless_name) |
|
122 |
os.rename(os.path.join(cache_dir, name), |
|
123 |
os.path.join(directory, magicless_name)) |
|
124 |
||
125 |
def _unregister_finder(self): |
|
126 |
"""Removes any test copies of _PluginsAtFinder from sys.meta_path.""" |
|
127 |
idx = len(sys.meta_path) |
|
128 |
while idx: |
|
129 |
idx -= 1 |
|
130 |
finder = sys.meta_path[idx] |
|
131 |
if getattr(finder, "prefix", "") == self.module_prefix: |
|
132 |
self.log("removed %r from sys.meta_path", finder) |
|
133 |
sys.meta_path.pop(idx) |
|
134 |
||
135 |
def _unregister_all(self): |
|
136 |
"""Remove all plugins in the test namespace from sys.modules.""" |
|
137 |
for name in list(sys.modules): |
|
138 |
if name.startswith(self.module_prefix) or name == self.module_name: |
|
139 |
self.log("removed %s from sys.modules", name) |
|
140 |
del sys.modules[name] |
|
141 |
||
142 |
def assertPluginModules(self, plugin_dict): |
|
143 |
self.assertEqual( |
|
144 |
dict((k[len(self.module_prefix):], sys.modules[k]) |
|
145 |
for k in sys.modules if k.startswith(self.module_prefix)), |
|
146 |
plugin_dict) |
|
|
5268.6.1
by Vincent Ladeuil
Drive-by fix of the submodule leak. |
147 |
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
148 |
def assertPluginUnknown(self, name): |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
149 |
self.assertTrue(getattr(self.module, name, None) is None) |
150 |
self.assertFalse(self.module_prefix + name in sys.modules) |
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
151 |
|
152 |
def assertPluginKnown(self, name): |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
153 |
self.assertTrue(getattr(self.module, name, None) is not None) |
154 |
self.assertTrue(self.module_prefix + name in sys.modules) |
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
155 |
|
156 |
||
|
5616.7.10
by Martin Pool
Clean up describe_plugins to sort loaded and unloaded plugins together. |
157 |
class TestLoadingPlugins(BaseTestPlugins): |
|
1515
by Robert Collins
* Plugins with the same name in different directories in the bzr plugin |
158 |
|
159 |
activeattributes = {} |
|
160 |
||
161 |
def test_plugins_with_the_same_name_are_not_loaded(self): |
|
|
2256.2.2
by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not |
162 |
# This test tests that having two plugins in different directories does
|
163 |
# not result in both being loaded when they have the same name. get a
|
|
164 |
# file name we can use which is also a valid attribute for accessing in
|
|
165 |
# activeattributes. - we cannot give import parameters.
|
|
|
1515
by Robert Collins
* Plugins with the same name in different directories in the bzr plugin |
166 |
tempattribute = "0" |
|
5784.1.1
by Martin Pool
Stop using failIf, failUnless, etc |
167 |
self.assertFalse(tempattribute in self.activeattributes) |
|
1515
by Robert Collins
* Plugins with the same name in different directories in the bzr plugin |
168 |
# set a place for the plugins to record their loading, and at the same
|
169 |
# time validate that the location the plugins should record to is
|
|
170 |
# valid and correct.
|
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
171 |
self.__class__.activeattributes [tempattribute] = [] |
|
5784.1.1
by Martin Pool
Stop using failIf, failUnless, etc |
172 |
self.assertTrue(tempattribute in self.activeattributes) |
|
1515
by Robert Collins
* Plugins with the same name in different directories in the bzr plugin |
173 |
# create two plugin directories
|
174 |
os.mkdir('first') |
|
175 |
os.mkdir('second') |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
176 |
# write a plugin that will record when its loaded in the
|
|
1515
by Robert Collins
* Plugins with the same name in different directories in the bzr plugin |
177 |
# tempattribute list.
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
178 |
template = ("from breezy.tests.test_plugins import TestLoadingPlugins\n" |
|
2256.2.2
by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not |
179 |
"TestLoadingPlugins.activeattributes[%r].append('%s')\n") |
|
2652.2.7
by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely. |
180 |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
181 |
with open(os.path.join('first', 'plugin.py'), 'w') as outfile: |
|
2911.6.1
by Blake Winton
Change 'print >> f,'s to 'f.write('s. |
182 |
outfile.write(template % (tempattribute, 'first')) |
183 |
outfile.write('\n') |
|
|
2652.2.7
by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely. |
184 |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
185 |
with open(os.path.join('second', 'plugin.py'), 'w') as outfile: |
|
2911.6.1
by Blake Winton
Change 'print >> f,'s to 'f.write('s. |
186 |
outfile.write(template % (tempattribute, 'second')) |
187 |
outfile.write('\n') |
|
|
2652.2.7
by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely. |
188 |
|
|
1515
by Robert Collins
* Plugins with the same name in different directories in the bzr plugin |
189 |
try: |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
190 |
self.load_with_paths(['first', 'second']) |
|
2256.2.2
by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not |
191 |
self.assertEqual(['first'], self.activeattributes[tempattribute]) |
192 |
finally: |
|
193 |
del self.activeattributes[tempattribute] |
|
194 |
||
195 |
def test_plugins_from_different_dirs_can_demand_load(self): |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
196 |
self.assertFalse('breezy.plugins.pluginone' in sys.modules) |
197 |
self.assertFalse('breezy.plugins.plugintwo' in sys.modules) |
|
|
2256.2.2
by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not |
198 |
# This test tests that having two plugins in different
|
199 |
# directories with different names allows them both to be loaded, when
|
|
200 |
# we do a direct import statement.
|
|
201 |
# Determine a file name we can use which is also a valid attribute
|
|
202 |
# for accessing in activeattributes. - we cannot give import parameters.
|
|
203 |
tempattribute = "different-dirs" |
|
|
5784.1.1
by Martin Pool
Stop using failIf, failUnless, etc |
204 |
self.assertFalse(tempattribute in self.activeattributes) |
|
2256.2.2
by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not |
205 |
# set a place for the plugins to record their loading, and at the same
|
206 |
# time validate that the location the plugins should record to is
|
|
207 |
# valid and correct.
|
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
208 |
breezy.tests.test_plugins.TestLoadingPlugins.activeattributes \ |
|
2256.2.2
by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not |
209 |
[tempattribute] = [] |
|
5784.1.1
by Martin Pool
Stop using failIf, failUnless, etc |
210 |
self.assertTrue(tempattribute in self.activeattributes) |
|
2256.2.2
by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not |
211 |
# create two plugin directories
|
212 |
os.mkdir('first') |
|
213 |
os.mkdir('second') |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
214 |
# write plugins that will record when they are loaded in the
|
|
2256.2.2
by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not |
215 |
# tempattribute list.
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
216 |
template = ("from breezy.tests.test_plugins import TestLoadingPlugins\n" |
|
2256.2.2
by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not |
217 |
"TestLoadingPlugins.activeattributes[%r].append('%s')\n") |
|
2652.2.7
by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely. |
218 |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
219 |
with open(os.path.join('first', 'pluginone.py'), 'w') as outfile: |
|
2911.6.1
by Blake Winton
Change 'print >> f,'s to 'f.write('s. |
220 |
outfile.write(template % (tempattribute, 'first')) |
221 |
outfile.write('\n') |
|
|
2652.2.7
by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely. |
222 |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
223 |
with open(os.path.join('second', 'plugintwo.py'), 'w') as outfile: |
|
2911.6.1
by Blake Winton
Change 'print >> f,'s to 'f.write('s. |
224 |
outfile.write(template % (tempattribute, 'second')) |
225 |
outfile.write('\n') |
|
|
2652.2.7
by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely. |
226 |
|
|
2256.2.2
by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not |
227 |
try: |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
228 |
self.assertPluginUnknown('pluginone') |
229 |
self.assertPluginUnknown('plugintwo') |
|
230 |
self.update_module_paths(['first', 'second']) |
|
231 |
exec("import %spluginone" % self.module_prefix) |
|
|
2256.2.2
by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not |
232 |
self.assertEqual(['first'], self.activeattributes[tempattribute]) |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
233 |
exec("import %splugintwo" % self.module_prefix) |
|
2256.2.2
by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not |
234 |
self.assertEqual(['first', 'second'], |
235 |
self.activeattributes[tempattribute]) |
|
|
1515
by Robert Collins
* Plugins with the same name in different directories in the bzr plugin |
236 |
finally: |
237 |
del self.activeattributes[tempattribute] |
|
|
1516
by Robert Collins
* bzrlib.plugin.all_plugins has been changed from an attribute to a |
238 |
|
|
2652.2.1
by Blake Winton
Add a test for BZR_PLUGIN_PATH, and code and another test to allow BZR_PLUGIN_PATH to contain trailing slashes. |
239 |
def test_plugins_can_load_from_directory_with_trailing_slash(self): |
240 |
# This test tests that a plugin can load from a directory when the
|
|
241 |
# directory in the path has a trailing slash.
|
|
|
2652.2.7
by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely. |
242 |
# check the plugin is not loaded already
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
243 |
self.assertPluginUnknown('ts_plugin') |
|
2652.2.7
by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely. |
244 |
tempattribute = "trailing-slash" |
|
5784.1.1
by Martin Pool
Stop using failIf, failUnless, etc |
245 |
self.assertFalse(tempattribute in self.activeattributes) |
|
2652.2.3
by Blake Winton
Understand the code and comments of the test, instead of just cargo-culting them. |
246 |
# set a place for the plugin to record its loading, and at the same
|
247 |
# time validate that the location the plugin should record to is
|
|
|
2652.2.1
by Blake Winton
Add a test for BZR_PLUGIN_PATH, and code and another test to allow BZR_PLUGIN_PATH to contain trailing slashes. |
248 |
# valid and correct.
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
249 |
breezy.tests.test_plugins.TestLoadingPlugins.activeattributes \ |
|
2652.2.1
by Blake Winton
Add a test for BZR_PLUGIN_PATH, and code and another test to allow BZR_PLUGIN_PATH to contain trailing slashes. |
250 |
[tempattribute] = [] |
|
5784.1.1
by Martin Pool
Stop using failIf, failUnless, etc |
251 |
self.assertTrue(tempattribute in self.activeattributes) |
|
2652.2.3
by Blake Winton
Understand the code and comments of the test, instead of just cargo-culting them. |
252 |
# create a directory for the plugin
|
253 |
os.mkdir('plugin_test') |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
254 |
# write a plugin that will record when its loaded in the
|
|
2652.2.1
by Blake Winton
Add a test for BZR_PLUGIN_PATH, and code and another test to allow BZR_PLUGIN_PATH to contain trailing slashes. |
255 |
# tempattribute list.
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
256 |
template = ("from breezy.tests.test_plugins import TestLoadingPlugins\n" |
|
2652.2.1
by Blake Winton
Add a test for BZR_PLUGIN_PATH, and code and another test to allow BZR_PLUGIN_PATH to contain trailing slashes. |
257 |
"TestLoadingPlugins.activeattributes[%r].append('%s')\n") |
|
2652.2.7
by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely. |
258 |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
259 |
with open(os.path.join('plugin_test', 'ts_plugin.py'), 'w') as outfile: |
|
2911.6.1
by Blake Winton
Change 'print >> f,'s to 'f.write('s. |
260 |
outfile.write(template % (tempattribute, 'plugin')) |
|
2911.6.4
by Blake Winton
Fix test failures |
261 |
outfile.write('\n') |
|
2652.2.7
by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely. |
262 |
|
|
2652.2.1
by Blake Winton
Add a test for BZR_PLUGIN_PATH, and code and another test to allow BZR_PLUGIN_PATH to contain trailing slashes. |
263 |
try: |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
264 |
self.load_with_paths(['plugin_test'+os.sep]) |
|
2652.2.3
by Blake Winton
Understand the code and comments of the test, instead of just cargo-culting them. |
265 |
self.assertEqual(['plugin'], self.activeattributes[tempattribute]) |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
266 |
self.assertPluginKnown('ts_plugin') |
|
2652.2.1
by Blake Winton
Add a test for BZR_PLUGIN_PATH, and code and another test to allow BZR_PLUGIN_PATH to contain trailing slashes. |
267 |
finally: |
268 |
del self.activeattributes[tempattribute] |
|
269 |
||
|
3766.3.2
by Robert Collins
Fix reporting of incompatible api plugin load errors, fixing bug 279451. |
270 |
def load_and_capture(self, name): |
271 |
"""Load plugins from '.' capturing the output. |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
272 |
|
|
3766.3.2
by Robert Collins
Fix reporting of incompatible api plugin load errors, fixing bug 279451. |
273 |
:param name: The name of the plugin.
|
274 |
:return: A string with the log from the plugin loading call.
|
|
275 |
"""
|
|
|
2967.4.5
by Daniel Watkins
Added test for badly-named plugins. |
276 |
# Capture output
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
277 |
stream = StringIO() |
|
3766.3.2
by Robert Collins
Fix reporting of incompatible api plugin load errors, fixing bug 279451. |
278 |
try: |
279 |
handler = logging.StreamHandler(stream) |
|
|
6622.1.33
by Jelmer Vernooij
Fix more tests (all?) |
280 |
log = logging.getLogger('brz') |
|
3766.3.2
by Robert Collins
Fix reporting of incompatible api plugin load errors, fixing bug 279451. |
281 |
log.addHandler(handler) |
282 |
try: |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
283 |
self.load_with_paths(['.']) |
|
3766.3.2
by Robert Collins
Fix reporting of incompatible api plugin load errors, fixing bug 279451. |
284 |
finally: |
285 |
# Stop capturing output
|
|
286 |
handler.flush() |
|
287 |
handler.close() |
|
288 |
log.removeHandler(handler) |
|
289 |
return stream.getvalue() |
|
290 |
finally: |
|
291 |
stream.close() |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
292 |
|
|
3766.3.2
by Robert Collins
Fix reporting of incompatible api plugin load errors, fixing bug 279451. |
293 |
def test_plugin_with_bad_api_version_reports(self): |
|
5616.7.3
by Martin Pool
Put plugin warnings into both the apport and plain crash report |
294 |
"""Try loading a plugin that requests an unsupported api. |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
295 |
|
|
5616.7.12
by Martin Pool
Comment correction |
296 |
Observe that it records the problem but doesn't complain on stderr.
|
|
5616.7.7
by Martin Pool
Paper over test global state dependency |
297 |
|
298 |
See https://bugs.launchpad.net/bzr/+bug/704195
|
|
|
5616.7.3
by Martin Pool
Put plugin warnings into both the apport and plain crash report |
299 |
"""
|
|
3766.3.2
by Robert Collins
Fix reporting of incompatible api plugin load errors, fixing bug 279451. |
300 |
name = 'wants100.py' |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
301 |
with open(name, 'w') as f: |
|
6672.1.2
by Jelmer Vernooij
Remove breezy.api. |
302 |
f.write("import breezy\n" |
303 |
"from breezy.errors import IncompatibleVersion\n" |
|
304 |
"raise IncompatibleVersion(breezy, [(1, 0, 0)], (0, 0, 5))\n") |
|
|
3766.3.2
by Robert Collins
Fix reporting of incompatible api plugin load errors, fixing bug 279451. |
305 |
log = self.load_and_capture(name) |
|
5616.7.1
by Martin Pool
Record but don't show warnings about updated plugins |
306 |
self.assertNotContainsRe(log, |
|
6672.1.2
by Jelmer Vernooij
Remove breezy.api. |
307 |
r"It supports breezy version") |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
308 |
self.assertEqual({'wants100'}, viewkeys(self.plugin_warnings)) |
|
5616.7.1
by Martin Pool
Record but don't show warnings about updated plugins |
309 |
self.assertContainsRe( |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
310 |
self.plugin_warnings['wants100'][0], |
|
6672.1.2
by Jelmer Vernooij
Remove breezy.api. |
311 |
r"It supports breezy version") |
|
3766.3.2
by Robert Collins
Fix reporting of incompatible api plugin load errors, fixing bug 279451. |
312 |
|
313 |
def test_plugin_with_bad_name_does_not_load(self): |
|
314 |
# The file name here invalid for a python module.
|
|
|
6622.1.33
by Jelmer Vernooij
Fix more tests (all?) |
315 |
name = 'brz-bad plugin-name..py' |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
316 |
open(name, 'w').close() |
|
3766.3.2
by Robert Collins
Fix reporting of incompatible api plugin load errors, fixing bug 279451. |
317 |
log = self.load_and_capture(name) |
318 |
self.assertContainsRe(log, |
|
|
6622.1.33
by Jelmer Vernooij
Fix more tests (all?) |
319 |
r"Unable to load 'brz-bad plugin-name\.' in '\.' as a plugin " |
|
3290.1.1
by James Westby
Strip "bzr_" from the start of the suggested plugin name. |
320 |
"because the file path isn't a valid module name; try renaming "
|
|
6798.1.1
by Jelmer Vernooij
Properly escape backslashes. |
321 |
"it to 'bad_plugin_name_'\\.") |
|
2967.4.5
by Daniel Watkins
Added test for badly-named plugins. |
322 |
|
|
1516
by Robert Collins
* bzrlib.plugin.all_plugins has been changed from an attribute to a |
323 |
|
|
5616.7.10
by Martin Pool
Clean up describe_plugins to sort loaded and unloaded plugins together. |
324 |
class TestPlugins(BaseTestPlugins): |
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
325 |
|
326 |
def setup_plugin(self, source=""): |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
327 |
# This test tests a new plugin appears in breezy.plugin.plugins().
|
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
328 |
# check the plugin is not loaded already
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
329 |
self.assertPluginUnknown('plugin') |
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
330 |
# write a plugin that _cannot_ fail to load.
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
331 |
with open('plugin.py', 'w') as f: f.write(source + '\n') |
332 |
self.load_with_paths(['.']) |
|
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
333 |
|
|
6759.4.3
by Jelmer Vernooij
Avoid accessing global state. |
334 |
def test_plugin_loaded(self): |
335 |
self.assertPluginUnknown('plugin') |
|
336 |
self.assertIs(None, breezy.plugin.get_loaded_plugin('plugin')) |
|
337 |
self.setup_plugin() |
|
338 |
p = breezy.plugin.get_loaded_plugin('plugin') |
|
339 |
self.assertIsInstance(p, breezy.plugin.PlugIn) |
|
340 |
self.assertIs(p.module, sys.modules[self.module_prefix + 'plugin']) |
|
341 |
||
|
6780.1.1
by Jelmer Vernooij
Check for plugin existing in sys.modules but being None. |
342 |
def test_plugin_loaded_disabled(self): |
343 |
self.assertPluginUnknown('plugin') |
|
344 |
self.overrideEnv('BRZ_DISABLE_PLUGINS', 'plugin') |
|
345 |
self.setup_plugin() |
|
346 |
self.assertIs(None, breezy.plugin.get_loaded_plugin('plugin')) |
|
347 |
||
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
348 |
def test_plugin_appears_in_plugins(self): |
349 |
self.setup_plugin() |
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
350 |
self.assertPluginKnown('plugin') |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
351 |
p = self.plugins['plugin'] |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
352 |
self.assertIsInstance(p, breezy.plugin.PlugIn) |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
353 |
self.assertIs(p.module, sys.modules[self.module_prefix + 'plugin']) |
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
354 |
|
355 |
def test_trivial_plugin_get_path(self): |
|
356 |
self.setup_plugin() |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
357 |
p = self.plugins['plugin'] |
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
358 |
plugin_path = self.test_dir + '/plugin.py' |
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
359 |
self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path())) |
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
360 |
|
|
3193.2.1
by Alexander Belchenko
show path to plugin module as *.py instead of *.pyc if python source available |
361 |
def test_plugin_get_path_py_not_pyc(self): |
|
5086.1.3
by Vincent Ladeuil
Fix imports in test_plugins. |
362 |
# first import creates plugin.pyc
|
363 |
self.setup_plugin() |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
364 |
self.promote_cache(self.test_dir) |
365 |
self.reset() |
|
366 |
self.load_with_paths(['.']) # import plugin.pyc |
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
367 |
p = plugin.plugins()['plugin'] |
|
3193.2.1
by Alexander Belchenko
show path to plugin module as *.py instead of *.pyc if python source available |
368 |
plugin_path = self.test_dir + '/plugin.py' |
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
369 |
self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path())) |
|
3193.2.1
by Alexander Belchenko
show path to plugin module as *.py instead of *.pyc if python source available |
370 |
|
371 |
def test_plugin_get_path_pyc_only(self): |
|
|
5086.1.3
by Vincent Ladeuil
Fix imports in test_plugins. |
372 |
# first import creates plugin.pyc (or plugin.pyo depending on __debug__)
|
373 |
self.setup_plugin() |
|
|
3193.2.1
by Alexander Belchenko
show path to plugin module as *.py instead of *.pyc if python source available |
374 |
os.unlink(self.test_dir + '/plugin.py') |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
375 |
self.promote_cache(self.test_dir) |
376 |
self.reset() |
|
377 |
self.load_with_paths(['.']) # import plugin.pyc (or .pyo) |
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
378 |
p = plugin.plugins()['plugin'] |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
379 |
plugin_path = self.test_dir + '/plugin' + plugin.COMPILED_EXT |
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
380 |
self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path())) |
|
3193.2.1
by Alexander Belchenko
show path to plugin module as *.py instead of *.pyc if python source available |
381 |
|
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
382 |
def test_no_test_suite_gives_None_for_test_suite(self): |
383 |
self.setup_plugin() |
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
384 |
p = plugin.plugins()['plugin'] |
385 |
self.assertEqual(None, p.test_suite()) |
|
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
386 |
|
387 |
def test_test_suite_gives_test_suite_result(self): |
|
388 |
source = """def test_suite(): return 'foo'""" |
|
389 |
self.setup_plugin(source) |
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
390 |
p = plugin.plugins()['plugin'] |
391 |
self.assertEqual('foo', p.test_suite()) |
|
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
392 |
|
|
3302.8.21
by Vincent Ladeuil
Fixed as per Robert's review. |
393 |
def test_no_load_plugin_tests_gives_None_for_load_plugin_tests(self): |
|
3302.8.10
by Vincent Ladeuil
Prepare bzrlib.plugin to use the new test loader. |
394 |
self.setup_plugin() |
|
5086.1.3
by Vincent Ladeuil
Fix imports in test_plugins. |
395 |
loader = tests.TestUtil.TestLoader() |
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
396 |
p = plugin.plugins()['plugin'] |
397 |
self.assertEqual(None, p.load_plugin_tests(loader)) |
|
|
3302.8.10
by Vincent Ladeuil
Prepare bzrlib.plugin to use the new test loader. |
398 |
|
|
3302.8.21
by Vincent Ladeuil
Fixed as per Robert's review. |
399 |
def test_load_plugin_tests_gives_load_plugin_tests_result(self): |
|
3302.8.10
by Vincent Ladeuil
Prepare bzrlib.plugin to use the new test loader. |
400 |
source = """ |
|
6625.1.5
by Martin
Drop custom load_tests implementation and use unittest signature |
401 |
def load_tests(loader, standard_tests, pattern):
|
|
3302.8.10
by Vincent Ladeuil
Prepare bzrlib.plugin to use the new test loader. |
402 |
return 'foo'"""
|
403 |
self.setup_plugin(source) |
|
|
5086.1.3
by Vincent Ladeuil
Fix imports in test_plugins. |
404 |
loader = tests.TestUtil.TestLoader() |
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
405 |
p = plugin.plugins()['plugin'] |
406 |
self.assertEqual('foo', p.load_plugin_tests(loader)) |
|
407 |
||
408 |
def check_version_info(self, expected, source='', name='plugin'): |
|
409 |
self.setup_plugin(source) |
|
410 |
self.assertEqual(expected, plugin.plugins()[name].version_info()) |
|
|
3302.8.10
by Vincent Ladeuil
Prepare bzrlib.plugin to use the new test loader. |
411 |
|
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
412 |
def test_no_version_info(self): |
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
413 |
self.check_version_info(None) |
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
414 |
|
415 |
def test_with_version_info(self): |
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
416 |
self.check_version_info((1, 2, 3, 'dev', 4), |
417 |
"version_info = (1, 2, 3, 'dev', 4)") |
|
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
418 |
|
419 |
def test_short_version_info_gets_padded(self): |
|
420 |
# the gtk plugin has version_info = (1,2,3) rather than the 5-tuple.
|
|
421 |
# so we adapt it
|
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
422 |
self.check_version_info((1, 2, 3, 'final', 0), |
423 |
"version_info = (1, 2, 3)") |
|
424 |
||
425 |
def check_version(self, expected, source=None, name='plugin'): |
|
426 |
self.setup_plugin(source) |
|
427 |
self.assertEqual(expected, plugins[name].__version__) |
|
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
428 |
|
429 |
def test_no_version_info___version__(self): |
|
430 |
self.setup_plugin() |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
431 |
plugin = breezy.plugin.plugins()['plugin'] |
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
432 |
self.assertEqual("unknown", plugin.__version__) |
433 |
||
|
3777.6.7
by Marius Kruger
* Can now also handle non-iteratable and string plugin versions. |
434 |
def test_str__version__with_version_info(self): |
435 |
self.setup_plugin("version_info = '1.2.3'") |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
436 |
plugin = breezy.plugin.plugins()['plugin'] |
|
3777.6.7
by Marius Kruger
* Can now also handle non-iteratable and string plugin versions. |
437 |
self.assertEqual("1.2.3", plugin.__version__) |
438 |
||
439 |
def test_noniterable__version__with_version_info(self): |
|
440 |
self.setup_plugin("version_info = (1)") |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
441 |
plugin = breezy.plugin.plugins()['plugin'] |
|
3777.6.7
by Marius Kruger
* Can now also handle non-iteratable and string plugin versions. |
442 |
self.assertEqual("1", plugin.__version__) |
443 |
||
444 |
def test_1__version__with_version_info(self): |
|
445 |
self.setup_plugin("version_info = (1,)") |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
446 |
plugin = breezy.plugin.plugins()['plugin'] |
|
3777.6.7
by Marius Kruger
* Can now also handle non-iteratable and string plugin versions. |
447 |
self.assertEqual("1", plugin.__version__) |
448 |
||
449 |
def test_1_2__version__with_version_info(self): |
|
|
3777.6.5
by Marius Kruger
add 2 more tests for plugin version numbers |
450 |
self.setup_plugin("version_info = (1, 2)") |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
451 |
plugin = breezy.plugin.plugins()['plugin'] |
|
3777.6.5
by Marius Kruger
add 2 more tests for plugin version numbers |
452 |
self.assertEqual("1.2", plugin.__version__) |
453 |
||
|
3777.6.7
by Marius Kruger
* Can now also handle non-iteratable and string plugin versions. |
454 |
def test_1_2_3__version__with_version_info(self): |
|
3777.6.5
by Marius Kruger
add 2 more tests for plugin version numbers |
455 |
self.setup_plugin("version_info = (1, 2, 3)") |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
456 |
plugin = breezy.plugin.plugins()['plugin'] |
|
3777.6.5
by Marius Kruger
add 2 more tests for plugin version numbers |
457 |
self.assertEqual("1.2.3", plugin.__version__) |
458 |
||
459 |
def test_candidate__version__with_version_info(self): |
|
|
3777.6.4
by Marius Kruger
fix tests |
460 |
self.setup_plugin("version_info = (1, 2, 3, 'candidate', 1)") |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
461 |
plugin = breezy.plugin.plugins()['plugin'] |
|
3777.6.4
by Marius Kruger
fix tests |
462 |
self.assertEqual("1.2.3rc1", plugin.__version__) |
463 |
||
464 |
def test_dev__version__with_version_info(self): |
|
465 |
self.setup_plugin("version_info = (1, 2, 3, 'dev', 0)") |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
466 |
plugin = breezy.plugin.plugins()['plugin'] |
|
3777.6.4
by Marius Kruger
fix tests |
467 |
self.assertEqual("1.2.3dev", plugin.__version__) |
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
468 |
|
|
3777.6.7
by Marius Kruger
* Can now also handle non-iteratable and string plugin versions. |
469 |
def test_dev_fallback__version__with_version_info(self): |
470 |
self.setup_plugin("version_info = (1, 2, 3, 'dev', 4)") |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
471 |
plugin = breezy.plugin.plugins()['plugin'] |
|
4634.50.6
by John Arbash Meinel
Handle a plugin fallback versioning issue. |
472 |
self.assertEqual("1.2.3dev4", plugin.__version__) |
|
3777.6.7
by Marius Kruger
* Can now also handle non-iteratable and string plugin versions. |
473 |
|
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
474 |
def test_final__version__with_version_info(self): |
|
3777.6.4
by Marius Kruger
fix tests |
475 |
self.setup_plugin("version_info = (1, 2, 3, 'final', 0)") |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
476 |
plugin = breezy.plugin.plugins()['plugin'] |
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
477 |
self.assertEqual("1.2.3", plugin.__version__) |
478 |
||
|
4634.50.6
by John Arbash Meinel
Handle a plugin fallback versioning issue. |
479 |
def test_final_fallback__version__with_version_info(self): |
480 |
self.setup_plugin("version_info = (1, 2, 3, 'final', 2)") |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
481 |
plugin = breezy.plugin.plugins()['plugin'] |
|
5851.2.2
by Martin Pool
Format plugin version as 1.2.3.2 not 1.2.3.final.2 |
482 |
self.assertEqual("1.2.3.2", plugin.__version__) |
|
4634.50.6
by John Arbash Meinel
Handle a plugin fallback versioning issue. |
483 |
|
|
2762.2.1
by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square |
484 |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
485 |
# GZ 2017-06-02: Move this suite to blackbox, as it's what it actually is.
|
486 |
class TestPluginHelp(BaseTestPlugins): |
|
|
1733.2.5
by Michael Ellerman
Show which plugin (if any) provides a command. |
487 |
|
488 |
def split_help_commands(self): |
|
489 |
help = {} |
|
490 |
current = None |
|
|
3908.1.1
by Andrew Bennetts
Try harder to avoid loading plugins during the test suite. |
491 |
out, err = self.run_bzr('--no-plugins help commands') |
492 |
for line in out.splitlines(): |
|
|
2034.1.2
by Aaron Bentley
Fix testcase |
493 |
if not line.startswith(' '): |
494 |
current = line.split()[0] |
|
|
1733.2.5
by Michael Ellerman
Show which plugin (if any) provides a command. |
495 |
help[current] = help.get(current, '') + line |
496 |
||
497 |
return help |
|
498 |
||
499 |
def test_plugin_help_builtins_unaffected(self): |
|
500 |
# Check we don't get false positives
|
|
501 |
help_commands = self.split_help_commands() |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
502 |
for cmd_name in breezy.commands.builtin_command_names(): |
503 |
if cmd_name in breezy.commands.plugin_command_names(): |
|
|
1733.2.5
by Michael Ellerman
Show which plugin (if any) provides a command. |
504 |
continue
|
505 |
try: |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
506 |
help = breezy.commands.get_cmd_object(cmd_name).get_help_text() |
|
1733.2.5
by Michael Ellerman
Show which plugin (if any) provides a command. |
507 |
except NotImplementedError: |
508 |
# some commands have no help
|
|
509 |
pass
|
|
510 |
else: |
|
|
2666.1.1
by Ian Clatworthy
Bazaar User Reference generated from online help |
511 |
self.assertNotContainsRe(help, 'plugin "[^"]*"') |
|
1733.2.5
by Michael Ellerman
Show which plugin (if any) provides a command. |
512 |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
513 |
if cmd_name in help_commands: |
|
1733.2.5
by Michael Ellerman
Show which plugin (if any) provides a command. |
514 |
# some commands are hidden
|
515 |
help = help_commands[cmd_name] |
|
|
2666.1.1
by Ian Clatworthy
Bazaar User Reference generated from online help |
516 |
self.assertNotContainsRe(help, 'plugin "[^"]*"') |
|
1733.2.5
by Michael Ellerman
Show which plugin (if any) provides a command. |
517 |
|
518 |
def test_plugin_help_shows_plugin(self): |
|
519 |
# Create a test plugin
|
|
520 |
os.mkdir('plugin_test') |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
521 |
source = ( |
522 |
"from breezy import commands\n" |
|
523 |
"class cmd_myplug(commands.Command):\n" |
|
524 |
" __doc__ = '''Just a simple test plugin.'''\n" |
|
525 |
" aliases = ['mplg']\n" |
|
526 |
" def run(self):\n" |
|
527 |
" print ('Hello from my plugin')\n" |
|
528 |
)
|
|
529 |
self.create_plugin('myplug', source, 'plugin_test') |
|
530 |
||
531 |
# Check its help
|
|
532 |
self.load_with_paths(['plugin_test']) |
|
533 |
myplug = self.plugins['myplug'].module |
|
534 |
breezy.commands.register_command(myplug.cmd_myplug) |
|
535 |
self.addCleanup(breezy.commands.plugin_cmds.remove, 'myplug') |
|
536 |
help = self.run_bzr('help myplug')[0] |
|
537 |
self.assertContainsRe(help, 'plugin "myplug"') |
|
538 |
help = self.split_help_commands()['myplug'] |
|
|
6798.1.1
by Jelmer Vernooij
Properly escape backslashes. |
539 |
self.assertContainsRe(help, '\\[myplug\\]') |
|
2215.4.1
by Alexander Belchenko
Bugfix #68124: Allow plugins import from zip archives. |
540 |
|
541 |
||
|
2432.1.25
by Robert Collins
Return plugin module docstrings for 'bzr help plugin'. |
542 |
class TestHelpIndex(tests.TestCase): |
543 |
"""Tests for the PluginsHelpIndex class.""" |
|
544 |
||
545 |
def test_default_constructable(self): |
|
546 |
index = plugin.PluginsHelpIndex() |
|
547 |
||
548 |
def test_get_topics_None(self): |
|
549 |
"""Searching for None returns an empty list.""" |
|
550 |
index = plugin.PluginsHelpIndex() |
|
551 |
self.assertEqual([], index.get_topics(None)) |
|
552 |
||
|
2475.1.1
by Martin Pool
Rename test_plugin tests and the example module used there. |
553 |
def test_get_topics_for_plugin(self): |
554 |
"""Searching for plugin name gets its docstring.""" |
|
|
2432.1.25
by Robert Collins
Return plugin module docstrings for 'bzr help plugin'. |
555 |
index = plugin.PluginsHelpIndex() |
|
2475.1.1
by Martin Pool
Rename test_plugin tests and the example module used there. |
556 |
# make a new plugin here for this test, even if we're run with
|
557 |
# --no-plugins
|
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
558 |
self.assertFalse('breezy.plugins.demo_module' in sys.modules) |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
559 |
demo_module = FakeModule('', 'breezy.plugins.demo_module') |
560 |
sys.modules['breezy.plugins.demo_module'] = demo_module |
|
|
2457.1.1
by Robert Collins
(robertc) Fix bzr --no-plugins selftest which was broken by the help indices patch. (Robert Collins, Martin Pool) |
561 |
try: |
|
2475.1.1
by Martin Pool
Rename test_plugin tests and the example module used there. |
562 |
topics = index.get_topics('demo_module') |
|
2457.1.1
by Robert Collins
(robertc) Fix bzr --no-plugins selftest which was broken by the help indices patch. (Robert Collins, Martin Pool) |
563 |
self.assertEqual(1, len(topics)) |
564 |
self.assertIsInstance(topics[0], plugin.ModuleHelpTopic) |
|
565 |
self.assertEqual(demo_module, topics[0].module) |
|
566 |
finally: |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
567 |
del sys.modules['breezy.plugins.demo_module'] |
|
2432.1.25
by Robert Collins
Return plugin module docstrings for 'bzr help plugin'. |
568 |
|
569 |
def test_get_topics_no_topic(self): |
|
570 |
"""Searching for something that is not a plugin returns [].""" |
|
571 |
# test this by using a name that cannot be a plugin - its not
|
|
572 |
# a valid python identifier.
|
|
573 |
index = plugin.PluginsHelpIndex() |
|
574 |
self.assertEqual([], index.get_topics('nothing by this name')) |
|
575 |
||
576 |
def test_prefix(self): |
|
577 |
"""PluginsHelpIndex has a prefix of 'plugins/'.""" |
|
578 |
index = plugin.PluginsHelpIndex() |
|
579 |
self.assertEqual('plugins/', index.prefix) |
|
580 |
||
|
2475.1.1
by Martin Pool
Rename test_plugin tests and the example module used there. |
581 |
def test_get_plugin_topic_with_prefix(self): |
582 |
"""Searching for plugins/demo_module returns help.""" |
|
|
2432.1.25
by Robert Collins
Return plugin module docstrings for 'bzr help plugin'. |
583 |
index = plugin.PluginsHelpIndex() |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
584 |
self.assertFalse('breezy.plugins.demo_module' in sys.modules) |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
585 |
demo_module = FakeModule('', 'breezy.plugins.demo_module') |
586 |
sys.modules['breezy.plugins.demo_module'] = demo_module |
|
|
2457.1.1
by Robert Collins
(robertc) Fix bzr --no-plugins selftest which was broken by the help indices patch. (Robert Collins, Martin Pool) |
587 |
try: |
|
2475.1.1
by Martin Pool
Rename test_plugin tests and the example module used there. |
588 |
topics = index.get_topics('plugins/demo_module') |
|
2457.1.1
by Robert Collins
(robertc) Fix bzr --no-plugins selftest which was broken by the help indices patch. (Robert Collins, Martin Pool) |
589 |
self.assertEqual(1, len(topics)) |
590 |
self.assertIsInstance(topics[0], plugin.ModuleHelpTopic) |
|
591 |
self.assertEqual(demo_module, topics[0].module) |
|
592 |
finally: |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
593 |
del sys.modules['breezy.plugins.demo_module'] |
|
2432.1.25
by Robert Collins
Return plugin module docstrings for 'bzr help plugin'. |
594 |
|
595 |
||
596 |
class FakeModule(object): |
|
597 |
"""A fake module to test with.""" |
|
598 |
||
599 |
def __init__(self, doc, name): |
|
600 |
self.__doc__ = doc |
|
601 |
self.__name__ = name |
|
602 |
||
603 |
||
604 |
class TestModuleHelpTopic(tests.TestCase): |
|
605 |
"""Tests for the ModuleHelpTopic class.""" |
|
606 |
||
607 |
def test_contruct(self): |
|
608 |
"""Construction takes the module to document.""" |
|
609 |
mod = FakeModule('foo', 'foo') |
|
610 |
topic = plugin.ModuleHelpTopic(mod) |
|
611 |
self.assertEqual(mod, topic.module) |
|
612 |
||
613 |
def test_get_help_text_None(self): |
|
614 |
"""A ModuleHelpTopic returns the docstring for get_help_text.""" |
|
615 |
mod = FakeModule(None, 'demo') |
|
616 |
topic = plugin.ModuleHelpTopic(mod) |
|
617 |
self.assertEqual("Plugin 'demo' has no docstring.\n", |
|
618 |
topic.get_help_text()) |
|
619 |
||
620 |
def test_get_help_text_no_carriage_return(self): |
|
621 |
"""ModuleHelpTopic.get_help_text adds a \n if needed.""" |
|
622 |
mod = FakeModule('one line of help', 'demo') |
|
623 |
topic = plugin.ModuleHelpTopic(mod) |
|
624 |
self.assertEqual("one line of help\n", |
|
625 |
topic.get_help_text()) |
|
626 |
||
627 |
def test_get_help_text_carriage_return(self): |
|
628 |
"""ModuleHelpTopic.get_help_text adds a \n if needed.""" |
|
629 |
mod = FakeModule('two lines of help\nand more\n', 'demo') |
|
630 |
topic = plugin.ModuleHelpTopic(mod) |
|
631 |
self.assertEqual("two lines of help\nand more\n", |
|
632 |
topic.get_help_text()) |
|
633 |
||
634 |
def test_get_help_text_with_additional_see_also(self): |
|
635 |
mod = FakeModule('two lines of help\nand more', 'demo') |
|
636 |
topic = plugin.ModuleHelpTopic(mod) |
|
|
6059.3.6
by Vincent Ladeuil
Fix tests failing on pqm. |
637 |
self.assertEqual("two lines of help\nand more\n\n:See also: bar, foo\n", |
638 |
topic.get_help_text(['foo', 'bar'])) |
|
|
2432.1.29
by Robert Collins
Add get_help_topic to ModuleHelpTopic. |
639 |
|
640 |
def test_get_help_topic(self): |
|
641 |
"""The help topic for a plugin is its module name.""" |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
642 |
mod = FakeModule('two lines of help\nand more', 'breezy.plugins.demo') |
|
2432.1.29
by Robert Collins
Add get_help_topic to ModuleHelpTopic. |
643 |
topic = plugin.ModuleHelpTopic(mod) |
644 |
self.assertEqual('demo', topic.get_help_topic()) |
|
|
6059.3.6
by Vincent Ladeuil
Fix tests failing on pqm. |
645 |
mod = FakeModule('two lines of help\nand more', |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
646 |
'breezy.plugins.foo_bar') |
|
2432.1.29
by Robert Collins
Add get_help_topic to ModuleHelpTopic. |
647 |
topic = plugin.ModuleHelpTopic(mod) |
648 |
self.assertEqual('foo_bar', topic.get_help_topic()) |
|
|
3835.2.7
by Aaron Bentley
Add tests for plugins |
649 |
|
650 |
||
|
5086.1.2
by Vincent Ladeuil
Cosmetic changes. |
651 |
class TestEnvPluginPath(tests.TestCase): |
|
4628.2.1
by Vincent Ladeuil
Start introducing accessors for plugin paths. |
652 |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
653 |
user = "USER" |
654 |
core = "CORE" |
|
655 |
site = "SITE" |
|
|
4628.2.2
by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH. |
656 |
|
657 |
def check_path(self, expected_dirs, setting_dirs): |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
658 |
if setting_dirs is None: |
659 |
del os.environ['BRZ_PLUGIN_PATH'] |
|
660 |
else: |
|
661 |
os.environ['BRZ_PLUGIN_PATH'] = os.pathsep.join(setting_dirs) |
|
662 |
actual = [(p if t == 'path' else t.upper()) |
|
663 |
for p, t in plugin._env_plugin_path()] |
|
664 |
self.assertEqual(expected_dirs, actual) |
|
|
4628.2.2
by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH. |
665 |
|
|
4628.2.1
by Vincent Ladeuil
Start introducing accessors for plugin paths. |
666 |
def test_default(self): |
|
4628.2.2
by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH. |
667 |
self.check_path([self.user, self.core, self.site], |
668 |
None) |
|
669 |
||
670 |
def test_adhoc_policy(self): |
|
671 |
self.check_path([self.user, self.core, self.site], |
|
672 |
['+user', '+core', '+site']) |
|
673 |
||
674 |
def test_fallback_policy(self): |
|
675 |
self.check_path([self.core, self.site, self.user], |
|
676 |
['+core', '+site', '+user']) |
|
677 |
||
678 |
def test_override_policy(self): |
|
679 |
self.check_path([self.user, self.site, self.core], |
|
680 |
['+user', '+site', '+core']) |
|
681 |
||
682 |
def test_disable_user(self): |
|
683 |
self.check_path([self.core, self.site], ['-user']) |
|
684 |
||
685 |
def test_disable_user_twice(self): |
|
686 |
# Ensures multiple removals don't left cruft
|
|
687 |
self.check_path([self.core, self.site], ['-user', '-user']) |
|
688 |
||
|
4628.2.5
by Vincent Ladeuil
Fixes prompted by review. |
689 |
def test_duplicates_are_removed(self): |
690 |
self.check_path([self.user, self.core, self.site], |
|
691 |
['+user', '+user']) |
|
692 |
# And only the first reference is kept (since the later references will
|
|
|
5086.1.2
by Vincent Ladeuil
Cosmetic changes. |
693 |
# only produce '<plugin> already loaded' mutters)
|
|
4628.2.5
by Vincent Ladeuil
Fixes prompted by review. |
694 |
self.check_path([self.user, self.core, self.site], |
695 |
['+user', '+user', '+core', |
|
696 |
'+user', '+site', '+site', |
|
697 |
'+core']) |
|
698 |
||
|
5086.1.5
by Vincent Ladeuil
Fix typo in test name. |
699 |
def test_disable_overrides_enable(self): |
|
4628.2.2
by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH. |
700 |
self.check_path([self.core, self.site], ['-user', '+user']) |
701 |
||
702 |
def test_disable_core(self): |
|
|
4628.2.3
by Vincent Ladeuil
Update doc and add NEWS entry. |
703 |
self.check_path([self.site], ['-core']) |
704 |
self.check_path([self.user, self.site], ['+user', '-core']) |
|
|
4628.2.2
by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH. |
705 |
|
706 |
def test_disable_site(self): |
|
|
4628.2.3
by Vincent Ladeuil
Update doc and add NEWS entry. |
707 |
self.check_path([self.core], ['-site']) |
708 |
self.check_path([self.user, self.core], ['-site', '+user']) |
|
|
4628.2.2
by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH. |
709 |
|
710 |
def test_override_site(self): |
|
|
4628.2.3
by Vincent Ladeuil
Update doc and add NEWS entry. |
711 |
self.check_path(['mysite', self.user, self.core], |
712 |
['mysite', '-site', '+user']) |
|
713 |
self.check_path(['mysite', self.core], |
|
|
4628.2.2
by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH. |
714 |
['mysite', '-site']) |
715 |
||
716 |
def test_override_core(self): |
|
|
4628.2.3
by Vincent Ladeuil
Update doc and add NEWS entry. |
717 |
self.check_path(['mycore', self.user, self.site], |
718 |
['mycore', '-core', '+user', '+site']) |
|
719 |
self.check_path(['mycore', self.site], |
|
|
4628.2.2
by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH. |
720 |
['mycore', '-core']) |
721 |
||
722 |
def test_my_plugin_only(self): |
|
723 |
self.check_path(['myplugin'], ['myplugin', '-user', '-core', '-site']) |
|
724 |
||
725 |
def test_my_plugin_first(self): |
|
726 |
self.check_path(['myplugin', self.core, self.site, self.user], |
|
727 |
['myplugin', '+core', '+site', '+user']) |
|
|
4628.2.1
by Vincent Ladeuil
Start introducing accessors for plugin paths. |
728 |
|
|
4628.2.5
by Vincent Ladeuil
Fixes prompted by review. |
729 |
def test_bogus_references(self): |
730 |
self.check_path(['+foo', '-bar', self.core, self.site], |
|
731 |
['+foo', '-bar']) |
|
|
5086.1.4
by Vincent Ladeuil
Slight plugin tests rewriting. |
732 |
|
|
5086.1.6
by Vincent Ladeuil
Crude fix for bug #411413. |
733 |
|
|
5616.7.10
by Martin Pool
Clean up describe_plugins to sort loaded and unloaded plugins together. |
734 |
class TestDisablePlugin(BaseTestPlugins): |
|
5086.1.6
by Vincent Ladeuil
Crude fix for bug #411413. |
735 |
|
|
5086.1.8
by Vincent Ladeuil
Fix warnings during autoload, add doc and a NEWS entry. |
736 |
def test_cannot_import(self): |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
737 |
self.create_plugin_package('works') |
738 |
self.create_plugin_package('fails') |
|
739 |
self.overrideEnv('BRZ_DISABLE_PLUGINS', 'fails') |
|
740 |
self.update_module_paths(["."]) |
|
741 |
import breezy.testingplugins.works as works |
|
|
5086.1.6
by Vincent Ladeuil
Crude fix for bug #411413. |
742 |
try: |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
743 |
import breezy.testingplugins.fails as fails |
|
5086.1.6
by Vincent Ladeuil
Crude fix for bug #411413. |
744 |
except ImportError: |
745 |
pass
|
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
746 |
else: |
747 |
self.fail("Loaded blocked plugin: " + repr(fails)) |
|
748 |
self.assertPluginModules({'fails': None, 'works': works}) |
|
749 |
||
750 |
def test_partial_imports(self): |
|
751 |
self.create_plugin('good') |
|
752 |
self.create_plugin('bad') |
|
753 |
self.create_plugin_package('ugly') |
|
754 |
self.overrideEnv('BRZ_DISABLE_PLUGINS', 'bad:ugly') |
|
755 |
self.load_with_paths(['.']) |
|
756 |
self.assertEqual({'good'}, viewkeys(self.plugins)) |
|
757 |
self.assertPluginModules({ |
|
758 |
'good': self.plugins['good'].module, |
|
759 |
'bad': None, |
|
760 |
'ugly': None, |
|
761 |
})
|
|
762 |
# Ensure there are no warnings about plugins not being imported as
|
|
763 |
# the user has explictly requested they be disabled.
|
|
764 |
self.assertNotContainsRe(self.get_log(), r"Unable to load plugin") |
|
765 |
||
766 |
||
767 |
class TestEnvDisablePlugins(tests.TestCase): |
|
768 |
||
769 |
def _get_names(self, env_value): |
|
770 |
os.environ['BRZ_DISABLE_PLUGINS'] = env_value |
|
771 |
return plugin._env_disable_plugins() |
|
772 |
||
773 |
def test_unset(self): |
|
774 |
self.assertEqual([], plugin._env_disable_plugins()) |
|
775 |
||
776 |
def test_empty(self): |
|
777 |
self.assertEqual([], self._get_names('')) |
|
778 |
||
779 |
def test_single(self): |
|
780 |
self.assertEqual(['single'], self._get_names('single')) |
|
781 |
||
782 |
def test_multi(self): |
|
783 |
expected = ['one', 'two'] |
|
784 |
self.assertEqual(expected, self._get_names(os.pathsep.join(expected))) |
|
785 |
||
786 |
def test_mixed(self): |
|
787 |
value = os.pathsep.join(['valid', 'in-valid']) |
|
788 |
self.assertEqual(['valid'], self._get_names(value)) |
|
789 |
self.assertContainsRe(self.get_log(), |
|
790 |
r"Invalid name 'in-valid' in BRZ_DISABLE_PLUGINS=" + repr(value)) |
|
791 |
||
792 |
||
793 |
class TestEnvPluginsAt(tests.TestCase): |
|
794 |
||
795 |
def _get_paths(self, env_value): |
|
796 |
os.environ['BRZ_PLUGINS_AT'] = env_value |
|
797 |
return plugin._env_plugins_at() |
|
798 |
||
799 |
def test_empty(self): |
|
800 |
self.assertEqual([], plugin._env_plugins_at()) |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
801 |
self.assertEqual([], self._get_paths('')) |
|
5268.5.1
by Vincent Ladeuil
Reproduce bug #591215. |
802 |
|
803 |
def test_one_path(self): |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
804 |
self.assertEqual([('b', 'man')], self._get_paths('b@man')) |
|
5268.5.1
by Vincent Ladeuil
Reproduce bug #591215. |
805 |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
806 |
def test_multiple(self): |
807 |
self.assertEqual( |
|
808 |
[('tools', 'bzr-tools'), ('p', 'play.py')], |
|
809 |
self._get_paths(os.pathsep.join(('tools@bzr-tools', 'p@play.py')))) |
|
810 |
||
811 |
def test_many_at(self): |
|
812 |
self.assertEqual( |
|
813 |
[('church', 'StMichael@Plea@Norwich')], |
|
814 |
self._get_paths('church@StMichael@Plea@Norwich')) |
|
815 |
||
816 |
def test_only_py(self): |
|
817 |
self.assertEqual([('test', './test.py')], self._get_paths('./test.py')) |
|
818 |
||
819 |
def test_only_package(self): |
|
820 |
self.assertEqual([('py', '/opt/b/py')], self._get_paths('/opt/b/py')) |
|
821 |
||
822 |
def test_bad_name(self): |
|
823 |
self.assertEqual([], self._get_paths('/usr/local/bzr-git')) |
|
824 |
self.assertContainsRe(self.get_log(), |
|
825 |
r"Invalid name 'bzr-git' in BRZ_PLUGINS_AT='/usr/local/bzr-git'") |
|
|
5268.5.1
by Vincent Ladeuil
Reproduce bug #591215. |
826 |
|
827 |
||
|
5616.7.10
by Martin Pool
Clean up describe_plugins to sort loaded and unloaded plugins together. |
828 |
class TestLoadPluginAt(BaseTestPlugins): |
|
5086.5.3
by Vincent Ladeuil
First shot at loading plugins from a specific directory. |
829 |
|
830 |
def setUp(self): |
|
831 |
super(TestLoadPluginAt, self).setUp() |
|
832 |
# Create the same plugin in two directories
|
|
|
5086.5.8
by Vincent Ladeuil
Make sure we can load from a non-standard directory name. |
833 |
self.create_plugin_package('test_foo', dir='non-standard-dir') |
|
5086.5.13
by Vincent Ladeuil
Reproduce bug #552922. |
834 |
# The "normal" directory, we use 'standard' instead of 'plugins' to
|
835 |
# avoid depending on the precise naming.
|
|
836 |
self.create_plugin_package('test_foo', dir='standard/test_foo') |
|
|
5086.5.8
by Vincent Ladeuil
Make sure we can load from a non-standard directory name. |
837 |
|
|
5086.5.14
by Vincent Ladeuil
Fix bug #552922 by controlling which files can be used to load a plugin. |
838 |
def assertTestFooLoadedFrom(self, path): |
|
5086.5.8
by Vincent Ladeuil
Make sure we can load from a non-standard directory name. |
839 |
self.assertPluginKnown('test_foo') |
|
5131.2.1
by Martin
Permit bzrlib to run under python -OO by explictly assigning to __doc__ for user-visible docstrings |
840 |
self.assertDocstring('This is the doc for test_foo', |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
841 |
self.module.test_foo) |
842 |
self.assertEqual(path, self.module.test_foo.dir_source) |
|
|
5086.5.3
by Vincent Ladeuil
First shot at loading plugins from a specific directory. |
843 |
|
844 |
def test_regular_load(self): |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
845 |
self.load_with_paths(['standard']) |
|
5086.5.13
by Vincent Ladeuil
Reproduce bug #552922. |
846 |
self.assertTestFooLoadedFrom('standard/test_foo') |
|
5086.5.3
by Vincent Ladeuil
First shot at loading plugins from a specific directory. |
847 |
|
848 |
def test_import(self): |
|
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
849 |
self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir') |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
850 |
self.update_module_paths(['standard']) |
851 |
import breezy.testingplugins.test_foo |
|
|
5086.5.8
by Vincent Ladeuil
Make sure we can load from a non-standard directory name. |
852 |
self.assertTestFooLoadedFrom('non-standard-dir') |
853 |
||
854 |
def test_loading(self): |
|
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
855 |
self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir') |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
856 |
self.load_with_paths(['standard']) |
857 |
self.assertTestFooLoadedFrom('non-standard-dir') |
|
858 |
||
859 |
def test_loading_other_name(self): |
|
860 |
self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir') |
|
861 |
os.rename('standard/test_foo', 'standard/test_bar') |
|
862 |
self.load_with_paths(['standard']) |
|
|
5086.5.9
by Vincent Ladeuil
More tests. |
863 |
self.assertTestFooLoadedFrom('non-standard-dir') |
864 |
||
865 |
def test_compiled_loaded(self): |
|
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
866 |
self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir') |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
867 |
self.load_with_paths(['standard']) |
|
5086.5.9
by Vincent Ladeuil
More tests. |
868 |
self.assertTestFooLoadedFrom('non-standard-dir') |
|
5235.1.1
by Martin
Make BZR_PLUGINS_AT tests that check filenames use a path-based assertion method rather than just string comparison |
869 |
self.assertIsSameRealPath('non-standard-dir/__init__.py', |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
870 |
self.module.test_foo.__file__) |
|
5086.5.9
by Vincent Ladeuil
More tests. |
871 |
|
872 |
# Try importing again now that the source has been compiled
|
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
873 |
os.remove('non-standard-dir/__init__.py') |
874 |
self.promote_cache('non-standard-dir') |
|
875 |
self.reset() |
|
876 |
self.load_with_paths(['standard']) |
|
|
5086.5.9
by Vincent Ladeuil
More tests. |
877 |
self.assertTestFooLoadedFrom('non-standard-dir') |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
878 |
suffix = plugin.COMPILED_EXT |
879 |
self.assertIsSameRealPath('non-standard-dir/__init__' + suffix, |
|
880 |
self.module.test_foo.__file__) |
|
|
5086.5.9
by Vincent Ladeuil
More tests. |
881 |
|
882 |
def test_submodule_loading(self): |
|
883 |
# We create an additional directory under the one for test_foo
|
|
884 |
self.create_plugin_package('test_bar', dir='non-standard-dir/test_bar') |
|
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
885 |
self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir') |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
886 |
self.update_module_paths(['standard']) |
887 |
import breezy.testingplugins.test_foo |
|
888 |
self.assertEqual(self.module_prefix + 'test_foo', |
|
889 |
self.module.test_foo.__package__) |
|
890 |
import breezy.testingplugins.test_foo.test_bar |
|
|
5235.1.1
by Martin
Make BZR_PLUGINS_AT tests that check filenames use a path-based assertion method rather than just string comparison |
891 |
self.assertIsSameRealPath('non-standard-dir/test_bar/__init__.py', |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
892 |
self.module.test_foo.test_bar.__file__) |
|
5086.5.13
by Vincent Ladeuil
Reproduce bug #552922. |
893 |
|
|
5268.6.2
by Vincent Ladeuil
Reproduce bug #588959. |
894 |
def test_relative_submodule_loading(self): |
895 |
self.create_plugin_package('test_foo', dir='another-dir', source=''' |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
896 |
from . import test_bar
|
|
5268.6.2
by Vincent Ladeuil
Reproduce bug #588959. |
897 |
''') |
898 |
# We create an additional directory under the one for test_foo
|
|
899 |
self.create_plugin_package('test_bar', dir='another-dir/test_bar') |
|
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
900 |
self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@another-dir') |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
901 |
self.update_module_paths(['standard']) |
902 |
import breezy.testingplugins.test_foo |
|
903 |
self.assertEqual(self.module_prefix + 'test_foo', |
|
904 |
self.module.test_foo.__package__) |
|
|
5268.6.2
by Vincent Ladeuil
Reproduce bug #588959. |
905 |
self.assertIsSameRealPath('another-dir/test_bar/__init__.py', |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
906 |
self.module.test_foo.test_bar.__file__) |
|
5268.6.2
by Vincent Ladeuil
Reproduce bug #588959. |
907 |
|
|
5086.5.15
by Vincent Ladeuil
Fixed as per Ian's review. |
908 |
def test_loading_from___init__only(self): |
|
5086.5.13
by Vincent Ladeuil
Reproduce bug #552922. |
909 |
# We rename the existing __init__.py file to ensure that we don't load
|
910 |
# a random file
|
|
911 |
init = 'non-standard-dir/__init__.py' |
|
912 |
random = 'non-standard-dir/setup.py' |
|
913 |
os.rename(init, random) |
|
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
914 |
self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir') |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
915 |
self.load_with_paths(['standard']) |
|
5086.5.13
by Vincent Ladeuil
Reproduce bug #552922. |
916 |
self.assertPluginUnknown('test_foo') |
|
5086.5.14
by Vincent Ladeuil
Fix bug #552922 by controlling which files can be used to load a plugin. |
917 |
|
918 |
def test_loading_from_specific_file(self): |
|
919 |
plugin_dir = 'non-standard-dir' |
|
920 |
plugin_file_name = 'iamtestfoo.py' |
|
921 |
plugin_path = osutils.pathjoin(plugin_dir, plugin_file_name) |
|
922 |
source = '''\ |
|
923 |
"""This is the doc for %s""" |
|
924 |
dir_source = '%s' |
|
925 |
''' % ('test_foo', plugin_path) |
|
926 |
self.create_plugin('test_foo', source=source, |
|
927 |
dir=plugin_dir, file_name=plugin_file_name) |
|
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
928 |
self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@%s' % plugin_path) |
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
929 |
self.load_with_paths(['standard']) |
|
5086.5.14
by Vincent Ladeuil
Fix bug #552922 by controlling which files can be used to load a plugin. |
930 |
self.assertTestFooLoadedFrom(plugin_path) |
|
5616.7.10
by Martin Pool
Clean up describe_plugins to sort loaded and unloaded plugins together. |
931 |
|
932 |
||
933 |
class TestDescribePlugins(BaseTestPlugins): |
|
934 |
||
935 |
def test_describe_plugins(self): |
|
|
5616.7.11
by Martin Pool
Additional tests and fixes for refactored describe_plugins. |
936 |
class DummyModule(object): |
937 |
__doc__ = 'Hi there' |
|
938 |
class DummyPlugin(object): |
|
939 |
__version__ = '0.1.0' |
|
940 |
module = DummyModule() |
|
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
941 |
self.plugin_warnings = {'bad': ['Failed to load (just testing)']} |
942 |
self.plugins = {'good': DummyPlugin()} |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
943 |
self.assertEqual("""\ |
|
5616.7.10
by Martin Pool
Clean up describe_plugins to sort loaded and unloaded plugins together. |
944 |
bad (failed to load)
|
945 |
** Failed to load (just testing)
|
|
946 |
||
|
5616.7.11
by Martin Pool
Additional tests and fixes for refactored describe_plugins. |
947 |
good 0.1.0
|
948 |
Hi there
|
|
949 |
||
|
6651.4.1
by Martin
Rewrite of the plugin module for Python 3 compat and general sanity |
950 |
""", ''.join(plugin.describe_plugins(state=self))) |