How to use test_add_listener method in Molotov

Best Python code snippet using molotov_python

jpb_observer_old.py

Source: jpb_observer_old.py Github

copy

Full Screen

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 ()...

Full Screen

Full Screen

base_observer_old.py

Source: base_observer_old.py Github

copy

Full Screen

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 ()...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

How To Run Cypress Tests In Azure DevOps Pipeline

When software developers took years to create and introduce new products to the market is long gone. Users (or consumers) today are more eager to use their favorite applications with the latest bells and whistles. However, users today don’t have the patience to work around bugs, errors, and design flaws. People have less self-control, and if your product or application doesn’t make life easier for users, they’ll leave for a better solution.

How To Use Playwright For Web Scraping with Python

In today’s data-driven world, the ability to access and analyze large amounts of data can give researchers, businesses & organizations a competitive edge. One of the most important & free sources of this data is the Internet, which can be accessed and mined through web scraping.

Guide To Find Index Of Element In List with Python Selenium

In an ideal world, you can test your web application in the same test environment and return the same results every time. The reality can be difficult sometimes when you have flaky tests, which may be due to the complexity of the web elements you are trying to perform an action on your test case.

Rebuild Confidence in Your Test Automation

These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.

How to Position Your Team for Success in Estimation

Estimates are critical if you want to be successful with projects. If you begin with a bad estimating approach, the project will almost certainly fail. To produce a much more promising estimate, direct each estimation-process issue toward a repeatable standard process. A smart approach reduces the degree of uncertainty. When dealing with presales phases, having the most precise estimation findings can assist you to deal with the project plan. This also helps the process to function more successfully, especially when faced with tight schedules and the danger of deviation.

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Molotov automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful