Rev 5087: (vila) Cleanup test_plugins in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Mar 12 14:34:08 GMT 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5087 [merge]
revision-id: pqm at pqm.ubuntu.com-20100312143405-ln4h5ph0hut5iicf
parent: pqm at pqm.ubuntu.com-20100311232034-x3miloj34rko1mqs
parent: v.ladeuil+lp at free.fr-20100312135602-6vi6zrvy219qzmbc
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2010-03-12 14:34:05 +0000
message:
  (vila) Cleanup test_plugins
modified:
  bzrlib/plugin.py               plugin.py-20050622060424-829b654519533d69
  bzrlib/tests/test_plugins.py   plugins.py-20050622075746-32002b55e5e943e9
=== modified file 'bzrlib/plugin.py'
--- a/bzrlib/plugin.py	2010-02-10 02:03:20 +0000
+++ b/bzrlib/plugin.py	2010-03-12 13:41:08 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2004, 2005, 2007, 2008, 2010 Canonical Ltd
+# Copyright (C) 2005-2010 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -67,15 +67,6 @@
     return _plugins_disabled
 
 
- at deprecated_function(deprecated_in((2, 0, 0)))
-def get_default_plugin_path():
-    """Get the DEFAULT_PLUGIN_PATH"""
-    global DEFAULT_PLUGIN_PATH
-    if DEFAULT_PLUGIN_PATH is None:
-        DEFAULT_PLUGIN_PATH = osutils.pathjoin(config.config_dir(), 'plugins')
-    return DEFAULT_PLUGIN_PATH
-
-
 def disable_plugins():
     """Disable loading plugins.
 
@@ -188,7 +179,7 @@
     paths = []
     for p in env_paths + defaults:
         if p.startswith('+'):
-            # Resolve reference if they are known
+            # Resolve references if they are known
             try:
                 p = refs[p[1:]]
             except KeyError:

=== modified file 'bzrlib/tests/test_plugins.py'
--- a/bzrlib/tests/test_plugins.py	2010-01-25 17:48:22 +0000
+++ b/bzrlib/tests/test_plugins.py	2010-03-12 13:54:25 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2007 Canonical Ltd
+# Copyright (C) 2005-2010 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -20,41 +20,22 @@
 # affects the global state of the process.  See bzrlib/plugins.py for more
 # comments.
 
+from cStringIO import StringIO
 import logging
 import os
-from StringIO import StringIO
 import sys
-import zipfile
 
+import bzrlib
 from bzrlib import (
     osutils,
     plugin,
     tests,
     )
-import bzrlib.plugin
-import bzrlib.plugins
-import bzrlib.commands
-import bzrlib.help
-from bzrlib.tests import (
-    TestCase,
-    TestCaseInTempDir,
-    TestUtil,
-    )
-from bzrlib.osutils import pathjoin, abspath, normpath
-
-
-PLUGIN_TEXT = """\
-import bzrlib.commands
-class cmd_myplug(bzrlib.commands.Command):
-    '''Just a simple test plugin.'''
-    aliases = ['mplg']
-    def run(self):
-        print 'Hello from my plugin'
-"""
+
 
 # TODO: Write a test for plugin decoration of commands.
 
-class TestLoadingPlugins(TestCaseInTempDir):
+class TestLoadingPlugins(tests.TestCaseInTempDir):
 
     activeattributes = {}
 
@@ -251,7 +232,7 @@
             "it to 'bad_plugin_name_'\.")
 
 
-class TestPlugins(TestCaseInTempDir):
+class TestPlugins(tests.TestCaseInTempDir):
 
     def setup_plugin(self, source=""):
         # This test tests a new plugin appears in bzrlib.plugin.plugins().
@@ -284,29 +265,31 @@
         plugins = bzrlib.plugin.plugins()
         plugin = plugins['plugin']
         plugin_path = self.test_dir + '/plugin.py'
-        self.assertIsSameRealPath(plugin_path, normpath(plugin.path()))
+        self.assertIsSameRealPath(plugin_path, osutils.normpath(plugin.path()))
 
     def test_plugin_get_path_py_not_pyc(self):
-        self.setup_plugin()         # after first import there will be plugin.pyc
+        # first import creates plugin.pyc
+        self.setup_plugin()
         self.teardown_plugin()
         bzrlib.plugin.load_from_path(['.']) # import plugin.pyc
         plugins = bzrlib.plugin.plugins()
         plugin = plugins['plugin']
         plugin_path = self.test_dir + '/plugin.py'
-        self.assertIsSameRealPath(plugin_path, normpath(plugin.path()))
+        self.assertIsSameRealPath(plugin_path, osutils.normpath(plugin.path()))
 
     def test_plugin_get_path_pyc_only(self):
-        self.setup_plugin()         # after first import there will be plugin.pyc
+        # first import creates plugin.pyc (or plugin.pyo depending on __debug__)
+        self.setup_plugin()
         self.teardown_plugin()
         os.unlink(self.test_dir + '/plugin.py')
-        bzrlib.plugin.load_from_path(['.']) # import plugin.pyc
+        bzrlib.plugin.load_from_path(['.']) # import plugin.pyc (or .pyo)
         plugins = bzrlib.plugin.plugins()
         plugin = plugins['plugin']
         if __debug__:
             plugin_path = self.test_dir + '/plugin.pyc'
         else:
             plugin_path = self.test_dir + '/plugin.pyo'
-        self.assertIsSameRealPath(plugin_path, normpath(plugin.path()))
+        self.assertIsSameRealPath(plugin_path, osutils.normpath(plugin.path()))
 
     def test_no_test_suite_gives_None_for_test_suite(self):
         self.setup_plugin()
@@ -321,7 +304,7 @@
 
     def test_no_load_plugin_tests_gives_None_for_load_plugin_tests(self):
         self.setup_plugin()
-        loader = TestUtil.TestLoader()
+        loader = tests.TestUtil.TestLoader()
         plugin = bzrlib.plugin.plugins()['plugin']
         self.assertEqual(None, plugin.load_plugin_tests(loader))
 
@@ -330,7 +313,7 @@
 def load_tests(standard_tests, module, loader):
     return 'foo'"""
         self.setup_plugin(source)
