Merge pull request #5 from racker/add_basic_tests
Add tests for event emitter class
This commit is contained in:
2 changed files with 106 additions and 0 deletions
3
teeth_agent/tests/__init__.py
Normal file
3
teeth_agent/tests/__init__.py
Normal file
@@ -0,0 +1,3 @@
"""
Unit Tests for the Teeth Agent.
"""
103
teeth_agent/tests/test_events.py
Normal file
103
teeth_agent/tests/test_events.py
Normal file
@@ -0,0 +1,103 @@
"""
Copyright 2013 Rackspace, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from twisted.trial import unittest
from teeth_agent.events import EventEmitter, EventEmitterUnhandledError
class EventEmitterTest(unittest.TestCase):
"""Event Emitter tests."""
def setUp(self):
self.ee = EventEmitter()
def tearDown(self):
del self.ee
def test_empty_emit(self):
self.ee.emit("nothing.here", "some args")
self.ee.emit("nothing.here2")
def test_single_event(self):
self.count = 0
def got_it(topic):
self.assertEqual(topic, "test")
self.count += 1
self.ee.on("test", got_it)
self.ee.emit("test")
self.ee.emit("other_test")
self.assertEqual(self.count, 1)
def test_multicb(self):
self.count = 0
def got_it(topic):
self.assertEqual(topic, "test")
self.count += 1
self.ee.on("test", got_it)
self.ee.on("test", got_it)
self.ee.emit("test")
self.assertEqual(self.count, 2)
def test_once(self):
self.count = 0
def got_it(topic):
self.assertEqual(topic, "test")
self.count += 1
self.ee.once("test", got_it)
self.ee.emit("test")
self.ee.emit("test")
self.assertEqual(self.count, 1)
def test_removeAllListeners(self):
self.count = 0
def got_it(topic):
self.assertEqual(topic, "test")
self.count += 1
self.ee.on("test", got_it)
self.ee.emit("test")
self.ee.removeAllListeners("test")
self.ee.emit("test")
self.assertEqual(self.count, 1)
def test_error(self):
self.count = 0
try:
self.ee.emit("error")
except EventEmitterUnhandledError:
self.count += 1
self.assertEqual(self.count, 1)
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.