69
69
# tempattribute list.
70
70
template = ("from bzrlib.tests.test_plugins import TestLoadingPlugins\n"
71
71
"TestLoadingPlugins.activeattributes[%r].append('%s')\n")
72
print >> file(os.path.join('first', 'plugin.py'), 'w'), template % (tempattribute, 'first')
73
print >> file(os.path.join('second', 'plugin.py'), 'w'), template % (tempattribute, 'second')
73
outfile = open(os.path.join('first', 'plugin.py'), 'w')
75
print >> outfile, template % (tempattribute, 'first')
79
outfile = open(os.path.join('second', 'plugin.py'), 'w')
81
print >> outfile, template % (tempattribute, 'second')
75
86
bzrlib.plugin.load_from_path(['first', 'second'])
76
87
self.assertEqual(['first'], self.activeattributes[tempattribute])
102
113
# tempattribute list.
103
114
template = ("from bzrlib.tests.test_plugins import TestLoadingPlugins\n"
104
115
"TestLoadingPlugins.activeattributes[%r].append('%s')\n")
105
print >> file(os.path.join('first', 'pluginone.py'), 'w'), template % (tempattribute, 'first')
106
print >> file(os.path.join('second', 'plugintwo.py'), 'w'), template % (tempattribute, 'second')
117
outfile = open(os.path.join('first', 'pluginone.py'), 'w')
119
print >> outfile, template % (tempattribute, 'first')
123
outfile = open(os.path.join('second', 'plugintwo.py'), 'w')
125
print >> outfile, template % (tempattribute, 'second')
107
129
oldpath = bzrlib.plugins.__path__
109
131
bzrlib.plugins.__path__ = ['first', 'second']
119
141
del bzrlib.plugins.plugin
120
142
self.failIf(getattr(bzrlib.plugins, 'plugin', None))
144
def test_plugins_can_load_from_directory_with_trailing_slash(self):
145
# This test tests that a plugin can load from a directory when the
146
# directory in the path has a trailing slash.
147
# check the plugin is not loaded already
148
self.failIf(getattr(bzrlib.plugins, 'ts_plugin', None))
149
tempattribute = "trailing-slash"
150
self.failIf(tempattribute in self.activeattributes)
151
# set a place for the plugin to record its loading, and at the same
152
# time validate that the location the plugin should record to is
154
bzrlib.tests.test_plugins.TestLoadingPlugins.activeattributes \
156
self.failUnless(tempattribute in self.activeattributes)
157
# create a directory for the plugin
158
os.mkdir('plugin_test')
159
# write a plugin that will record when its loaded in the
160
# tempattribute list.
161
template = ("from bzrlib.tests.test_plugins import TestLoadingPlugins\n"
162
"TestLoadingPlugins.activeattributes[%r].append('%s')\n")
164
outfile = open(os.path.join('plugin_test', 'ts_plugin.py'), 'w')
166
print >> outfile, template % (tempattribute, 'plugin')
171
bzrlib.plugin.load_from_path(['plugin_test'+os.sep])
172
self.assertEqual(['plugin'], self.activeattributes[tempattribute])
174
# remove the plugin 'plugin'
175
del self.activeattributes[tempattribute]
176
if getattr(bzrlib.plugins, 'ts_plugin', None):
177
del bzrlib.plugins.ts_plugin
178
self.failIf(getattr(bzrlib.plugins, 'ts_plugin', None))
123
181
class TestAllPlugins(TestCaseInTempDir):
244
302
bzrlib.plugins.__path__ = old_path
304
def test_set_plugins_path_with_trailing_slashes(self):
305
"""set_plugins_path should set the module __path__ based on
307
old_path = bzrlib.plugins.__path__
308
old_env = os.environ.get('BZR_PLUGIN_PATH')
310
bzrlib.plugins.__path__ = []
311
os.environ['BZR_PLUGIN_PATH'] = "first\\//\\" + os.pathsep + \
313
bzrlib.plugin.set_plugins_path()
314
expected_path = ['first', 'second',
315
os.path.dirname(bzrlib.plugins.__file__)]
316
self.assertEqual(expected_path, bzrlib.plugins.__path__)
318
bzrlib.plugins.__path__ = old_path
320
os.environ['BZR_PLUGIN_PATH'] = old_env
322
del os.environ['BZR_PLUGIN_PATH']
247
324
class TestHelpIndex(tests.TestCase):
248
325
"""Tests for the PluginsHelpIndex class."""