当前位置: 首页>>代码示例>>Python>>正文


Python AssimEvent.enable_all_observers方法代码示例

本文整理汇总了Python中assimevent.AssimEvent.enable_all_observers方法的典型用法代码示例。如果您正苦于以下问题:Python AssimEvent.enable_all_observers方法的具体用法?Python AssimEvent.enable_all_observers怎么用?Python AssimEvent.enable_all_observers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在assimevent.AssimEvent的用法示例。


在下文中一共展示了AssimEvent.enable_all_observers方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_simple_init_bad

# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import enable_all_observers [as 别名]
 def test_simple_init_bad(self):
     'Perform a few simple AssimEvent bad initializations'
     AssimEvent.enable_all_observers()
     AssimEvent.observers = []
     observer=DummyObserver()
     badobserver=BadObserver()
     AssimEvent.registerobserver(observer)
     self.assertRaises(ValueError, AssimEvent, 'first', 999)
     self.assertRaises(AttributeError, AssimEvent.registerobserver, badobserver)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:11,代码来源:assimevent_test.py

示例2: test_fork_exec_event

# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import enable_all_observers [as 别名]
    def test_fork_exec_event(self):
        '''This test will create a fork/exec event observer script
        and then test to see if its getting invoked properly...
        '''
        AssimEvent.enable_all_observers()
        tmpdir = tempfile.mkdtemp('.d', 'testexec_')
        (fd, pathname) = tempfile.mkstemp('.out.txt')
        execscript = os.path.join(tmpdir, 'observer.sh')
        makescript(execscript, pathname)
        AssimEvent.observers = []
        observer=ForkExecObserver(scriptdir=tmpdir)
        dummyclient = ClientClass()
        dummyclient.fred='fred'
        dummyclient.sevenofnine='Annika'
        dummyclient.foo = {'foo': 'bar'}

        self.assertEqual(observer.listscripts(), [execscript,])
        AssimEvent.registerobserver(observer)
        AssimEvent(dummyclient, AssimEvent.CREATEOBJ)
        AssimEvent(dummyclient, AssimEvent.OBJUP, extrainfo={'origaddr': '10.10.10.254'})
        os.close(fd)
        expectedcontent=\
'''====START====
ARG1=create
ARG2=ClientClass
ASSIM_fred=fred
ASSIM_nodetype=ClientClass
ASSIM_sevenofnine=Annika
==== JSON START ====
{"associatedobject":{"foo":{"foo":"bar"},"fred":"fred","nodetype":"ClientClass","sevenofnine":"Annika"},"eventtype":0,"extrainfo":null}
==== JSON END ====
====END====
====START====
ARG1=up
ARG2=ClientClass
ASSIM_fred=fred
ASSIM_nodetype=ClientClass
ASSIM_origaddr=10.10.10.254
ASSIM_sevenofnine=Annika
==== JSON START ====
{"associatedobject":{"foo":{"foo":"bar"},"fred":"fred","nodetype":"ClientClass","sevenofnine":"Annika"},"eventtype":1,"extrainfo":{"origaddr":"10.10.10.254"}}
==== JSON END ====
====END====
'''
        TestAssimEvent.waitfor(pathname, expectedcontent)
        f=open(pathname, 'r')
        content=f.read()
        f.close()
        self.assertEqual(content, expectedcontent)
        os.unlink(execscript)
        os.unlink(pathname)
        os.rmdir(tmpdir)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:54,代码来源:assimevent_test.py

示例3: test_fork_exec_killchild

# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import enable_all_observers [as 别名]
    def test_fork_exec_killchild(self):
        '''This test will create a fork/exec event observer script
        and then kill the child listener and verify that it is handled
        correctly.
        '''
        AssimEvent.enable_all_observers()
        tmpdir = tempfile.mkdtemp('.d', 'testexec_')
        (fd, pathname) = tempfile.mkstemp('.out.txt')
        execscript = os.path.join(tmpdir, 'observer.sh')
        makescript(execscript, pathname)
        AssimEvent.observers = []
        observer=ForkExecObserver(scriptdir=tmpdir)
        dummyclient = ClientClass()
        dummyclient.fred='fred'
        dummyclient.sevenofnine='Annika'
        dummyclient.foo = {'foo': 'bar'}
        AssimEvent.registerobserver(observer)
        try:
            os.kill(observer.childpid, signal.SIGKILL)
        except OSError:
            # "docker build" doesn't let us kill processes...
            # so we give up on this test and call it good...
            os.unlink(execscript)
            os.unlink(pathname)
            os.rmdir(tmpdir)
            return
        time.sleep(0.1)
        AssimEvent(dummyclient, AssimEvent.CREATEOBJ)
        # Death of our FIFO child will cause it to get respawned, and
        # message sent to new child.  No messages should be lost.
        expectedcontent=\
'''====START====
ARG1=create
ARG2=ClientClass
ASSIM_fred=fred
ASSIM_nodetype=ClientClass
ASSIM_sevenofnine=Annika
==== JSON START ====
{"associatedobject":{"foo":{"foo":"bar"},"fred":"fred","nodetype":"ClientClass","sevenofnine":"Annika"},"eventtype":0,"extrainfo":null}
==== JSON END ====
====END====
'''
        TestAssimEvent.waitfor(pathname, expectedcontent)
        f=open(pathname, 'r')
        content=f.read()
        f.close()
        self.assertEqual(content, expectedcontent)
        os.close(fd)
        os.unlink(execscript)
        os.unlink(pathname)
        os.rmdir(tmpdir)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:53,代码来源:assimevent_test.py

示例4: test_simple_init_good

# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import enable_all_observers [as 别名]
 def test_simple_init_good(self):
     'Perform a few simple AssimEvent good initializations'
     AssimEvent.enable_all_observers()
     AssimEvent.observers = []
     observer=DummyObserver()
     AssimEvent.registerobserver(observer)
     event1 = AssimEvent('first', AssimEvent.CREATEOBJ)
     self.assertEqual(len(observer.events), 1)
     self.assertTrue(observer.events[0], event1)
     self.assertEqual(AssimEvent.unregisterobserver(observer), True)
     event2 = AssimEvent('second', AssimEvent.CREATEOBJ)
     self.assertEqual(len(observer.events), 1)
     self.assertTrue(observer.events[0], event1)
     AssimEvent.registerobserver(observer)
     event3 = AssimEvent('third', AssimEvent.CREATEOBJ)
     self.assertEqual(len(observer.events), 2)
     self.assertTrue(observer.events[0], event3)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:19,代码来源:assimevent_test.py

示例5: makescript

# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import enable_all_observers [as 别名]
# You should have received a copy of the GNU General Public License
# along with the Assimilation Project software.  If not, see http://www.gnu.org/licenses/
#
#
_suites = ['all', 'events']
import sys
sys.path.append("../cma")
sys.path.append("/usr/local/lib/python2.7/dist-packages")
from testify import *
import os, sys, tempfile, time, signal
from assimevent import AssimEvent
from assimeventobserver import ForkExecObserver

DEBUG=False

AssimEvent.enable_all_observers()

def makescript(createdscriptname, outfile):
    'Create the requested script - outputting to requested file'
    script='''#!/bin/sh
    # Simple script to test external event interfaces
    (   echo "====START===="
        j=1
        for arg
        do
            echo "ARG${j}=$arg"
            j=$(expr $j + 1)
        done
        env |  grep '^ASSIM_' | LC_ALL=C sort
        echo "==== JSON START ===="
        cat
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:33,代码来源:assimevent_test.py


注:本文中的assimevent.AssimEvent.enable_all_observers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。