Exemplo n.º 1
0
def test():
    """
    Verify access to the channel metadata
    """
    # access
    from journal import libjournal

    # make a channel
    channel = libjournal.Informational("test.channel")
    # get its metadata
    notes = channel.notes
    # adjust the application name
    notes["application"] = "info_notes"
    # add something
    notes["author"] = "michael"

    # make sure the adjustments stick by getting the value once again
    notes = channel.notes
    # and comparing against expectations
    assert notes["application"] == "info_notes"
    assert notes["author"] == "michael"
    assert notes["channel"] == "test.channel"
    assert notes["severity"] == "info"

    # all done
    return
Exemplo n.º 2
0
def test():
    """
    Verify access to the channel properties
    """
    # access
    from journal import libjournal

    # make a channel
    channel = libjournal.Informational("test.channel")

    # verify its name
    assert channel.name == "test.channel"
    # check that it is read-only
    try:
        # by attempting to modify
        channel.name = "foo"
        # hence, we can't get here
        assert False, "unreachable"
    # if all goes well
    except AttributeError as error:
        # no problem
        pass

    # verify its verbosity is at 1 by default
    assert channel.verbosity == 1
    # that it can be modified
    channel.verbosity = 5
    # and the assignment sticks
    assert channel.verbosity == 5

    # verify its activation state is off by default
    assert channel.active is True
    # that it can be modified
    channel.active = False
    # and the assignment sticks
    assert channel.active is False

    # verify it's not fatal
    assert channel.fatal is False
    # that it can be modified
    channel.fatal = True
    # and the assignment sticks
    assert channel.fatal is True

    # verify that the accessible device is the console
    assert channel.device.name == "cout"
    # make a trash can
    trash = libjournal.Trash()
    # register it as the device
    channel.device = trash
    # and verify that the assignment sticks
    assert channel.device is trash
    # check the name
    assert channel.device.name == "trash"
    # and verify that it's different from the default device held by the class
    assert channel.device is not channel.defaultDevice

    # all done
    return
Exemplo n.º 3
0
def test():
    """
    Verify that channels with the same name have common state
    """
    # access
    from journal import libjournal

    # make a channel
    ch_1 = libjournal.Informational("test.channel")
    # deactivate it
    ch_1.active = False
    # and make it fatal
    ch_1.fatal = True

    # make another
    ch_2 = libjournal.Informational("test.channel")
    # verify it is inactive
    assert ch_2.active is False
    # and fatal
    assert ch_2.fatal is True
    # activate it
    ch_2.active = True
    # and make it non-fatal
    ch_2.fatal = False

    # verify that both channels are now active
    assert ch_1.active is True
    assert ch_2.active is True
    # and once again, using {__bool__}
    assert bool(ch_1) is True
    assert bool(ch_2) is True

    # verify that they are both non-fatal
    assert ch_1.fatal is False
    assert ch_2.fatal is False

    # all done
    return
Exemplo n.º 4
0
def test():
    """
    Verify that the info channel wide defaults are as expected
    """
    # access
    from journal import libjournal

    # verify that info channels are inactive by default
    assert libjournal.Informational.defaultActive is True
    # and non-fatal
    assert libjournal.Informational.defaultFatal is False
    # verify that the channel default device is not set
    assert libjournal.Informational.defaultDevice == None

    # make a trash can
    trash = libjournal.Trash()
    # make it the default device
    libjournal.Informational.defaultDevice = trash
    # and make sure the assignment sticks
    assert libjournal.Informational.defaultDevice is trash

    # make a channel
    channel = libjournal.Informational("test.channel")
    # verify that its view of its default state is consistent
    assert channel.defaultActive == libjournal.Informational.defaultActive
    assert channel.defaultFatal == libjournal.Informational.defaultFatal
    # similarly for the default device
    assert channel.defaultDevice == libjournal.Informational.defaultDevice

    # and now, the instance state
    assert channel.active == channel.defaultActive
    assert channel.fatal == channel.defaultFatal
    assert channel.device == channel.defaultDevice

    # all done
    return