本文整理汇总了Python中EventHandlers.tests.TestEventLogger类的典型用法代码示例。如果您正苦于以下问题:Python TestEventLogger类的具体用法?Python TestEventLogger怎么用?Python TestEventLogger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestEventLogger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testWebbrickStatusQuery
def testWebbrickStatusQuery(self):
self._log.debug( "\n\ntestWebbrickStatusQuery" )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigWebbrickStatusQuery) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
self.router.publish( EventAgent("TestWebbrickStatusMonitor"), Events.evtSecond5 ) # so webbrick is in list for recover
self.router.publish( EventAgent("TestWebbrickStatusMonitor"), Events.evtMinute1 ) # do recover
waitNSeconds(2) # recover is async
self.router.publish( EventAgent("TestWebbrickStatusMonitor"), Events.evtSecond5 ) # do scan
waitNSeconds(2) # scan is async
# We should see lots of events here as initial pass.
# my test rig only has 1 temp sensors.
# so:
# 1 temp sensors
# 4 analogue in
# 4 analogue out
# 12 digital in
# 8 digital out
# 8 mimic out
self.assert_( TestEventLogger.expectAtLeastNevents(36+NUM_TEMP_SENSORS), "expecting %u events" % (36+NUM_TEMP_SENSORS) )
oldLen = len(TestEventLogger._events)
self.router.publish( EventAgent("TestWebbrickStatusMonitor"), Events.evtSecond5 ) # do scan
waitNSeconds(2) # scan is async
TestEventLogger.logEvents()
self.assert_( oldLen <= len(TestEventLogger._events) )
示例2: testSend
def testSend(self):
self._log.debug( "\ntestListen" )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigAsteriskSend) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
skt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
skt.connect(("localhost", 20998))
skt.send( " agi_request: dialparties.agi\n" )
skt.send( " agi_channel: SIP/100-b7a017f8\n" )
skt.send( " agi_language: en\n" )
skt.send( " agi_type: SIP\n" )
skt.send( " agi_uniqueid: 1173178145.6\n" )
skt.send( " agi_callerid: 100\n" )
skt.send( " agi_calleridname: SNOM\n" )
skt.send( " agi_callingpres: 0\n" )
skt.send( " agi_callingani2: 0\n" )
skt.send( " agi_callington: 0\n" )
skt.send( " agi_callingtns: 0\n" )
skt.send( " agi_dnid: 200\n" )
skt.send( " agi_rdnis: unknown\n" )
skt.send( " agi_context: macro-dial\n" )
skt.send( " agi_extension: s\n" )
skt.send( " agi_priority: 1\n" )
skt.send( " agi_enhanced: 0.0\n" )
skt.send( " agi_accountcode:\n" )
skt.send( "\n" )
skt.close()
time.sleep(2)
TestEventLogger.logEvents()
self.assert_( len(TestEventLogger._events) >= 1)
示例3: testDeltaTime2
def testDeltaTime2(self):
"""
Test the delta time event generator.
"""
self._log.debug( "\n\ntestDeltaTime2" )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigDeltaTime2) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
self.router.publish( EventAgent("TestDelayedEvent"), Events.evtTD0 ) # TD0 0 Off
# time events are not in the log.
TestEventLogger.logEvents()
self.assertEqual( len(TestEventLogger._events), 2)
self.assertEqual( TestEventLogger._events[0].getType(), "http://id.webbrick.co.uk/events/webbrick/TD" )
self.assertEqual( TestEventLogger._events[1].getType(), "http://id.webbrick.co.uk/events/time/delta" )
self.router.publish( EventAgent("TestDelayedEvent"), Events.evtMinute ) # minute
self.router.publish( EventAgent("TestDelayedEvent"), Events.evtMinute ) # minute
# delayed event should now be here.
self.assertEqual( len(TestEventLogger._events), 4)
self.assertEqual( TestEventLogger._events[2].getType(), "delta/delay" )
self.assertEqual( TestEventLogger._events[2].getSource(), "delta/delay1" )
self.assertEqual( TestEventLogger._events[3].getType(), "delta/delay" )
self.assertEqual( TestEventLogger._events[3].getSource(), "delta/delay2" )
示例4: testFloatCounterSet
def testFloatCounterSet(self):
"""
Set Counter to a fixed value
"""
_log.debug( "\ntestFloatCounterSet" )
self.loader = EventRouterLoader()
errCount = self.loader.loadHandlers( getDictFromXmlString(testConfigFloatCounterSet) )
self.assertEqual( errCount, 0)
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
self.router.publish( EventAgent("testCounters"), makeEvent( 'test/event', 'set/counter', { 'val':'300.45' } ) )
TestEventLogger.logEvents()
expectedEvents = {
"test/event" :
[
("set/counter" , 'val', 300.45)
],
"test/1" :
[ ("test/entryCount",'val', 300.45)
]
}
Utils.expectNevents(self, 2)
haveErr, excessEvents = Utils.verifyEvents2( expectedEvents, TestEventLogger._events )
_log.debug( "Excess Events %s " % (excessEvents) )
self.assertEqual( haveErr, False, "Incorrect event set" )
示例5: testTimeEvent4
def testTimeEvent4(self):
"""
Run test with time interval in seconds.
"""
self._log.debug( "\n\ntestTimeEvent4" )
loader = EventRouterLoader()
loader.loadHandlers( getDictFromXmlString(testConfigTime4) )
loader.start() # all tasks
self._router = loader.getEventRouter()
self.waitNEvents( 1 )
TestEventLogger.logEvents()
# first event should be isDark
self.assert_( len(TestEventLogger._events) > 0)
self.assertEqual( TestEventLogger._events[0].getType(), u'http://id.webbrick.co.uk/events/time/isDark' )
self.assertEqual( TestEventLogger._events[0].getSource(), "time/isDark" )
self.waitNEvents( 5 )
TestEventLogger.logEvents()
self.assert_( len(TestEventLogger._events) > 4)
evt = TestEventLogger._events[1]
od = evt.getPayload()
self.assertEqual( len(od["timestr"]),8 )
self.assertEqual( len(od["datestr"]),10 )
self.assertEqual( len(od["datetimestr"]),19 )
loader.stop() # all tasks
self.dumpEvents = False
示例6: testHttpAction2RequestsSpaced
def testHttpAction2RequestsSpaced(self):
self._log.debug( "\ntestHttpAction2RequestsSpaced" )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigHttpAction) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
time.sleep(1)
self.router.publish( EventAgent("TestHttpAction"), Events.evtTD0 ) # 0 Off
maxTime = 10
while (len(self.httpServer.requests()) < 1) and (maxTime > 0):
maxTime -= 1
time.sleep(1)
self.router.publish( EventAgent("TestHttpAction"), Events.evtTD0 ) # 0 Off
maxTime = 10
while (len(self.httpServer.requests()) < 2) and (maxTime > 0):
maxTime -= 1
time.sleep(1)
TestEventLogger.logEvents()
# now look for correct url requests
self._log.debug( "testHttpAction %s", self.httpServer.requests() )
self.assertEqual( len(self.httpServer.requests()), 2)
self.assertEqual( self.httpServer.requests()[0], "/test?medianame=ITunes&mediacmd=volup" )
self.assertEqual( self.httpServer.requests()[1], "/test?medianame=ITunes&mediacmd=volup" )
示例7: testTimeEvent2
def testTimeEvent2(self):
"""
Run test with time interval in seconds.
"""
self._log.debug( "\ntestTimeEvent2" )
loader = EventRouterLoader()
loader.loadHandlers( getDictFromXmlString(testConfigTime2) )
loader.start() # all tasks
self.waitNEvents( 5, 70 )
# now look for correct url requests
TestEventLogger.logEvents()
self.assertEqual( len(TestEventLogger._events), 5)
# the requests could be in either order.
seenOne = 0
seenTwo = 0
for evnt in TestEventLogger._events:
if ( evnt.getSource() == "local/BoilerOn" ):
seenOne += 1
elif ( evnt.getSource() == "local/HwOn" ):
seenTwo += 1
else:
pass # error
self.assertEqual( seenOne, 1 )
self.assertEqual( seenTwo, 4 )
loader.stop() # all tasks
self.dumpEvents = False
示例8: testIntCounterDec2Reset
def testIntCounterDec2Reset(self):
_log.debug( "\ntestIntCounterDec2Reset" )
self.loader = EventRouterLoader()
errCount = self.loader.loadHandlers( getDictFromXmlString(testConfigDecrement2Reset) )
self.assertEqual( errCount, 0)
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
self.router.publish( EventAgent("testCounters"), Events.evtTD0 )
self.router.publish( EventAgent("testCounters"), Events.evtTD0 )
self.router.publish( EventAgent("testCounters"), Events.evtHour03 )
TestEventLogger.logEvents()
expectedEvents = {
"http://id.webbrick.co.uk/events/webbrick/TD" :
[
("webbrick/100/TD/0" , None, None),
("webbrick/100/TD/0" , None, None)
],
"http://id.webbrick.co.uk/events/time/hour" :
[ ("time/hour",None, None)
],
"test/entryCount" :
[ ("test/entryCount",'val', 98)
, ("test/entryCountTotal",'val', 100)
],
}
Utils.expectNevents(self, 5)
haveErr, excessEvents = Utils.verifyEvents2( expectedEvents, TestEventLogger._events )
_log.debug( "Excess Events %s " % (excessEvents) )
self.assertEqual( haveErr, False, "Incorrect event set" )
示例9: testOnkyo
def testOnkyo(self):
self._log.debug( "\ntestOnkyo" )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigOnkyo) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
self.router.publish( EventAgent("testVolume"), evtOnkyoVolume0 )
# time events are not in the log.
self.assert_(TestEventLogger.expectNevents(2))
self.assertEqual( TestEventLogger._events[0].getSource(), "webbrick/1/100" )
evt = TestEventLogger._events[1]
self.assertEqual( evt.getType(), "avamplifier/volume/current" )
self.assertEqual( evt.getSource(), "avamplifier/1/volume/main/current" )
evtod = evt.getPayload()
self.assert_( evtod.has_key("val") )
self.assertEqual( evtod["val"], 0 )
self.router.publish( EventAgent("testVolume"), evtOnkyoVolume50 )
self.assert_(TestEventLogger.expectNevents(4))
self.router.publish( EventAgent("testVolume"), evtOnkyoVolume100 )
self.assert_(TestEventLogger.expectNevents(6))
TestEventLogger.logEvents()
示例10: testCompoundNewState
def testCompoundNewState(self):
self._log.debug( "\ntestCompoundNewState" )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigCompoundEventNewState) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
# initial state is all things off.
self.router.publish( EventAgent("TestCompound"), Events.evtMinute1 )
TestEventLogger.logEvents()
self.expectNevents( 1 )
self.router.publish( EventAgent("TestCompound"), Events.evtMinute2 )
self.expectNevents( 3 )
self.assertEqual( TestEventLogger._events[2].getType(), u'internal' )
self.assertEqual( TestEventLogger._events[2].getSource(), "testState" )
od = TestEventLogger._events[2].getPayload()
self.assertEqual( od["idx"], '1' )
self.router.publish( EventAgent("TestCompound"), Events.evtMinute3 )
self.expectNevents( 4 )
self.router.publish( EventAgent("TestCompound"), Events.evtMinute4 )
self.expectNevents( 6 )
self.assertEqual( TestEventLogger._events[5].getType(), u'internal' )
self.assertEqual( TestEventLogger._events[5].getSource(), "testState" )
od = TestEventLogger._events[5].getPayload()
self.assertEqual( od["idx"], 3 ) # previous minute
示例11: testTestEventLogger
def testTestEventLogger(self):
"""
Test loading the test event logger
"""
_log.debug( "\ntestTestEventLogger" )
self._loader = EventRouterLoader()
self._loader.loadHandlers( getDictFromXmlString(testConfigTestEventLogger) )
self._loader.start() # all tasks
self._router = self._loader.getEventRouter()
self._router.publish( EventAgent("TestEventRouterLoad"), Events.evtTD0 )
self._router.publish( EventAgent("TestEventRouterLoad"), Events.evtTD1 )
if len(TestEventLogger._events) < 2 :
time.sleep(1) # allow threading to catch up.
# now look for correct events requests
TestEventLogger.logEvents()
self.assertEqual( len(TestEventLogger._events), 2)
self.assertEqual( TestEventLogger._events[0].getType(), "http://id.webbrick.co.uk/events/webbrick/TD" )
self.assertEqual( TestEventLogger._events[0].getSource(), "webbrick/100/TD/0" )
self.assertEqual( TestEventLogger._events[1].getType(), "http://id.webbrick.co.uk/events/webbrick/TD" )
self.assertEqual( TestEventLogger._events[1].getSource(), "webbrick/100/TD/1" )
示例12: testSetDOOff
def testSetDOOff(self):
self._log.debug( "\n\ntestSetDOOff" )
self.timeout = time.time() + 5
do = DigitalOutput('do/type','do/source',self.router,'10.100.100.100','2')
do.turnOff()
time.sleep(0.2)
TestEventLogger.logEvents()
assert TestEventLogger._events[0].getType() == 'do/type'
assert TestEventLogger._events[0].getSource() == 'do/source/off'
示例13: testSetDODwellFinish
def testSetDODwellFinish(self):
self._log.debug( "\n\ntestSetDOOn" )
self.timeout = time.time() + 15
do = DigitalOutput('do/type','do/source',self.router,'10.100.100.100','2')
do.turnOn()
#let eventrouter catch up
time.sleep(0.2)
TestEventLogger.logEvents()
assert TestEventLogger._events[0].getType() == 'do/type'
assert TestEventLogger._events[0].getSource() == 'do/source/on'
示例14: expectNevents
def expectNevents(self, cnt):
idx = 2000
while (len(TestEventLogger._events) < cnt) and (idx > 0):
time.sleep(0.05)
idx = idx - 1
if len(TestEventLogger._events) != cnt:
TestEventLogger.logEvents()
self.assertEqual(len(TestEventLogger._events), cnt)
示例15: testSetDOOnDwell
def testSetDOOnDwell(self):
self._log.debug( "\n\ntestSetDOOn" )
self.timeout = time.time() + 15
do = DigitalOutput('do/type','do/source',self.router,'10.100.100.100','2')
do.turnOn(100)
#let eventrouter catch up
time.sleep(0.2)
assert TestEventLogger._events[0].getType() == 'do/type'
assert TestEventLogger._events[0].getSource() == 'do/source/dwell'
assert TestEventLogger._events[0].getPayload()['val'] == '100'
TestEventLogger.logEvents()