-        loader = TestUtil.TestLoader()
+        loader = tests.TestUtil.TestLoader()
         plugin = bzrlib.plugin.plugins()['plugin']
         self.assertEqual('foo', plugin.load_plugin_tests(loader))
 
@@ -407,7 +390,7 @@
         self.assertEqual("1.2.3.final.2", plugin.__version__)
 
 
-class TestPluginHelp(TestCaseInTempDir):
+class TestPluginHelp(tests.TestCaseInTempDir):
 
     def split_help_commands(self):
         help = {}
@@ -442,8 +425,17 @@
     def test_plugin_help_shows_plugin(self):
         # Create a test plugin
         os.mkdir('plugin_test')
-        f = open(pathjoin('plugin_test', 'myplug.py'), 'w')
-        f.write(PLUGIN_TEXT)
+        f = open(osutils.pathjoin('plugin_test', 'myplug.py'), 'w')
+        f.write("""\
+from bzrlib import commands
+class cmd_myplug(commands.Command):
+    '''Just a simple test plugin.'''
+    aliases = ['mplg']
+    def run(self):
+        print 'Hello from my plugin'
+
+"""
+)
         f.close()
 
         try:
@@ -627,7 +619,7 @@
         self.assertEqual(path, bzrlib.plugins.__path__)
 
 
-class TestEnvPluginPath(tests.TestCaseInTempDir):
+class TestEnvPluginPath(tests.TestCase):
 
     def setUp(self):
         super(TestEnvPluginPath, self).setUp()
@@ -680,7 +672,7 @@
         self.check_path([self.user, self.core, self.site],
                         ['+user', '+user'])
         # And only the first reference is kept (since the later references will
-        # onnly produce <plugin> already loaded mutters)
+        # only produce '<plugin> already loaded' mutters)
         self.check_path([self.user, self.core, self.site],
                         ['+user', '+user', '+core',
                          '+user', '+site', '+site',




More information about the bazaar-commits mailing list