diff --git a/Observer.py b/Observer.py index 053198f..c62d3f5 100644 --- a/Observer.py +++ b/Observer.py @@ -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' diff --git a/testObserver.py b/testObserver.py index d1609cf..0498034 100644 --- a/testObserver.py +++ b/testObserver.py @@ -1,20 +1,106 @@ #!/usr/bin/env python +""" + * Copyright (c) 2012. Julien Lengrand-Lambert . + * 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 -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() \ No newline at end of file + 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() \ No newline at end of file