def test_component_handling():
    baseitem = DirectGuiBase()
    testoptiondefs = (('test-1', 0, None), )
    baseitem.defineoptions({}, testoptiondefs)

    assert len(baseitem.components()) == 0

    baseitem.createcomponent(
        'componentName',  # componentName
        (),  # componentAliases
        'componentGroup',  # componentGroup
        OnscreenText,  # widgetClass
        (),  # *widgetArgs
        text='Test',  # **kw
        parent=core.NodePath())

    # check if we have exactly one component now
    assert len(baseitem.components()) == 1
    # check if we have a component named like the one we just created
    assert baseitem.hascomponent('componentName')

    # get our new component
    component = baseitem.component('componentName')
    # check some of its values
    assert component.text == 'Test'

    # destroy our recently created component
    baseitem.destroycomponent('componentName')
    # check if it really is gone
    assert baseitem.hascomponent('componentName') == False
def test_options():
    baseitem = DirectGuiBase()
    testoptiondefs = (
        ('test-1', 0, DGG.INITOPT),
        ('test-2', 0, None),
    )
    baseitem.defineoptions({}, testoptiondefs)
    assert len(baseitem.options()) == 2
def test_destroy():
    baseitem = DirectGuiBase()
    testoptiondefs = (('test-1', 0, None), )
    baseitem.defineoptions({}, testoptiondefs)
    baseitem.destroy()
    # check if things got correctly removed
    assert not hasattr(baseitem, '_optionInfo')
    assert not hasattr(baseitem, '__componentInfo')
    assert not hasattr(baseitem, 'postInitialiseFuncList')
def test_get_options():
    baseitem = DirectGuiBase()
    testoptiondefs = (('test-1', 0, None), )
    baseitem.defineoptions({}, testoptiondefs)

    # Using the configure function
    # check if configuration have been set correctly
    assert baseitem.configure() == {
        'test-1': ('test-1', 0, 0),
    }
    # check for specific configurations
    assert baseitem.configure('test-1') == ('test-1', 0, 0)

    # using index style references __getItem__ and cget
    assert baseitem['test-1'] == 0
    assert baseitem.cget('test-1') == 0
def test_set_options():
    baseitem = DirectGuiBase()

    testoptiondefs = (('test-1', 0, DGG.INITOPT), ('test-2', 0, None))
    baseitem.defineoptions({}, testoptiondefs)

    # try to set a value of an initopt option (shouldn't be possible)
    baseitem.configure('test-1', **{'test-1': 1})
    # check it's value. It shouldn't have changed
    assert baseitem['test-1'] == 0

    baseitem['test-1'] = 1
    # check it's value. It shouldn't have changed
    assert baseitem['test-1'] == 0

    # try changing using the configure function. As test-2 isn't an
    # initopt option, this should work fine
    baseitem.configure('test-2', **{'test-2': 2})
    # check it's value. It should be 2 now
    assert baseitem['test-2'] == 2

    # try changing using index style referencing
    baseitem['test-2'] = 1
    assert baseitem['test-2'] == 1
def test_isinitoption():
    baseitem = DirectGuiBase()
    testoptiondefs = (('test-true', 0, DGG.INITOPT), ('test-false', 0, None))
    baseitem.defineoptions({}, testoptiondefs)
    assert baseitem.isinitoption('test-true') == True
    assert baseitem.isinitoption('test-false') == False
def test_defineoptions():
    baseitem = DirectGuiBase()
    testoptiondefs = (('test', 0, None), )
    baseitem.defineoptions({}, testoptiondefs)
    assert baseitem['test'] == 0