18
18
"""Tests for plugins"""
22
# **************************************************
24
# **************************************************
33
from bzrlib.selftest import TestCaseInTempDir
20
# XXX: There are no plugin tests at the moment because the plugin module
21
# affects the global state of the process. See bzrlib/plugins.py for more
26
from bzrlib.tests import TestCaseInTempDir
27
from bzrlib.osutils import pathjoin, abspath
36
29
class PluginTest(TestCaseInTempDir):
37
30
"""Create an external plugin and test loading."""
38
def test_plugin_loading(self):
41
orig_help = self.backtick('bzr help commands') # No plugins yet
42
os.mkdir('plugin_test')
43
f = open(os.path.join('plugin_test', 'myplug.py'), 'wt')
47
newhelp = backtick('bzr help commands')
48
assert newhelp.startswith('You have been overridden\n')
49
# We added a line, but the rest should work
50
assert newhelp[25:] == help
52
assert backtick('bzr commit -m test') == "I'm sorry dave, you can't do that\n"
54
shutil.rmtree('plugin_test')
60
# """import bzrlib, bzrlib.commands
61
# class cmd_myplug(bzrlib.commands.Command):
62
# '''Just a simple test plugin.'''
65
# print 'Hello from my plugin'
69
# os.environ['BZRPLUGINPATH'] = os.path.abspath('plugin_test')
31
# def test_plugin_loading(self):
32
# orig_help = self.run_bzr_captured('bzr help commands')[0]
33
# os.mkdir('plugin_test')
34
# f = open(pathjoin('plugin_test', 'myplug.py'), 'wt')
35
# f.write(PLUGIN_TEXT)
37
# newhelp = self.run_bzr_captured('bzr help commands')[0]
38
# assert newhelp.startswith('You have been overridden\n')
39
# # We added a line, but the rest should work
40
# assert newhelp[25:] == help
42
# assert backtick('bzr commit -m test') == "I'm sorry dave, you can't do that\n"
44
# shutil.rmtree('plugin_test')
47
# os.environ['BZRPLUGINPATH'] = abspath('plugin_test')
70
48
# help = backtick('bzr help commands')
71
49
# assert help.find('myplug') != -1
72
50
# assert help.find('Just a simple test plugin.') != -1
75
53
# assert backtick('bzr myplug') == 'Hello from my plugin\n'
76
54
# assert backtick('bzr mplg') == 'Hello from my plugin\n'
78
# f = open(os.path.join('plugin_test', 'override.py'), 'wb')
56
# f = open(pathjoin('plugin_test', 'override.py'), 'wb')
79
57
# f.write("""import bzrlib, bzrlib.commands
80
58
# class cmd_commit(bzrlib.commands.cmd_commit):
81
59
# '''Commit changes into a new revision.'''
89
67
# bzrlib.commands.cmd_help.run(self, *args, **kwargs)
72
import bzrlib.commands
73
class cmd_myplug(bzrlib.commands.Command):
74
'''Just a simple test plugin.'''
77
print 'Hello from my plugin'
80
# TODO: Write a test for plugin decoration of commands.