[python-meh] Skip callbacks providing no information

Vratislav Podzimek vpodzime at redhat.com
Tue Dec 3 12:33:50 UTC 2013


Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 meh/dump.py        | 4 +++-
 meh/handler.py     | 4 +++-
 tests/callbacks.py | 7 +++++++
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/meh/dump.py b/meh/dump.py
index 761d5da..9c04fb0 100644
--- a/meh/dump.py
+++ b/meh/dump.py
@@ -463,7 +463,9 @@ class ExceptionDump(object):
         ret += "\nRegistered callbacks:\n"
         for (item_name, callback) in items_callbacks:
             try:
-                ret += "%s:\n%s\n" % (item_name, callback())
+                callback_ret = callback()
+                if callback_ret:
+                    ret += "%s:\n%s\n" % (item_name, callback_ret)
             except Exception as exc:
                 ret += "%s: Caused error: %s\n" % (item_name, exc)
 
diff --git a/meh/handler.py b/meh/handler.py
index b3708c2..4d98c45 100644
--- a/meh/handler.py
+++ b/meh/handler.py
@@ -266,7 +266,9 @@ class ExceptionHandler(object):
         # save data generated by callbacks
         for (item_name, (callback, _anc)) in self.conf.callbackDict.iteritems():
             try:
-                params[item_name] = callback()
+                ret = callback()
+                if ret:
+                    params[item_name] = ret
             except Exception as exc:
                 params[item_name] = "Caused error: %s" % exc
 
diff --git a/tests/callbacks.py b/tests/callbacks.py
index a73b0a8..5407f12 100644
--- a/tests/callbacks.py
+++ b/tests/callbacks.py
@@ -15,6 +15,9 @@ def callback3():
 def callback4():
     return "This was generated by the callback4"
 
+def callback5():
+    return ""
+
 class Callbacks_TestCase(BaseTestCase):
     def runTest(self):
         conf = Config(programName="CallbacksTest",
@@ -33,6 +36,7 @@ class Callbacks_TestCase(BaseTestCase):
         conf.register_callback("callback3", callback3, override=True)
 
         conf.register_callback("callback4", callback4, attchmnt_only=True)
+        conf.register_callback("callback5", callback5, attchmnt_only=False)
 
         # should not raise exception
         dump = self.dump(conf, None)
@@ -46,4 +50,7 @@ class Callbacks_TestCase(BaseTestCase):
         # should not appear in the dump (attachment only)
         self.assertNotIn("callback4", dump)
 
+        # should not appear in the dump (nothing provided)
+        self.assertNotIn("callback5", dump)
+
 
-- 
1.8.4.2



More information about the anaconda-patches mailing list