Blame SOURCES/0213-reportclient-honor-ABRT_VERBOSE.patch

28bab8
From 128490bb35079d77c0fa04f2e254bd6a0acc382a Mon Sep 17 00:00:00 2001
28bab8
From: Jakub Filak <jfilak@redhat.com>
28bab8
Date: Thu, 24 Nov 2016 07:54:21 +0100
28bab8
Subject: [PATCH] reportclient: honor ABRT_VERBOSE
28bab8
28bab8
libreport's verbosity can be configured via ABRT_VERBOSE environment
28bab8
variable and reportclient must be aware of that.
28bab8
28bab8
Related to #1257159
28bab8
28bab8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
28bab8
---
28bab8
 src/client-python/__init__.py |  9 ++++++++
28bab8
 tests/Makefile.am             |  1 +
28bab8
 tests/client_python.at        | 53 +++++++++++++++++++++++++++++++++++++++++++
28bab8
 tests/testsuite.at            |  1 +
28bab8
 4 files changed, 64 insertions(+)
28bab8
 create mode 100644 tests/client_python.at
28bab8
28bab8
diff --git a/src/client-python/__init__.py b/src/client-python/__init__.py
28bab8
index 8966f22..f10f710 100644
28bab8
--- a/src/client-python/__init__.py
28bab8
+++ b/src/client-python/__init__.py
28bab8
@@ -31,6 +31,7 @@ from report import EXIT_STOP_EVENT_RUN as RETURN_STOP_EVENT_RUN
28bab8
 
28bab8
 
28bab8
 GETTEXT_PROGNAME = "libreport"
28bab8
+import os
28bab8
 import locale
28bab8
 import gettext
28bab8
 
28bab8
@@ -52,10 +53,18 @@ def init_gettext():
28bab8
 init_gettext()
28bab8
 
28bab8
 verbose = 0
28bab8
+ABRT_VERBOSE = os.getenv("ABRT_VERBOSE")
28bab8
+if ABRT_VERBOSE:
28bab8
+    try:
28bab8
+        verbose = int(ABRT_VERBOSE)
28bab8
+    except:
28bab8
+        pass
28bab8
+
28bab8
 
28bab8
 def set_verbosity(verbosity):
28bab8
     global verbose
28bab8
     verbose = verbosity
28bab8
+    os.environ["ABRT_VERBOSE"] = str(verbose)
28bab8
 
28bab8
 def log(fmt, *args):
28bab8
     sys.stderr.write("%s\n" % (fmt % args))
28bab8
diff --git a/tests/Makefile.am b/tests/Makefile.am
28bab8
index b45f2d9..52dfce4 100644
28bab8
--- a/tests/Makefile.am
28bab8
+++ b/tests/Makefile.am
28bab8
@@ -40,6 +40,7 @@ TESTSUITE_AT = \
28bab8
   libreport_types.at \
28bab8
   xml_definition.at \
28bab8
   report_python.at \
28bab8
+  client_python.at \
28bab8
   xfuncs.at \
28bab8
   string_list.at \
28bab8
   ureport.at \
28bab8
diff --git a/tests/client_python.at b/tests/client_python.at
28bab8
new file mode 100644
28bab8
index 0000000..656b1b2
28bab8
--- /dev/null
28bab8
+++ b/tests/client_python.at
28bab8
@@ -0,0 +1,53 @@
28bab8
+# -*- Autotest -*-
28bab8
+
28bab8
+AT_BANNER([client_python])
28bab8
+
28bab8
+## --------- ##
28bab8
+## verbosity ##
28bab8
+## --------- ##
28bab8
+
28bab8
+AT_PYTESTFUN([verbosity], [[
28bab8
+import sys
28bab8
+import os
28bab8
+import unittest
28bab8
+
28bab8
+sys.path.insert(0, "../../../src/client-python")
28bab8
+sys.path.insert(0, "../../../src/client-python/.libs")
28bab8
+
28bab8
+
28bab8
+class TestReportClientVerbose(unittest.TestCase):
28bab8
+    def setUp(self):
28bab8
+        try:
28bab8
+            del os.environ["ABRT_VERBOSE"]
28bab8
+        except:
28bab8
+            pass
28bab8
+        os.unsetenv("ABRT_VERBOSE")
28bab8
+        self.clientpython = __import__("client-python", globals(), locals(), [], -1)
28bab8
+        reload(self.clientpython)
28bab8
+        sys.modules["clientpython"] = self.clientpython
28bab8
+
28bab8
+    def tearDown(self):
28bab8
+        del sys.modules["clientpython"]
28bab8
+
28bab8
+    def test_default(self):
28bab8
+        self.assertEquals(self.clientpython.verbose, 0)
28bab8
+
28bab8
+    def test_assign(self):
28bab8
+        self.clientpython.set_verbosity(1)
28bab8
+        self.assertEquals(self.clientpython.verbose, 1)
28bab8
+        self.assertEquals(os.environ["ABRT_VERBOSE"], "1")
28bab8
+
28bab8
+    def test_load_from_environ(self):
28bab8
+        os.environ["ABRT_VERBOSE"] = "2"
28bab8
+        reload(self.clientpython)
28bab8
+        self.assertEquals(self.clientpython.verbose, 2)
28bab8
+
28bab8
+    def test_recover_from_invalid_environ(self):
28bab8
+        os.environ["ABRT_VERBOSE"] = "foo"
28bab8
+        reload(self.clientpython)
28bab8
+        self.assertEquals(self.clientpython.verbose, 0)
28bab8
+
28bab8
+
28bab8
+if __name__ == "__main__":
28bab8
+    unittest.main()
28bab8
+]])
28bab8
diff --git a/tests/testsuite.at b/tests/testsuite.at
28bab8
index ccb37d1..8ded735 100644
28bab8
--- a/tests/testsuite.at
28bab8
+++ b/tests/testsuite.at
28bab8
@@ -15,6 +15,7 @@ m4_include([make_description.at])
28bab8
 m4_include([libreport_types.at])
28bab8
 m4_include([xml_definition.at])
28bab8
 m4_include([report_python.at])
28bab8
+m4_include([client_python.at])
28bab8
 m4_include([string_list.at])
28bab8
 m4_include([ureport.at])
28bab8
 m4_include([problem_report.at])
28bab8
-- 
28bab8
1.8.3.1
28bab8