From e99416456afd4aa8bde42016826f9a345291cbf3 Mon Sep 17 00:00:00 2001 From: Matthew Poletiek Date: Tue, 8 Dec 2020 21:03:16 -0600 Subject: Initial Commit --- tests/unit/base.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/unit/base.py (limited to 'tests/unit/base.py') diff --git a/tests/unit/base.py b/tests/unit/base.py new file mode 100644 index 0000000..1e112ce --- /dev/null +++ b/tests/unit/base.py @@ -0,0 +1,50 @@ +import sys +import unittest + +import mock + +try: + import mox +except ImportError: + from mox3 import mox + +import warnings +warnings.simplefilter('ignore', Warning) + + +class BaseTest(unittest.TestCase): + def setUp(self): + __builtins__['_'] = lambda s: s + self.mox = mox.Mox() + + def tearDown(self): + self.mox.UnsetStubs() + self.mox.VerifyAll() + + +pygtk_mocks = ('gtk', 'pango', 'gobject') +pygtk_base_classes = ('gobject.GObject', 'gtk.HBox', 'gtk.Dialog') + + +class DummyBase(object): + def __init__(self, *a, **k): + # gtk.Dialog + self.vbox = mock.MagicMock() + + # gtk.Dialog + def set_position(self, pos): + pass + + +def mock_gtk(): + for module in pygtk_mocks: + sys.modules[module] = mock.MagicMock() + + for path in pygtk_base_classes: + module, base_class = path.split('.') + setattr(sys.modules[module], base_class, DummyBase) + + +def unmock_gtk(): + for module in pygtk_mocks: + del sys.modules[module] -- cgit v1.2.3