mirror of
https://github.com/jlengrand/Observer.git
synced 2026-03-10 08:31:23 +00:00
Starts addind tests to codeBase
Adds tests for Observer TODO: Test subscription and unsubscription
This commit is contained in:
@@ -35,6 +35,9 @@ class Observer():
|
||||
Creates Observer.
|
||||
An Observer is uniquely defined by its name.vDefault name is 'observer'.
|
||||
"""
|
||||
if not isinstance(name, str):
|
||||
raise TypeError("Expected string for name")
|
||||
|
||||
self.name = name
|
||||
self.message = 'message'
|
||||
|
||||
|
||||
112
testObserver.py
112
testObserver.py
@@ -1,20 +1,106 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
* Copyright (c) 2012. Julien Lengrand-Lambert <jlengrand[at]gmail[dot]com>.
|
||||
* Released to public domain under terms of the BSD Simplified license.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the organization nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* See <http://www.opensource.org/licenses/bsd-license>
|
||||
|
||||
from Observer import Observer
|
||||
from Observable import Observable
|
||||
Unit tests for the Observer module.
|
||||
See README for more information about this Observer implementation
|
||||
|
||||
a = Observer("riri")
|
||||
b = Observer("fifi")
|
||||
c = Observer("loulou")
|
||||
May coverage be with me
|
||||
"""
|
||||
|
||||
d = Observable()
|
||||
import unittest
|
||||
import Observer as obs
|
||||
|
||||
d.subscribe(a)
|
||||
d.subscribe(b)
|
||||
d.subscribe(b)
|
||||
d.subscribe(c)
|
||||
|
||||
d.unsubscribe(b)
|
||||
class TestObserver(unittest.TestCase):
|
||||
"""
|
||||
Testing all classes from Observer module
|
||||
"""
|
||||
def setUp(self):
|
||||
"""
|
||||
Method called before each test
|
||||
"""
|
||||
self.myObservable = obs.Observable()
|
||||
|
||||
d.set_val(3)
|
||||
d.set_val()
|
||||
self.name1 = "myObserver1"
|
||||
self.myObserver1 = obs.Observer(self.name1)
|
||||
self.name2 = "myObserver2"
|
||||
self.myObserver2 = obs.Observer(self.name2)
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
"""
|
||||
Method called after each test
|
||||
"""
|
||||
pass
|
||||
|
||||
def testObserver(self):
|
||||
"""
|
||||
Checks for Exception if strange input
|
||||
"""
|
||||
# Normal behavior
|
||||
self.assertEquals(self.myObserver1.name, self.name1)
|
||||
self.assertEquals(str(self.myObserver1), self.name1)
|
||||
self.assertRaises(TypeError, lambda: obs.Observer(42))
|
||||
|
||||
def testSubscribe(self):
|
||||
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def testUnsubscribe(self):
|
||||
pass
|
||||
|
||||
def testNotify(self):
|
||||
pass
|
||||
|
||||
def testNameUnicity(self):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
# a = Observer("riri")
|
||||
# b = Observer("fifi")
|
||||
# c = Observer("loulou")
|
||||
|
||||
# d = Observable()
|
||||
|
||||
# d.subscribe(a)
|
||||
# d.subscribe(b)
|
||||
# d.subscribe(b)
|
||||
# d.subscribe(c)
|
||||
|
||||
# d.unsubscribe(b)
|
||||
|
||||
# d.set_val(3)
|
||||
# d.set_val()
|
||||
Reference in New Issue
Block a user