/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-05-24 00:39:50 UTC
  • mto: This revision was merged to the branch mainline in revision 7504.
  • Revision ID: jelmer@jelmer.uk-20200524003950-bbc545r76vc5yajg
Add github action.

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