~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_plugins.py

  • Committer: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
# TODO: Write a test for plugin decoration of commands.
40
40
 
41
 
class TestPluginMixin(object):
 
41
class BaseTestPlugins(tests.TestCaseInTempDir):
42
42
 
43
43
    def create_plugin(self, name, source=None, dir='.', file_name=None):
44
44
        if source is None:
99
99
        self.assertTrue('bzrlib.plugins.%s' % name in sys.modules)
100
100
 
101
101
 
102
 
class TestLoadingPlugins(tests.TestCaseInTempDir, TestPluginMixin):
 
102
class TestLoadingPlugins(BaseTestPlugins):
103
103
 
104
104
    activeattributes = {}
105
105
 
267
267
            stream.close()
268
268
 
269
269
    def test_plugin_with_bad_api_version_reports(self):
270
 
        # This plugin asks for bzrlib api version 1.0.0, which is not supported
271
 
        # anymore.
 
270
        """Try loading a plugin that requests an unsupported api.
 
271
        
 
272
        Observe that it records the problem but doesn't complain on stderr.
 
273
 
 
274
        See https://bugs.launchpad.net/bzr/+bug/704195
 
275
        """
 
276
        self.overrideAttr(plugin, 'plugin_warnings', {})
272
277
        name = 'wants100.py'
273
278
        f = file(name, 'w')
274
279
        try:
276
281
                "bzrlib.api.require_any_api(bzrlib, [(1, 0, 0)])\n")
277
282
        finally:
278
283
            f.close()
279
 
 
280
284
        log = self.load_and_capture(name)
281
 
        self.assertContainsRe(log,
 
285
        self.assertNotContainsRe(log,
 
286
            r"It requested API version")
 
287
        self.assertEquals(
 
288
            ['wants100'],
 
289
            plugin.plugin_warnings.keys())
 
290
        self.assertContainsRe(
 
291
            plugin.plugin_warnings['wants100'][0],
282
292
            r"It requested API version")
283
293
 
284
294
    def test_plugin_with_bad_name_does_not_load(self):
292
302
            "it to 'bad_plugin_name_'\.")
293
303
 
294
304
 
295
 
class TestPlugins(tests.TestCaseInTempDir, TestPluginMixin):
 
305
class TestPlugins(BaseTestPlugins):
296
306
 
297
307
    def setup_plugin(self, source=""):
298
308
        # This test tests a new plugin appears in bzrlib.plugin.plugins().
442
452
    def test_final_fallback__version__with_version_info(self):
443
453
        self.setup_plugin("version_info = (1, 2, 3, 'final', 2)")
444
454
        plugin = bzrlib.plugin.plugins()['plugin']
445
 
        self.assertEqual("1.2.3.final.2", plugin.__version__)
 
455
        self.assertEqual("1.2.3.2", plugin.__version__)
446
456
 
447
457
 
448
458
class TestPluginHelp(tests.TestCaseInTempDir):
768
778
                        ['+foo', '-bar'])
769
779
 
770
780
 
771
 
class TestDisablePlugin(tests.TestCaseInTempDir, TestPluginMixin):
 
781
class TestDisablePlugin(BaseTestPlugins):
772
782
 
773
783
    def setUp(self):
774
784
        super(TestDisablePlugin, self).setUp()
809
819
        self.assertLength(0, self.warnings)
810
820
 
811
821
 
 
822
 
812
823
class TestLoadPluginAtSyntax(tests.TestCase):
813
824
 
814
825
    def _get_paths(self, paths):
832
843
                          os.pathsep.join(['batman@cave', '', 'robin@mobile']))
833
844
 
834
845
 
835
 
class TestLoadPluginAt(tests.TestCaseInTempDir, TestPluginMixin):
 
846
class TestLoadPluginAt(BaseTestPlugins):
836
847
 
837
848
    def setUp(self):
838
849
        super(TestLoadPluginAt, self).setUp()
847
858
        self.create_plugin_package('test_foo', dir='standard/test_foo')
848
859
        # All the tests will load the 'test_foo' plugin from various locations
849
860
        self.addCleanup(self._unregister_plugin, 'test_foo')
 
861
        # Unfortunately there's global cached state for the specific
 
862
        # registered paths.
 
863
        self.addCleanup(plugin.PluginImporter.reset)
850
864
 
851
865
    def assertTestFooLoadedFrom(self, path):
852
866
        self.assertPluginKnown('test_foo')
945
959
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@%s' % plugin_path)
946
960
        plugin.load_plugins(['standard'])
947
961
        self.assertTestFooLoadedFrom(plugin_path)
 
962
 
 
963
 
 
964
class TestDescribePlugins(BaseTestPlugins):
 
965
 
 
966
    def test_describe_plugins(self):
 
967
        class DummyModule(object):
 
968
            __doc__ = 'Hi there'
 
969
        class DummyPlugin(object):
 
970
            __version__ = '0.1.0'
 
971
            module = DummyModule()
 
972
        def dummy_plugins():
 
973
            return { 'good': DummyPlugin() }
 
974
        self.overrideAttr(plugin, 'plugin_warnings',
 
975
            {'bad': ['Failed to load (just testing)']})
 
976
        self.overrideAttr(plugin, 'plugins', dummy_plugins)
 
977
        self.assertEquals("""\
 
978
bad (failed to load)
 
979
  ** Failed to load (just testing)
 
980
 
 
981
good 0.1.0
 
982
  Hi there
 
983
 
 
984
""", ''.join(plugin.describe_plugins()))