def test(): """ Verify access to the channel metadata """ # access from journal import libjournal # make a channel channel = libjournal.Error("test.channel") # get its metadata notes = channel.notes # adjust the application name notes["application"] = "error_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"] == "error_notes" assert notes["author"] == "michael" assert notes["channel"] == "test.channel" assert notes["severity"] == "error" # all done return
def test(): """ Verify access to the channel properties """ # access from journal import libjournal # make a channel channel = libjournal.Error("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 detail is at 1 by default assert channel.detail == 1 # that it can be modified channel.detail = 5 # and the assignment sticks assert channel.detail == 5 # verify its activation state is on 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 fatal assert channel.fatal is True # that it can be modified channel.fatal = False # and the assignment sticks assert channel.fatal is False # 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
def test(): """ Verify that channels with the same name have common state """ # access from journal import libjournal # make a channel ch_1 = libjournal.Error("test.channel") # deactivate it ch_1.active = False # and make it non-fatal ch_1.fatal = False # make another ch_2 = libjournal.Error("test.channel") # verify it is inactive assert ch_2.active is False # and non-fatal assert ch_2.fatal is False # activate it ch_2.active = True # and make it fatal ch_2.fatal = True # 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 fatal assert ch_1.fatal is True assert ch_2.fatal is True # all done return
def test(): """ Verify that the error channel wide defaults are as expected """ # access from journal import libjournal # verify that error channels are active by default assert libjournal.Error.defaultActive is True # and fatal assert libjournal.Error.defaultFatal is True # verify that the channel default device is not set assert libjournal.Error.defaultDevice == None # make a trash can trash = libjournal.Trash() # make it the default device libjournal.Error.defaultDevice = trash # and make sure the assignment sticks assert libjournal.Error.defaultDevice is trash # make a channel channel = libjournal.Error("test.channel") # verify that its view of its default state is consistent assert channel.defaultActive == libjournal.Error.defaultActive assert channel.defaultFatal == libjournal.Error.defaultFatal # similarly for the default device assert channel.defaultDevice == libjournal.Error.defaultDevice # and now, the instance state assert channel.active == channel.defaultActive assert channel.fatal == channel.defaultFatal assert channel.device == channel.defaultDevice # all done return