/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 00:32:38 UTC
  • mfrom: (7490.40.77 work)
  • mto: (7490.40.79 work)
  • mto: This revision was merged to the branch mainline in revision 7521.
  • Revision ID: jelmer@jelmer.uk-20200728003238-vx5u412hn72f18lr
Merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

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