[pygobject] overrides: warn on instantiation of Gio.VolumeMonitor



commit 44a51ddd6418f8fa85df5803b8288974bcf20bc2
Author: Christoph Reiter <creiter src gnome org>
Date:   Thu Mar 23 15:49:18 2017 +0100

    overrides: warn on instantiation of Gio.VolumeMonitor
    
    Gio.VolumeMonitor.get() should be used instead
    
    https://bugzilla.gnome.org/show_bug.cgi?id=744690

 gi/overrides/Gio.py |   19 +++++++++++++++++++
 tests/test_gio.py   |   11 +++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/gi/overrides/Gio.py b/gi/overrides/Gio.py
index bb320a5..cdb3ccb 100644
--- a/gi/overrides/Gio.py
+++ b/gi/overrides/Gio.py
@@ -18,8 +18,11 @@
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 # USA
 
+import warnings
+
 from ..overrides import override, deprecated_init
 from ..module import get_introspection_module
+from gi import PyGIWarning
 
 from gi.repository import GLib
 
@@ -30,6 +33,22 @@ Gio = get_introspection_module('Gio')
 __all__ = []
 
 
+class VolumeMonitor(Gio.VolumeMonitor):
+
+    def __init__(self, *args, **kwargs):
+        super(VolumeMonitor, self).__init__(*args, **kwargs)
+
+        # https://bugzilla.gnome.org/show_bug.cgi?id=744690
+        warnings.warn(
+            "Gio.VolumeMonitor shouldn't be instantiated directly, "
+            "use Gio.VolumeMonitor.get() instead.",
+            PyGIWarning, stacklevel=2)
+
+
+VolumeMonitor = override(VolumeMonitor)
+__all__.append('VolumeMonitor')
+
+
 class FileEnumerator(Gio.FileEnumerator):
     def __iter__(self):
         return self
diff --git a/tests/test_gio.py b/tests/test_gio.py
index d3e2f49..c7239ce 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -3,8 +3,10 @@
 
 import os
 import unittest
+import warnings
 
 import gi.overrides
+from gi import PyGIWarning
 from gi.repository import GLib, Gio
 
 from helper import ignore_gi_deprecation_warnings
@@ -40,6 +42,15 @@ class TestGio(unittest.TestCase):
         value = menu.get_item_attribute_value(0, "action", GLib.VariantType.new("s"))
         self.assertEqual("app.test", value.unpack())
 
+    def test_volume_monitor_warning(self):
+        with warnings.catch_warnings(record=True) as warn:
+            warnings.simplefilter('always')
+            Gio.VolumeMonitor()
+            self.assertEqual(len(warn), 1)
+            self.assertTrue(issubclass(warn[0].category, PyGIWarning))
+            self.assertRegexpMatches(str(warn[0].message),
+                                     '.*Gio\\.VolumeMonitor\\.get\\(\\).*')
+
 
 class TestGSettings(unittest.TestCase):
     def setUp(self):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]