~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_plugins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-08-28 05:09:22 UTC
  • mfrom: (2753.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070828050922-e7ovfulum5c7sd5o
(Blake Winton) BZR_PLUGIN_PATH should ignore trailiing slashes

Show diffs side-by-side

added added

removed removed

Lines of Context:
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')
 
72
 
 
73
        outfile = open(os.path.join('first', 'plugin.py'), 'w')
 
74
        try:
 
75
            print >> outfile, template % (tempattribute, 'first')
 
76
        finally:
 
77
            outfile.close()
 
78
 
 
79
        outfile = open(os.path.join('second', 'plugin.py'), 'w')
 
80
        try:
 
81
            print >> outfile, template % (tempattribute, 'second')
 
82
        finally:
 
83
            outfile.close()
 
84
 
74
85
        try:
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')
 
116
 
 
117
        outfile = open(os.path.join('first', 'pluginone.py'), 'w')
 
118
        try:
 
119
            print >> outfile, template % (tempattribute, 'first')
 
120
        finally:
 
121
            outfile.close()
 
122
 
 
123
        outfile = open(os.path.join('second', 'plugintwo.py'), 'w')
 
124
        try:
 
125
            print >> outfile, template % (tempattribute, 'second')
 
126
        finally:
 
127
            outfile.close()
 
128
 
107
129
        oldpath = bzrlib.plugins.__path__
108
130
        try:
109
131
            bzrlib.plugins.__path__ = ['first', 'second']
119
141
                del bzrlib.plugins.plugin
120
142
        self.failIf(getattr(bzrlib.plugins, 'plugin', None))
121
143
 
 
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
 
153
        # valid and correct.
 
154
        bzrlib.tests.test_plugins.TestLoadingPlugins.activeattributes \
 
155
            [tempattribute] = []
 
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")
 
163
 
 
164
        outfile = open(os.path.join('plugin_test', 'ts_plugin.py'), 'w')
 
165
        try:
 
166
            print >> outfile, template % (tempattribute, 'plugin')
 
167
        finally:
 
168
            outfile.close()
 
169
 
 
170
        try:
 
171
            bzrlib.plugin.load_from_path(['plugin_test'+os.sep])
 
172
            self.assertEqual(['plugin'], self.activeattributes[tempattribute])
 
173
        finally:
 
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))
 
179
 
122
180
 
123
181
class TestAllPlugins(TestCaseInTempDir):
124
182
 
243
301
        finally:
244
302
            bzrlib.plugins.__path__ = old_path
245
303
 
 
304
    def test_set_plugins_path_with_trailing_slashes(self):
 
305
        """set_plugins_path should set the module __path__ based on
 
306
        BZR_PLUGIN_PATH."""
 
307
        old_path = bzrlib.plugins.__path__
 
308
        old_env = os.environ.get('BZR_PLUGIN_PATH')
 
309
        try:
 
310
            bzrlib.plugins.__path__ = []
 
311
            os.environ['BZR_PLUGIN_PATH'] = "first\\//\\" + os.pathsep + \
 
312
                "second/\\/\\/"
 
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__)
 
317
        finally:
 
318
            bzrlib.plugins.__path__ = old_path
 
319
            if old_env != None:
 
320
                os.environ['BZR_PLUGIN_PATH'] = old_env
 
321
            else:
 
322
                del os.environ['BZR_PLUGIN_PATH']
246
323
 
247
324
class TestHelpIndex(tests.TestCase):
248
325
    """Tests for the PluginsHelpIndex class."""