Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #234 from fedora-infra/feature/warn-if-no-plugin

Feature/warn if no plugin
  • Loading branch information...
commit 281439dbf7fb7ec9db739d72c03f29d0cfdb44aa 2 parents c4df21d + 9b3f65b
@ralphbean ralphbean authored
View
5 fedmsg/commands/tail.py
@@ -110,7 +110,6 @@ def run(self):
self.config['mute'] = True
fedmsg.init(**self.config)
- fedmsg.meta.make_processors(**self.config)
# Build a message formatter
formatter = lambda d: d
@@ -149,6 +148,10 @@ def formatter(d):
if self.config['packages']:
packages = set(map(str.strip, self.config['packages'].split(',')))
+ # Only initialize this if we have to
+ if users or packages or self.config['terse']:
+ fedmsg.meta.make_processors(**self.config)
+
# Spin up a zmq.Poller and yield messages
for name, ep, topic, message in fedmsg.tail_messages(**self.config):
if exclusive_regexp.search(topic):
View
9 fedmsg/meta/__init__.py
@@ -59,6 +59,7 @@
from fedmsg.meta.default import DefaultProcessor
import logging
+log = logging.getLogger("fedmsg")
class ProcessorsNotInitialized(Exception):
@@ -90,13 +91,19 @@ def make_processors(**config):
try:
processors.append(processor.load()(_, **config))
except Exception as e:
- log = logging.getLogger("fedmsg")
log.warn("Failed to load %r processor." % processor.name)
log.warn(str(e))
# This should always be last
processors.append(DefaultProcessor(_, **config))
+ # By default we have three builtin processors: Default, Logger, and
+ # Announce. If these are the only three, then we didn't find any
+ # externally provided ones. calls to msg2subtitle and msg2link likely will
+ # not work the way the user is expecting.
+ if len(processors) == 3:
+ log.warn("No fedmsg.meta plugins found. fedmsg.meta.msg2* crippled")
+
def msg2processor(msg, **config):
""" For a given message return the text processor that can handle it.
View
46 fedmsg/tests/test_meta.py
@@ -51,6 +51,52 @@ def inner(self):
return wrapper
+def skip_if_fedmsg_meta_FI_is_present(f):
+ """ A test decorator that will skip if fedmsg_meta_fedora_infrastructure
+ is installed.
+
+ The presence of that module will screw up some tests.
+ """
+ def _wrapper(self, *args, **kw):
+ try:
+ import fedmsg_meta_fedora_infrastructure
+ raise SkipTest("fedmsg_meta_FI is present")
+ except ImportError:
+ pass
+
+ return f(self, *args, **kw)
+
+ return make_decorator(f)(_wrapper)
+
+
+class TestForWarning(unittest.TestCase):
+ def setUp(self):
+ dirname = os.path.abspath(os.path.dirname(__file__))
+ self.config = fedmsg.config.load_config(
+ filenames=[os.path.join(dirname, "fedmsg-test-config.py")],
+ invalidate_cache=True,
+ )
+ self.config['topic_prefix'] = 'org.fedoraproject'
+ self.config['topic_prefix_re'] = '^org\.fedoraproject\.(dev|stg|prod)'
+
+ @skip_if_fedmsg_meta_FI_is_present
+ def test_for_no_plugins(self):
+ """ Test that we print a warning if no plugin is installed """
+ messages = []
+
+ def mocked_warning(message):
+ messages.append(message)
+
+ expected = 'No fedmsg.meta plugins found. fedmsg.meta.msg2* crippled'
+ original = fedmsg.meta.log.warn
+ try:
+ fedmsg.meta.log.warn = mocked_warning
+ fedmsg.meta.make_processors(**self.config)
+ eq_(messages, [expected])
+ finally:
+ fedmsg.meta.log.warn = original
+
+
class Base(unittest.TestCase):
msg = None
expected_title = None
Please sign in to comment.
Something went wrong with that request. Please try again.