unit tests for cli.load_plugins
This commit is contained in:
parent
0f51a9936f
commit
6fe90a170d
5 changed files with 47 additions and 7 deletions
14
cli/koji
14
cli/koji
|
|
@ -65,16 +65,14 @@ def register_plugin(plugin):
|
|||
globals()[name] = v
|
||||
|
||||
|
||||
def load_plugins(options):
|
||||
def load_plugins(options, path):
|
||||
"""Load plugins specified by our configuration plus system plugins. Order
|
||||
is that system plugins are first, so they can be overriden by
|
||||
user-specified ones with same name."""
|
||||
logger = logging.getLogger('koji.plugins')
|
||||
syspath = '%s/lib/python%s.%s/site-packages/koji_cli_plugins' % \
|
||||
(sys.prefix, sys.version_info.major, sys.version_info.minor)
|
||||
if os.path.exists(syspath):
|
||||
tracker = koji.plugin.PluginTracker(path=syspath)
|
||||
for name in sorted(os.listdir(syspath)):
|
||||
if os.path.exists(path):
|
||||
tracker = koji.plugin.PluginTracker(path=path)
|
||||
for name in sorted(os.listdir(path)):
|
||||
if not name.endswith('.py'):
|
||||
continue
|
||||
name = name[:-3]
|
||||
|
|
@ -165,7 +163,9 @@ def get_options():
|
|||
else:
|
||||
warn("Warning: The pkgurl option is obsolete, please use topurl instead")
|
||||
|
||||
load_plugins(options)
|
||||
plugins_path = '%s/lib/python%s.%s/site-packages/koji_cli_plugins' % \
|
||||
(sys.prefix, sys.version_info.major, sys.version_info.minor)
|
||||
load_plugins(options, plugins_path)
|
||||
|
||||
if options.help_commands:
|
||||
list_commands()
|
||||
|
|
|
|||
0
tests/test_cli/data/plugins/not_plugin.omg
Normal file
0
tests/test_cli/data/plugins/not_plugin.omg
Normal file
19
tests/test_cli/data/plugins/plugin1.py
Normal file
19
tests/test_cli/data/plugins/plugin1.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from koji.plugin import export_cli, export_as
|
||||
|
||||
@export_as('foobar')
|
||||
@export_cli
|
||||
def foo():
|
||||
pass
|
||||
|
||||
@export_cli
|
||||
def foo2():
|
||||
pass
|
||||
|
||||
def foo3():
|
||||
pass
|
||||
|
||||
foo4 = 'foo4'
|
||||
|
||||
class bar():
|
||||
pass
|
||||
|
||||
1
tests/test_cli/data/plugins/plugin2.py
Normal file
1
tests/test_cli/data/plugins/plugin2.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
sth = 123
|
||||
20
tests/test_cli/test_load_plugins.py
Normal file
20
tests/test_cli/test_load_plugins.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from __future__ import absolute_import
|
||||
import mock
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from . import loadcli
|
||||
cli = loadcli.cli
|
||||
|
||||
|
||||
class TestLoadPlugins(unittest.TestCase):
|
||||
|
||||
@mock.patch('logging.getLogger')
|
||||
def test_load_plugins(self, getLogger):
|
||||
options = mock.MagicMock()
|
||||
cli.load_plugins(options, os.path.dirname(__file__) + '/data/plugins')
|
||||
self.assertTrue(callable(cli.foobar))
|
||||
self.assertTrue(callable(cli.foo2))
|
||||
self.assertFalse(hasattr(cli, 'foo3'))
|
||||
self.assertFalse(hasattr(cli, 'foo4'))
|
||||
self.assertFalse(hasattr(cli, 'sth'))
|
||||
Loading…
Add table
Add a link
Reference in a new issue