diff --git a/factory_method.py b/factory_method.py index c21e3960..1f5d393f 100644 --- a/factory_method.py +++ b/factory_method.py @@ -13,10 +13,7 @@ def __init__(self): def get(self, msgid): """We'll punt if we don't have a translation""" - try: - return self.trans[msgid] - except KeyError: - return str(msgid) + return self.trans.get(msgid, msgid) class EnglishGetter: diff --git a/iterator.py b/iterator.py index 74d67138..ba7180d1 100644 --- a/iterator.py +++ b/iterator.py @@ -12,7 +12,7 @@ def count_to(count): """Counts by word numbers, up to a maximum of five""" numbers = ["one", "two", "three", "four", "five"] # enumerate() returns a tuple containing a count (from start which - # defaults to 0) and the values obtained from iterating over sequence + # defaults to 0) and the values obtained from iterating over sequences for pos, number in zip(range(count), numbers): yield number diff --git a/mediator.py b/mediator.py index 82a2886f..986c7490 100644 --- a/mediator.py +++ b/mediator.py @@ -30,6 +30,7 @@ def tearDown(self): print("Tearing down") time.sleep(0.1) self._tm.publishReport() + print("\n") else: print("Test not executed. No tear down required.") @@ -108,17 +109,21 @@ def setTC(self, tc): reporter = Reporter() db = DB() tm = TestManager() + tm.setReporter(reporter) tm.setDB(db) + reporter.setTM(tm) db.setTM(tm) # For simplification we are looping on the same test. # Practically, it could be about various unique test classes and their # objects - for i in range(3): + for _ in range(3): tc = TC() tc.setTM(tm) + tm.setTC(tc) + tc.setup() tc.execute() tc.tearDown() diff --git a/observer.py b/observer.py index 4ce1aed6..d0bd573d 100644 --- a/observer.py +++ b/observer.py @@ -67,7 +67,6 @@ def main(): data1.attach(view2) data2.attach(view2) data2.attach(view1) - print("Setting Data 1 = 10") data1.data = 10 print("Setting Data 2 = 15") diff --git a/singleton.py b/singleton.py new file mode 100644 index 00000000..753bc427 --- /dev/null +++ b/singleton.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +class Hello(object): + singleton = None + + def __new__(clz): + if not clz.singleton: + clz.singleton = super(Hello, clz).__new__(clz) + return clz.singleton + + def __init__(self): + self.world = "world" + return None + +h = Hello() +h.hello = "hello" + +print h.hello +print h +print h.world + +x = Hello() + +print x.hello +print x +print x.world \ No newline at end of file