69
# Workaround lazy import random? madness
71
self.addCleanup(cleanup)
111
72
self.create_plugin(name, source, dir,
112
73
file_name='__init__.py')
114
def promote_cache(self, directory):
115
"""Move bytecode files out of __pycache__ in given directory."""
116
cache_dir = os.path.join(directory, '__pycache__')
117
if os.path.isdir(cache_dir):
118
for name in os.listdir(cache_dir):
119
magicless_name = '.'.join(name.split('.')[0::name.count('.')])
120
rel = osutils.relpath(self.test_dir, cache_dir)
121
self.log("moving %s in %s to %s", name, rel, magicless_name)
122
os.rename(os.path.join(cache_dir, name),
123
os.path.join(directory, magicless_name))
125
def _unregister_finder(self):
126
"""Removes any test copies of _PluginsAtFinder from sys.meta_path."""
127
idx = len(sys.meta_path)
130
finder = sys.meta_path[idx]
131
if getattr(finder, "prefix", "") == self.module_prefix:
132
self.log("removed %r from sys.meta_path", finder)
133
sys.meta_path.pop(idx)
135
def _unregister_all(self):
136
"""Remove all plugins in the test namespace from sys.modules."""
137
for name in list(sys.modules):
138
if name.startswith(self.module_prefix) or name == self.module_name:
139
self.log("removed %s from sys.modules", name)
140
del sys.modules[name]
142
def assertPluginModules(self, plugin_dict):
144
dict((k[len(self.module_prefix):], sys.modules[k])
145
for k in sys.modules if k.startswith(self.module_prefix)),
75
def _unregister_plugin(self, name):
76
"""Remove the plugin from sys.modules and the bzrlib namespace."""
77
py_name = 'bzrlib.plugins.%s' % name
78
if py_name in sys.modules:
79
del sys.modules[py_name]
80
if getattr(bzrlib.plugins, name, None) is not None:
81
delattr(bzrlib.plugins, name)
83
def _unregister_plugin_submodule(self, plugin_name, submodule_name):
84
"""Remove the submodule from sys.modules and the bzrlib namespace."""
85
py_name = 'bzrlib.plugins.%s.%s' % (plugin_name, submodule_name)
86
if py_name in sys.modules:
87
del sys.modules[py_name]
88
plugin = getattr(bzrlib.plugins, plugin_name, None)
89
if plugin is not None:
90
if getattr(plugin, submodule_name, None) is not None:
91
delattr(plugin, submodule_name)
148
93
def assertPluginUnknown(self, name):
149
self.assertTrue(getattr(self.module, name, None) is None)
150
self.assertFalse(self.module_prefix + name in sys.modules)
94
self.assertFalse(getattr(bzrlib.plugins, name, None) is not None)
95
self.assertFalse('bzrlib.plugins.%s' % name in sys.modules)
152
97
def assertPluginKnown(self, name):
153
self.assertTrue(getattr(self.module, name, None) is not None)
154
self.assertTrue(self.module_prefix + name in sys.modules)
98
self.assertTrue(getattr(bzrlib.plugins, name, None) is not None)
99
self.assertTrue('bzrlib.plugins.%s' % name in sys.modules)
157
102
class TestLoadingPlugins(BaseTestPlugins):
293
269
def test_plugin_with_bad_api_version_reports(self):
294
270
"""Try loading a plugin that requests an unsupported api.
296
272
Observe that it records the problem but doesn't complain on stderr.
298
274
See https://bugs.launchpad.net/bzr/+bug/704195
276
self.overrideAttr(plugin, 'plugin_warnings', {})
300
277
name = 'wants100.py'
301
with open(name, 'w') as f:
302
f.write("import breezy\n"
303
"from breezy.errors import IncompatibleVersion\n"
304
"raise IncompatibleVersion(breezy, [(1, 0, 0)], (0, 0, 5))\n")
280
f.write("import bzrlib.api\n"
281
"bzrlib.api.require_any_api(bzrlib, [(1, 0, 0)])\n")
305
284
log = self.load_and_capture(name)
306
285
self.assertNotContainsRe(log,
307
r"It supports breezy version")
308
self.assertEqual({'wants100'}, viewkeys(self.plugin_warnings))
286
r"It requested API version")
289
plugin.plugin_warnings.keys())
309
290
self.assertContainsRe(
310
self.plugin_warnings['wants100'][0],
311
r"It supports breezy version")
291
plugin.plugin_warnings['wants100'][0],
292
r"It requested API version")
313
294
def test_plugin_with_bad_name_does_not_load(self):
314
295
# The file name here invalid for a python module.
315
name = 'brz-bad plugin-name..py'
316
open(name, 'w').close()
296
name = 'bzr-bad plugin-name..py'
297
file(name, 'w').close()
317
298
log = self.load_and_capture(name)
318
299
self.assertContainsRe(log,
319
r"Unable to load 'brz-bad plugin-name\.' in '\.' as a plugin "
300
r"Unable to load 'bzr-bad plugin-name\.' in '\.' as a plugin "
320
301
"because the file path isn't a valid module name; try renaming "
321
"it to 'bad_plugin_name_'\\.")
302
"it to 'bad_plugin_name_'\.")
324
305
class TestPlugins(BaseTestPlugins):
326
307
def setup_plugin(self, source=""):
327
# This test tests a new plugin appears in breezy.plugin.plugins().
308
# This test tests a new plugin appears in bzrlib.plugin.plugins().
328
309
# check the plugin is not loaded already
329
310
self.assertPluginUnknown('plugin')
330
311
# write a plugin that _cannot_ fail to load.
331
with open('plugin.py', 'w') as f: f.write(source + '\n')
332
self.load_with_paths(['.'])
334
def test_plugin_loaded(self):
335
self.assertPluginUnknown('plugin')
336
self.assertIs(None, breezy.plugin.get_loaded_plugin('plugin'))
338
p = breezy.plugin.get_loaded_plugin('plugin')
339
self.assertIsInstance(p, breezy.plugin.PlugIn)
340
self.assertIs(p.module, sys.modules[self.module_prefix + 'plugin'])
342
def test_plugin_loaded_disabled(self):
343
self.assertPluginUnknown('plugin')
344
self.overrideEnv('BRZ_DISABLE_PLUGINS', 'plugin')
346
self.assertIs(None, breezy.plugin.get_loaded_plugin('plugin'))
312
with file('plugin.py', 'w') as f: f.write(source + '\n')
313
self.addCleanup(self.teardown_plugin)
314
plugin.load_from_path(['.'])
316
def teardown_plugin(self):
317
self._unregister_plugin('plugin')
318
self.assertPluginUnknown('plugin')
348
320
def test_plugin_appears_in_plugins(self):
349
321
self.setup_plugin()
350
322
self.assertPluginKnown('plugin')
351
p = self.plugins['plugin']
352
self.assertIsInstance(p, breezy.plugin.PlugIn)
353
self.assertIs(p.module, sys.modules[self.module_prefix + 'plugin'])
323
p = plugin.plugins()['plugin']
324
self.assertIsInstance(p, bzrlib.plugin.PlugIn)
325
self.assertEqual(p.module, plugins.plugin)
355
327
def test_trivial_plugin_get_path(self):
356
328
self.setup_plugin()
357
p = self.plugins['plugin']
329
p = plugin.plugins()['plugin']
358
330
plugin_path = self.test_dir + '/plugin.py'
359
331
self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
361
333
def test_plugin_get_path_py_not_pyc(self):
362
334
# first import creates plugin.pyc
363
335
self.setup_plugin()
364
self.promote_cache(self.test_dir)
366
self.load_with_paths(['.']) # import plugin.pyc
336
self.teardown_plugin()
337
plugin.load_from_path(['.']) # import plugin.pyc
367
338
p = plugin.plugins()['plugin']
368
339
plugin_path = self.test_dir + '/plugin.py'
369
340
self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
429
402
def test_no_version_info___version__(self):
430
403
self.setup_plugin()
431
plugin = breezy.plugin.plugins()['plugin']
404
plugin = bzrlib.plugin.plugins()['plugin']
432
405
self.assertEqual("unknown", plugin.__version__)
434
407
def test_str__version__with_version_info(self):
435
408
self.setup_plugin("version_info = '1.2.3'")
436
plugin = breezy.plugin.plugins()['plugin']
409
plugin = bzrlib.plugin.plugins()['plugin']
437
410
self.assertEqual("1.2.3", plugin.__version__)
439
412
def test_noniterable__version__with_version_info(self):
440
413
self.setup_plugin("version_info = (1)")
441
plugin = breezy.plugin.plugins()['plugin']
414
plugin = bzrlib.plugin.plugins()['plugin']
442
415
self.assertEqual("1", plugin.__version__)
444
417
def test_1__version__with_version_info(self):
445
418
self.setup_plugin("version_info = (1,)")
446
plugin = breezy.plugin.plugins()['plugin']
419
plugin = bzrlib.plugin.plugins()['plugin']
447
420
self.assertEqual("1", plugin.__version__)
449
422
def test_1_2__version__with_version_info(self):
450
423
self.setup_plugin("version_info = (1, 2)")
451
plugin = breezy.plugin.plugins()['plugin']
424
plugin = bzrlib.plugin.plugins()['plugin']
452
425
self.assertEqual("1.2", plugin.__version__)
454
427
def test_1_2_3__version__with_version_info(self):
455
428
self.setup_plugin("version_info = (1, 2, 3)")
456
plugin = breezy.plugin.plugins()['plugin']
429
plugin = bzrlib.plugin.plugins()['plugin']
457
430
self.assertEqual("1.2.3", plugin.__version__)
459
432
def test_candidate__version__with_version_info(self):
460
433
self.setup_plugin("version_info = (1, 2, 3, 'candidate', 1)")
461
plugin = breezy.plugin.plugins()['plugin']
434
plugin = bzrlib.plugin.plugins()['plugin']
462
435
self.assertEqual("1.2.3rc1", plugin.__version__)
464
437
def test_dev__version__with_version_info(self):
465
438
self.setup_plugin("version_info = (1, 2, 3, 'dev', 0)")
466
plugin = breezy.plugin.plugins()['plugin']
439
plugin = bzrlib.plugin.plugins()['plugin']
467
440
self.assertEqual("1.2.3dev", plugin.__version__)
469
442
def test_dev_fallback__version__with_version_info(self):
470
443
self.setup_plugin("version_info = (1, 2, 3, 'dev', 4)")
471
plugin = breezy.plugin.plugins()['plugin']
444
plugin = bzrlib.plugin.plugins()['plugin']
472
445
self.assertEqual("1.2.3dev4", plugin.__version__)
474
447
def test_final__version__with_version_info(self):
475
448
self.setup_plugin("version_info = (1, 2, 3, 'final', 0)")
476
plugin = breezy.plugin.plugins()['plugin']
449
plugin = bzrlib.plugin.plugins()['plugin']
477
450
self.assertEqual("1.2.3", plugin.__version__)
479
452
def test_final_fallback__version__with_version_info(self):
480
453
self.setup_plugin("version_info = (1, 2, 3, 'final', 2)")
481
plugin = breezy.plugin.plugins()['plugin']
454
plugin = bzrlib.plugin.plugins()['plugin']
482
455
self.assertEqual("1.2.3.2", plugin.__version__)
485
# GZ 2017-06-02: Move this suite to blackbox, as it's what it actually is.
486
class TestPluginHelp(BaseTestPlugins):
458
class TestPluginHelp(tests.TestCaseInTempDir):
488
460
def split_help_commands(self):
640
621
def test_get_help_topic(self):
641
622
"""The help topic for a plugin is its module name."""
642
mod = FakeModule('two lines of help\nand more', 'breezy.plugins.demo')
623
mod = FakeModule('two lines of help\nand more', 'bzrlib.plugins.demo')
643
624
topic = plugin.ModuleHelpTopic(mod)
644
625
self.assertEqual('demo', topic.get_help_topic())
645
626
mod = FakeModule('two lines of help\nand more',
646
'breezy.plugins.foo_bar')
627
'bzrlib.plugins.foo_bar')
647
628
topic = plugin.ModuleHelpTopic(mod)
648
629
self.assertEqual('foo_bar', topic.get_help_topic())
632
class TestLoadFromPath(tests.TestCaseInTempDir):
635
super(TestLoadFromPath, self).setUp()
636
# Change bzrlib.plugin to think no plugins have been loaded yet.
637
self.overrideAttr(bzrlib.plugins, '__path__', [])
638
self.overrideAttr(plugin, '_loaded', False)
640
# Monkey-patch load_from_path to stop it from actually loading anything.
641
self.overrideAttr(plugin, 'load_from_path', lambda dirs: None)
643
def test_set_plugins_path_with_args(self):
644
plugin.set_plugins_path(['a', 'b'])
645
self.assertEqual(['a', 'b'], bzrlib.plugins.__path__)
647
def test_set_plugins_path_defaults(self):
648
plugin.set_plugins_path()
649
self.assertEqual(plugin.get_standard_plugins_path(),
650
bzrlib.plugins.__path__)
652
def test_get_standard_plugins_path(self):
653
path = plugin.get_standard_plugins_path()
654
for directory in path:
655
self.assertNotContainsRe(directory, r'\\/$')
657
from distutils.sysconfig import get_python_lib
661
if sys.platform != 'win32':
662
python_lib = get_python_lib()
663
for directory in path:
664
if directory.startswith(python_lib):
667
self.fail('No path to global plugins')
669
def test_get_standard_plugins_path_env(self):
670
self.overrideEnv('BZR_PLUGIN_PATH', 'foo/')
671
path = plugin.get_standard_plugins_path()
672
for directory in path:
673
self.assertNotContainsRe(directory, r'\\/$')
675
def test_load_plugins(self):
676
plugin.load_plugins(['.'])
677
self.assertEqual(bzrlib.plugins.__path__, ['.'])
678
# subsequent loads are no-ops
679
plugin.load_plugins(['foo'])
680
self.assertEqual(bzrlib.plugins.__path__, ['.'])
682
def test_load_plugins_default(self):
683
plugin.load_plugins()
684
path = plugin.get_standard_plugins_path()
685
self.assertEqual(path, bzrlib.plugins.__path__)
651
688
class TestEnvPluginPath(tests.TestCase):
691
super(TestEnvPluginPath, self).setUp()
692
self.overrideAttr(plugin, 'DEFAULT_PLUGIN_PATH', None)
694
self.user = plugin.get_user_plugin_path()
695
self.site = plugin.get_site_plugin_path()
696
self.core = plugin.get_core_plugin_path()
698
def _list2paths(self, *args):
701
plugin._append_new_path(paths, p)
704
def _set_path(self, *args):
705
path = os.pathsep.join(self._list2paths(*args))
706
self.overrideEnv('BZR_PLUGIN_PATH', path)
657
708
def check_path(self, expected_dirs, setting_dirs):
658
if setting_dirs is None:
659
del os.environ['BRZ_PLUGIN_PATH']
661
os.environ['BRZ_PLUGIN_PATH'] = os.pathsep.join(setting_dirs)
662
actual = [(p if t == 'path' else t.upper())
663
for p, t in plugin._env_plugin_path()]
664
self.assertEqual(expected_dirs, actual)
710
self._set_path(*setting_dirs)
711
actual = plugin.get_standard_plugins_path()
712
self.assertEquals(self._list2paths(*expected_dirs), actual)
666
714
def test_default(self):
667
715
self.check_path([self.user, self.core, self.site],
734
782
class TestDisablePlugin(BaseTestPlugins):
785
super(TestDisablePlugin, self).setUp()
786
self.create_plugin_package('test_foo')
787
# Make sure we don't pollute the plugins namespace
788
self.overrideAttr(plugins, '__path__')
789
# Be paranoid in case a test fail
790
self.addCleanup(self._unregister_plugin, 'test_foo')
736
792
def test_cannot_import(self):
737
self.create_plugin_package('works')
738
self.create_plugin_package('fails')
739
self.overrideEnv('BRZ_DISABLE_PLUGINS', 'fails')
740
self.update_module_paths(["."])
741
import breezy.testingplugins.works as works
793
self.overrideEnv('BZR_DISABLE_PLUGINS', 'test_foo')
794
plugin.set_plugins_path(['.'])
743
import breezy.testingplugins.fails as fails
796
import bzrlib.plugins.test_foo
744
797
except ImportError:
747
self.fail("Loaded blocked plugin: " + repr(fails))
748
self.assertPluginModules({'fails': None, 'works': works})
750
def test_partial_imports(self):
751
self.create_plugin('good')
752
self.create_plugin('bad')
753
self.create_plugin_package('ugly')
754
self.overrideEnv('BRZ_DISABLE_PLUGINS', 'bad:ugly')
755
self.load_with_paths(['.'])
756
self.assertEqual({'good'}, viewkeys(self.plugins))
757
self.assertPluginModules({
758
'good': self.plugins['good'].module,
762
# Ensure there are no warnings about plugins not being imported as
763
# the user has explictly requested they be disabled.
764
self.assertNotContainsRe(self.get_log(), r"Unable to load plugin")
767
class TestEnvDisablePlugins(tests.TestCase):
769
def _get_names(self, env_value):
770
os.environ['BRZ_DISABLE_PLUGINS'] = env_value
771
return plugin._env_disable_plugins()
773
def test_unset(self):
774
self.assertEqual([], plugin._env_disable_plugins())
776
def test_empty(self):
777
self.assertEqual([], self._get_names(''))
779
def test_single(self):
780
self.assertEqual(['single'], self._get_names('single'))
782
def test_multi(self):
783
expected = ['one', 'two']
784
self.assertEqual(expected, self._get_names(os.pathsep.join(expected)))
786
def test_mixed(self):
787
value = os.pathsep.join(['valid', 'in-valid'])
788
self.assertEqual(['valid'], self._get_names(value))
789
self.assertContainsRe(self.get_log(),
790
r"Invalid name 'in-valid' in BRZ_DISABLE_PLUGINS=" + repr(value))
793
class TestEnvPluginsAt(tests.TestCase):
795
def _get_paths(self, env_value):
796
os.environ['BRZ_PLUGINS_AT'] = env_value
797
return plugin._env_plugins_at()
799
def test_empty(self):
800
self.assertEqual([], plugin._env_plugins_at())
801
self.assertEqual([], self._get_paths(''))
799
self.assertPluginUnknown('test_foo')
801
def test_regular_load(self):
802
self.overrideAttr(plugin, '_loaded', False)
803
plugin.load_plugins(['.'])
804
self.assertPluginKnown('test_foo')
805
self.assertDocstring("This is the doc for test_foo",
806
bzrlib.plugins.test_foo)
808
def test_not_loaded(self):
810
def captured_warning(*args, **kwargs):
811
self.warnings.append((args, kwargs))
812
self.overrideAttr(trace, 'warning', captured_warning)
813
# Reset the flag that protect against double loading
814
self.overrideAttr(plugin, '_loaded', False)
815
self.overrideEnv('BZR_DISABLE_PLUGINS', 'test_foo')
816
plugin.load_plugins(['.'])
817
self.assertPluginUnknown('test_foo')
818
# Make sure we don't warn about the plugin ImportError since this has
819
# been *requested* by the user.
820
self.assertLength(0, self.warnings)
824
class TestLoadPluginAtSyntax(tests.TestCase):
826
def _get_paths(self, paths):
827
return plugin._get_specific_plugin_paths(paths)
829
def test_empty(self):
830
self.assertEquals([], self._get_paths(None))
831
self.assertEquals([], self._get_paths(''))
803
833
def test_one_path(self):
804
self.assertEqual([('b', 'man')], self._get_paths('b@man'))
806
def test_multiple(self):
808
[('tools', 'bzr-tools'), ('p', 'play.py')],
809
self._get_paths(os.pathsep.join(('tools@bzr-tools', 'p@play.py'))))
811
def test_many_at(self):
813
[('church', 'StMichael@Plea@Norwich')],
814
self._get_paths('church@StMichael@Plea@Norwich'))
816
def test_only_py(self):
817
self.assertEqual([('test', './test.py')], self._get_paths('./test.py'))
819
def test_only_package(self):
820
self.assertEqual([('py', '/opt/b/py')], self._get_paths('/opt/b/py'))
822
def test_bad_name(self):
823
self.assertEqual([], self._get_paths('/usr/local/bzr-git'))
824
self.assertContainsRe(self.get_log(),
825
r"Invalid name 'bzr-git' in BRZ_PLUGINS_AT='/usr/local/bzr-git'")
834
self.assertEquals([('b', 'man')], self._get_paths('b@man'))
836
def test_bogus_path(self):
838
self.assertRaises(errors.BzrCommandError, self._get_paths, 'batman')
839
# Too much '@' isn't good either
840
self.assertRaises(errors.BzrCommandError, self._get_paths,
841
'batman@mobile@cave')
842
# An empty description probably indicates a problem
843
self.assertRaises(errors.BzrCommandError, self._get_paths,
844
os.pathsep.join(['batman@cave', '', 'robin@mobile']))
828
847
class TestLoadPluginAt(BaseTestPlugins):
831
850
super(TestLoadPluginAt, self).setUp()
851
# Make sure we don't pollute the plugins namespace
852
self.overrideAttr(plugins, '__path__')
853
# Reset the flag that protect against double loading
854
self.overrideAttr(plugin, '_loaded', False)
832
855
# Create the same plugin in two directories
833
856
self.create_plugin_package('test_foo', dir='non-standard-dir')
834
857
# The "normal" directory, we use 'standard' instead of 'plugins' to
835
858
# avoid depending on the precise naming.
836
859
self.create_plugin_package('test_foo', dir='standard/test_foo')
860
# All the tests will load the 'test_foo' plugin from various locations
861
self.addCleanup(self._unregister_plugin, 'test_foo')
862
# Unfortunately there's global cached state for the specific
864
self.addCleanup(plugin.PluginImporter.reset)
838
866
def assertTestFooLoadedFrom(self, path):
839
867
self.assertPluginKnown('test_foo')
840
868
self.assertDocstring('This is the doc for test_foo',
841
self.module.test_foo)
842
self.assertEqual(path, self.module.test_foo.dir_source)
869
bzrlib.plugins.test_foo)
870
self.assertEqual(path, bzrlib.plugins.test_foo.dir_source)
844
872
def test_regular_load(self):
845
self.load_with_paths(['standard'])
873
plugin.load_plugins(['standard'])
846
874
self.assertTestFooLoadedFrom('standard/test_foo')
848
876
def test_import(self):
849
self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir')
850
self.update_module_paths(['standard'])
851
import breezy.testingplugins.test_foo
877
self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
878
plugin.set_plugins_path(['standard'])
880
import bzrlib.plugins.test_foo
852
883
self.assertTestFooLoadedFrom('non-standard-dir')
854
885
def test_loading(self):
855
self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir')
856
self.load_with_paths(['standard'])
857
self.assertTestFooLoadedFrom('non-standard-dir')
859
def test_loading_other_name(self):
860
self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir')
861
os.rename('standard/test_foo', 'standard/test_bar')
862
self.load_with_paths(['standard'])
886
self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
887
plugin.load_plugins(['standard'])
863
888
self.assertTestFooLoadedFrom('non-standard-dir')
865
890
def test_compiled_loaded(self):
866
self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir')
867
self.load_with_paths(['standard'])
891
self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
892
plugin.load_plugins(['standard'])
868
893
self.assertTestFooLoadedFrom('non-standard-dir')
869
894
self.assertIsSameRealPath('non-standard-dir/__init__.py',
870
self.module.test_foo.__file__)
895
bzrlib.plugins.test_foo.__file__)
872
897
# Try importing again now that the source has been compiled
873
os.remove('non-standard-dir/__init__.py')
874
self.promote_cache('non-standard-dir')
876
self.load_with_paths(['standard'])
898
self._unregister_plugin('test_foo')
899
plugin._loaded = False
900
plugin.load_plugins(['standard'])
877
901
self.assertTestFooLoadedFrom('non-standard-dir')
878
suffix = plugin.COMPILED_EXT
879
self.assertIsSameRealPath('non-standard-dir/__init__' + suffix,
880
self.module.test_foo.__file__)
906
self.assertIsSameRealPath('non-standard-dir/__init__.%s' % suffix,
907
bzrlib.plugins.test_foo.__file__)
882
909
def test_submodule_loading(self):
883
910
# We create an additional directory under the one for test_foo
884
911
self.create_plugin_package('test_bar', dir='non-standard-dir/test_bar')
885
self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir')
886
self.update_module_paths(['standard'])
887
import breezy.testingplugins.test_foo
888
self.assertEqual(self.module_prefix + 'test_foo',
889
self.module.test_foo.__package__)
890
import breezy.testingplugins.test_foo.test_bar
912
self.addCleanup(self._unregister_plugin_submodule,
913
'test_foo', 'test_bar')
914
self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
915
plugin.set_plugins_path(['standard'])
916
import bzrlib.plugins.test_foo
917
self.assertEqual('bzrlib.plugins.test_foo',
918
bzrlib.plugins.test_foo.__package__)
919
import bzrlib.plugins.test_foo.test_bar
891
920
self.assertIsSameRealPath('non-standard-dir/test_bar/__init__.py',
892
self.module.test_foo.test_bar.__file__)
921
bzrlib.plugins.test_foo.test_bar.__file__)
894
923
def test_relative_submodule_loading(self):
895
924
self.create_plugin_package('test_foo', dir='another-dir', source='''
896
from . import test_bar
898
927
# We create an additional directory under the one for test_foo
899
928
self.create_plugin_package('test_bar', dir='another-dir/test_bar')
900
self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@another-dir')
901
self.update_module_paths(['standard'])
902
import breezy.testingplugins.test_foo
903
self.assertEqual(self.module_prefix + 'test_foo',
904
self.module.test_foo.__package__)
929
self.addCleanup(self._unregister_plugin_submodule,
930
'test_foo', 'test_bar')
931
self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@another-dir')
932
plugin.set_plugins_path(['standard'])
933
import bzrlib.plugins.test_foo
934
self.assertEqual('bzrlib.plugins.test_foo',
935
bzrlib.plugins.test_foo.__package__)
905
936
self.assertIsSameRealPath('another-dir/test_bar/__init__.py',
906
self.module.test_foo.test_bar.__file__)
937
bzrlib.plugins.test_foo.test_bar.__file__)
908
939
def test_loading_from___init__only(self):
909
940
# We rename the existing __init__.py file to ensure that we don't load