[mousetrap/gnome3-wip: 228/240] Add tests for mousetrap.core.Observable.
- From: Heidi Ellis <heidiellis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetrap/gnome3-wip: 228/240] Add tests for mousetrap.core.Observable.
- Date: Mon, 8 Sep 2014 15:31:44 +0000 (UTC)
commit ec1e8a916d0f1f77e85c07cd906fb9ea00caa701
Author: Stoney Jackson <dr stoney gmail com>
Date: Mon Jun 30 17:29:12 2014 -0400
Add tests for mousetrap.core.Observable.
src/mousetrap/tests/test_core.py | 63 ++++++++++++++++++++++++++++++++++++++
1 files changed, 63 insertions(+), 0 deletions(-)
---
diff --git a/src/mousetrap/tests/test_core.py b/src/mousetrap/tests/test_core.py
new file mode 100644
index 0000000..0345894
--- /dev/null
+++ b/src/mousetrap/tests/test_core.py
@@ -0,0 +1,63 @@
+import unittest
+from mousetrap.core import Loop, Observable
+
+
+class test_observable(unittest.TestCase):
+
+ def setUp(self):
+ self.observable = Observable()
+ self.client1 = Client()
+ self.client2 = Client()
+
+ def test_observable_callback_noArguments_success(self):
+ self.observable.subscribe(self.client1)
+ self.observable._fire('callback')
+ self.assertTrue(
+ len(self.client1.callback_params) == 1,
+ msg="callback not called."
+ )
+
+ def test_observable_callback_withArguments_success(self):
+ self.observable._add_argument('param', 'param')
+ self.observable.subscribe(self.client1)
+ self.observable._fire('callback')
+ self.assertEquals(
+ 'param', self.client1.callback_params[0]['param'],
+ msg="param not passed correctly."
+ )
+
+ def test_multiple_subscribers(self):
+ self.observable.subscribe(self.client1)
+ self.observable.subscribe(self.client2)
+ self.observable._fire('callback')
+ self.assertTrue(
+ len(self.client1.callback_params) == 1,
+ msg="callback not called on client1."
+ )
+ self.assertTrue(
+ len(self.client2.callback_params) == 1,
+ msg="callback not called on client2."
+ )
+
+
+class Client(object):
+ def __init__(self):
+ self.callback_params = []
+
+ def callback(self, param=None):
+ self.callback_params.append({'param':param})
+
+
+
+class test_Loop(unittest.TestCase):
+
+ def setUp(self):
+ self.config = {'loops_per_second': 10}
+ self.loop = Loop(self.config, app=None)
+
+ def test_loop(self):
+ self.loop.start()
+
+
+if __name__ == '__main__':
+ unittest.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]