aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/base.py')
-rw-r--r--tests/unit/base.py50
1 files changed, 50 insertions, 0 deletions
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]