From bd70184b69854759b11fe3cdf2cdb3cf2db77970 Mon Sep 17 00:00:00 2001 From: Maksym Date: Tue, 9 Jun 2015 01:43:43 +0300 Subject: [PATCH 1/3] added singleton --- singleton.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 singleton.py diff --git a/singleton.py b/singleton.py new file mode 100644 index 00000000..21fe4329 --- /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 = object.__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 From 4f045307b69650436a4b70ed4136be4aa08337ab Mon Sep 17 00:00:00 2001 From: Maksym Date: Wed, 10 Jun 2015 00:59:01 +0300 Subject: [PATCH 2/3] syntax fix --- mediator.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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() From aff32e76e894ca9fa1256474d70a3d907dbcbf8d Mon Sep 17 00:00:00 2001 From: Maksym Date: Fri, 17 Jul 2015 21:44:14 +0300 Subject: [PATCH 3/3] few fixes --- factory_method.py | 5 +---- iterator.py | 2 +- observer.py | 1 - singleton.py | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) 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/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 index 21fe4329..753bc427 100644 --- a/singleton.py +++ b/singleton.py @@ -5,7 +5,7 @@ class Hello(object): def __new__(clz): if not clz.singleton: - clz.singleton = object.__new__(clz) + clz.singleton = super(Hello, clz).__new__(clz) return clz.singleton def __init__(self):