Example #1
0
def test_CreateRoot():
    #
    # Test create and then modify state of a topic object
    #

    nameTuple = ('root',)
    description = 'root description'
    msgArgsInfo = None

    # when parent is None, only nameTuple=ALL_TOPICS is allowed, thereby
    # guaranteeing that only one tree root can be created
    pytest.raises(ValueError, Topic, treeConfig, nameTuple, description, msgArgsInfo)

    # create the ALL TOPICS topic; it has no message args
    nameTuple = (ALL_TOPICS,)
    argSpec = ArgSpecGiven( dict() )
    msgArgsInfo = ArgsInfo(nameTuple, argSpec, None)
    obj = Topic(treeConfig, nameTuple, description, msgArgsInfo)

    # verify its state is as expected after creation:
    assert obj.getListeners() == []
    assert obj.getNumListeners() == 0
    assert obj.hasListeners() == False

    def listener1(): pass
    def listener2(): pass
    def badListener1(arg1): pass # extra required arg
    def listener3(arg1=None): pass # extra is optional
    assert obj.isValid(listener1)
    assert not obj.isValid(badListener1)
    assert obj.isValid(listener3)

    global rootTopic
    rootTopic = obj
Example #2
0
def test0_CreateRoot():
    #
    # Test create and then modify state of a topic object
    #

    nameTuple = ('root', )
    description = 'root description'
    msgArgsInfo = None

    # when parent is None, only nameTuple=ALL_TOPICS is allowed, thereby
    # guaranteeing that only one tree root can be created
    pytest.raises(ValueError, Topic, treeConfig, nameTuple, description,
                  msgArgsInfo)

    # create the ALL TOPICS topic; it has no message args
    nameTuple = (ALL_TOPICS, )
    argSpec = ArgSpecGiven(dict())
    msgArgsInfo = ArgsInfo(nameTuple, argSpec, None)
    obj = Topic(treeConfig, nameTuple, description, msgArgsInfo)

    # verify its state is as expected after creation:
    assert obj.getListeners() == []
    assert obj.getNumListeners() == 0
    assert obj.hasListeners() == False

    def listener1():
        pass

    def listener2():
        pass

    def badListener1(arg1):
        pass  # extra required arg

    def listener3(arg1=None):
        pass  # extra is optional

    assert obj.isValid(listener1)
    assert not obj.isValid(badListener1)
    assert obj.isValid(listener3)

    global rootTopic
    rootTopic = obj