/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_plugins.py

  • Committer: Jelmer Vernooij
  • Date: 2020-07-28 02:11:05 UTC
  • mfrom: (7490.40.78 work)
  • mto: This revision was merged to the branch mainline in revision 7520.
  • Revision ID: jelmer@jelmer.uk-20200728021105-fzq7g6f8bl1g0aet
Merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
        self.log("using %r", paths)
77
77
        return paths
78
78
 
79
 
    def load_with_paths(self, paths):
 
79
    def load_with_paths(self, paths, warn_load_problems=True):
80
80
        self.log("loading plugins!")
81
 
        plugin.load_plugins(self.update_module_paths(paths), state=self)
 
81
        plugin.load_plugins(
 
82
            self.update_module_paths(paths), state=self,
 
83
            warn_load_problems=warn_load_problems)
82
84
 
83
85
    def create_plugin(self, name, source=None, dir='.', file_name=None):
84
86
        if source is None:
260
262
        finally:
261
263
            del self.activeattributes[tempattribute]
262
264
 
263
 
    def load_and_capture(self, name):
 
265
    def load_and_capture(self, name, warn_load_problems=True):
264
266
        """Load plugins from '.' capturing the output.
265
267
 
266
268
        :param name: The name of the plugin.
273
275
            log = logging.getLogger('brz')
274
276
            log.addHandler(handler)
275
277
            try:
276
 
                self.load_with_paths(['.'])
 
278
                self.load_with_paths(
 
279
                    ['.'], warn_load_problems=warn_load_problems)
277
280
            finally:
278
281
                # Stop capturing output
279
282
                handler.flush()
286
289
    def test_plugin_with_bad_api_version_reports(self):
287
290
        """Try loading a plugin that requests an unsupported api.
288
291
 
289
 
        Observe that it records the problem but doesn't complain on stderr.
290
 
 
291
 
        See https://bugs.launchpad.net/bzr/+bug/704195
 
292
        Observe that it records the problem but doesn't complain on stderr
 
293
        when warn_load_problems=False
292
294
        """
293
295
        name = 'wants100.py'
294
296
        with open(name, 'w') as f:
295
297
            f.write("import breezy\n"
296
298
                    "from breezy.errors import IncompatibleVersion\n"
297
299
                    "raise IncompatibleVersion(breezy, [(1, 0, 0)], (0, 0, 5))\n")
298
 
        log = self.load_and_capture(name)
299
 
        self.assertNotContainsRe(log,
300
 
                                 r"It supports breezy version")
 
300
        log = self.load_and_capture(name, warn_load_problems=False)
 
301
        self.assertNotContainsRe(log, r"It supports breezy version")
301
302
        self.assertEqual({'wants100'}, self.plugin_warnings.keys())
302
303
        self.assertContainsRe(
303
304
            self.plugin_warnings['wants100'][0],
313
314
                              "because the file path isn't a valid module name; try renaming "
314
315
                              "it to 'bad_plugin_name_'\\.")
315
316
 
 
317
    def test_plugin_with_error_suppress(self):
 
318
        # The file name here invalid for a python module.
 
319
        name = 'some_error.py'
 
320
        with open(name, 'w') as f:
 
321
            f.write('raise Exception("bad")\n')
 
322
        log = self.load_and_capture(name, warn_load_problems=False)
 
323
        self.assertEqual('', log)
 
324
 
 
325
    def test_plugin_with_error(self):
 
326
        # The file name here invalid for a python module.
 
327
        name = 'some_error.py'
 
328
        with open(name, 'w') as f:
 
329
            f.write('raise Exception("bad")\n')
 
330
        log = self.load_and_capture(name, warn_load_problems=True)
 
331
        self.assertEqual(
 
332
            'Unable to load plugin \'some_error\' from \'.\': bad\n', log)
 
333
 
316
334
 
317
335
class TestPlugins(BaseTestPlugins):
318
336