Best Python code snippet using molotov_python
jpb_observer_old.py
Source:jpb_observer_old.py
1# -*- coding: utf-8 -*-2#3# File: jpb_observer_old.py4# Author: Juan Pedro BolÃvar Puente <raskolnikov@es.gnu.org>5# Date: 20096# Time-stamp: <2012-01-20 20:57:32 jbo>7#8#9# Copyright (C) 2012 Juan Pedro BolÃvar Puente10#11# This file is part of jpblib.12#13# jpblib is free software: you can redistribute it and/or14# modify it under the terms of the GNU General Public License as15# published by the Free Software Foundation, either version 3 of the16# License, or (at your option) any later version.17#18# jpblib is distributed in the hope that it will be useful,19# but WITHOUT ANY WARRANTY; without even the implied warranty of20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the21# GNU General Public License for more details.22#23# You should have received a copy of the GNU General Public License24# along with this program. If not, see <http://www.gnu.org/licenses/>.25#26import unittest27from jpb.observer_old import *28TEST_SIGNALS = ["sig_one", "sig_two", "sig_three"]29class SubjectTester: pass30class ListenerTester: pass31subject (SubjectTester, TEST_SIGNALS)32listener (ListenerTester, TEST_SIGNALS, "ok")33CleverSubjectTester, CleverListenerTester = make_clever_observer (34 TEST_SIGNALS, defret = "ok")35class LightSubjectTester: pass36class LightListenerTester: pass37light_observer (LightSubjectTester, LightListenerTester, TEST_SIGNALS)38class TestListenerOld (unittest.TestCase):39 KLASS = ListenerTester40 def setUp (self):41 self.listener = self.KLASS ()42 def tearDown (self):43 del self.listener44 def test_listener_methods (self):45 self.assertEqual (hasattr (self.listener, 'handle_sig_one'), True)46 self.assertEqual (hasattr (self.listener, 'handle_sig_two'), True)47 self.assertEqual (hasattr (self.listener, 'handle_sig_three'), True)48 def test_listener_returns (self):49 self.assertEqual (self.listener.handle_sig_one (), "ok")50 self.assertEqual (self.listener.handle_sig_two (), "ok")51 self.assertEqual (self.listener.handle_sig_three (), "ok")52class TestSubjectOld (unittest.TestCase):53 KLASS = SubjectTester54 def setUp (self):55 self.observer = self.KLASS ()56 def tearDown (self):57 del self.observer58 def test_observer_signals (self):59 self.assertEqual (hasattr (self.observer, 'on_sig_one'), True)60 self.assertEqual (hasattr (self.observer, 'on_sig_two'), True)61 self.assertEqual (hasattr (self.observer, 'on_sig_three'), True)62 self.assertEqual (hasattr (self.observer, 'add_listener'), True)63 self.assertEqual (hasattr (self.observer, 'del_listener'), True)64 self.assertEqual (hasattr (self.observer, 'clear'), True)65class TestCleverListenerOld (TestListenerOld):66 KLASS = CleverListenerTester67class TestCleverSubjectOld (TestSubjectOld):68 KLASS = CleverSubjectTester69class TestObserverOld (unittest.TestCase):70 LISTENER_KLASS = ListenerTester71 SUBJECT_KLASS = SubjectTester72 class Counter:73 def __init__ (self, val = 0):74 self.val = 075 def increase (self):76 self.val += 177 def decrease (self):78 self.val -= 179 def setUp (self):80 self.lst = self.LISTENER_KLASS ()81 self.sub = self.SUBJECT_KLASS ()82 def tearDown (self):83 del self.sub84 del self.lst85 def test_add_listener (self):86 self.sub.add_listener (self.lst)87 self.assertEqual (self.sub.on_sig_one.count, 1)88 self.assertEqual (self.sub.on_sig_two.count, 1)89 self.assertEqual (self.sub.on_sig_three.count, 1)90 def test_del_listener (self):91 self.test_add_listener ()92 self.sub.del_listener (self.lst)93 self.assertEqual (self.sub.on_sig_one.count, 0)94 self.assertEqual (self.sub.on_sig_two.count, 0)95 self.assertEqual (self.sub.on_sig_three.count, 0)96class TestCleverObserverOld (TestObserverOld):97 LISTENER_KLASS = CleverListenerTester98 SUBJECT_KLASS = CleverSubjectTester99 def test_disconnect_all (self):100 self.sub.add_listener (self.lst)101 self.lst.disconnect ()102 self.assertEqual (self.sub.on_sig_one.count, 0)103 self.assertEqual (self.sub.on_sig_two.count, 0)104 self.assertEqual (self.sub.on_sig_three.count, 0)105class TestLightObserverOld (TestObserverOld):106 class Counter (LightListenerTester):107 def __init__ (self):108 self.value = 0109 def handle_sig_one (self):110 self.value += 1111 def handle_sig_two (self):112 self.value -= 1113 LISTENER_KLASS = Counter114 SUBJECT_KLASS = LightSubjectTester115 def test_add_listener (self):116 self.sub.add_listener (self.lst)117 self.assertEqual (len (self.sub._listeners), 1)118 def test_del_listener (self):119 self.test_add_listener ()120 self.sub.del_listener (self.lst)121 self.assertEqual (len (self.sub._listeners), 0)122 def test_signaling (self):123 self.test_add_listener ()124 self.sub.on_sig_one ()125 self.assertEqual (self.lst.value, 1)126 self.sub.on_sig_two ()...
base_observer_old.py
Source:base_observer_old.py
1#2# Copyright (C) 2009 Juan Pedro Bolivar Puente, Alberto Villegas Erce3# 4# This file is part of Pidgeoncide.5#6# Pidgeoncide is free software: you can redistribute it and/or7# modify it under the terms of the GNU General Public License as8# published by the Free Software Foundation, either version 3 of the9# License, or (at your option) any later version.10# 11# Pidgeoncide is distributed in the hope that it will be useful,12# but WITHOUT ANY WARRANTY; without even the implied warranty of13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14# GNU General Public License for more details.15# 16# You should have received a copy of the GNU General Public License17# along with this program. If not, see <http://www.gnu.org/licenses/>.18#19import unittest20from base.observer_old import *21TEST_SIGNALS = ["sig_one", "sig_two", "sig_three"]22class SubjectTester: pass23class ListenerTester: pass24subject (SubjectTester, TEST_SIGNALS)25listener (ListenerTester, TEST_SIGNALS, "ok")26CleverSubjectTester, CleverListenerTester = make_clever_observer (27 TEST_SIGNALS, defret = "ok")28class LightSubjectTester: pass29class LightListenerTester: pass30light_observer (LightSubjectTester, LightListenerTester, TEST_SIGNALS)31class TestListenerOld (unittest.TestCase):32 KLASS = ListenerTester33 def setUp (self):34 self.listener = self.KLASS ()35 def tearDown (self):36 del self.listener37 38 def test_listener_methods (self):39 self.assertEqual (hasattr (self.listener, 'handle_sig_one'), True)40 self.assertEqual (hasattr (self.listener, 'handle_sig_two'), True)41 self.assertEqual (hasattr (self.listener, 'handle_sig_three'), True)42 def test_listener_returns (self):43 self.assertEqual (self.listener.handle_sig_one (), "ok")44 self.assertEqual (self.listener.handle_sig_two (), "ok")45 self.assertEqual (self.listener.handle_sig_three (), "ok")46class TestSubjectOld (unittest.TestCase):47 KLASS = SubjectTester48 49 def setUp (self):50 self.observer = self.KLASS ()51 def tearDown (self):52 del self.observer53 def test_observer_signals (self):54 self.assertEqual (hasattr (self.observer, 'on_sig_one'), True)55 self.assertEqual (hasattr (self.observer, 'on_sig_two'), True)56 self.assertEqual (hasattr (self.observer, 'on_sig_three'), True)57 self.assertEqual (hasattr (self.observer, 'add_listener'), True)58 self.assertEqual (hasattr (self.observer, 'del_listener'), True)59 self.assertEqual (hasattr (self.observer, 'clear'), True)60class TestCleverListenerOld (TestListenerOld):61 62 KLASS = CleverListenerTester63class TestCleverSubjectOld (TestSubjectOld):64 65 KLASS = CleverSubjectTester66class TestObserverOld (unittest.TestCase):67 LISTENER_KLASS = ListenerTester68 SUBJECT_KLASS = SubjectTester69 70 class Counter:71 def __init__ (self, val = 0):72 self.val = 073 def increase (self):74 self.val += 175 def decrease (self):76 self.val -= 177 78 def setUp (self):79 self.lst = self.LISTENER_KLASS ()80 self.sub = self.SUBJECT_KLASS ()81 def tearDown (self):82 del self.sub83 del self.lst84 def test_add_listener (self):85 self.sub.add_listener (self.lst)86 self.assertEqual (self.sub.on_sig_one.count, 1)87 self.assertEqual (self.sub.on_sig_two.count, 1)88 self.assertEqual (self.sub.on_sig_three.count, 1)89 def test_del_listener (self):90 self.test_add_listener ()91 self.sub.del_listener (self.lst)92 self.assertEqual (self.sub.on_sig_one.count, 0)93 self.assertEqual (self.sub.on_sig_two.count, 0)94 self.assertEqual (self.sub.on_sig_three.count, 0)95class TestCleverObserverOld (TestObserverOld):96 LISTENER_KLASS = CleverListenerTester97 SUBJECT_KLASS = CleverSubjectTester98 def test_disconnect_all (self):99 self.sub.add_listener (self.lst)100 self.lst.disconnect ()101 self.assertEqual (self.sub.on_sig_one.count, 0)102 self.assertEqual (self.sub.on_sig_two.count, 0)103 self.assertEqual (self.sub.on_sig_three.count, 0)104class TestLightObserverOld (TestObserverOld):105 class Counter (LightListenerTester):106 def __init__ (self):107 self.value = 0108 109 def handle_sig_one (self):110 self.value += 1111 def handle_sig_two (self):112 self.value -= 1113 114 LISTENER_KLASS = Counter115 SUBJECT_KLASS = LightSubjectTester116 117 def test_add_listener (self):118 self.sub.add_listener (self.lst)119 self.assertEqual (len (self.sub._listeners), 1)120 121 def test_del_listener (self):122 self.test_add_listener ()123 self.sub.del_listener (self.lst)124 self.assertEqual (len (self.sub._listeners), 0)125 def test_signaling (self):126 self.test_add_listener ()127 self.sub.on_sig_one ()128 self.assertEqual (self.lst.value, 1)129 self.sub.on_sig_two ()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!