def test(): """ Send all error channel output to a log file """ # get the channel from journal.ext.journal import Error as error # send output to a log file error.logfile("error_file.log") # make a channel channel = error(name="test.journal.error") # add some metadata channel.notes["time"] = "now" # carefully try: # inject channel.line("error:") channel.log(" a nasty bug was detected") # shouldn't get here assert False, "unreachable" # if the correct exception was raised except channel.ApplicationError as error: # check the description assert str(error) == "test.journal.error: application error" # all done return
def test(): """ Verify the channel initial state """ # access from journal.ext.journal import Error as error # make a channel channel = error(name="tests.journal.error") # verify the channel name assert channel.name == "tests.journal.error" # the detail should be at the default level assert channel.detail == 1 # the channel should be active assert channel.active is True # and fatal assert channel.fatal is True # the page should be empty assert tuple(channel.page) == () # verify the metadata assert channel.notes["application"] == "journal" assert channel.notes["channel"] == channel.name assert channel.notes["severity"] == channel.severity # all done return
def test(): """ Exercise a non-fatal error channel with a realistic example """ # get the trash can from journal.ext.journal import Trash as trash # and the channel from journal.ext.journal import Error as error # make an error channel channel = error(name="tests.journal.error") # make it non-fatal channel.fatal = False # send the output to trash channel.device = trash() # add some metadata channel.notes["time"] = "now" # carefully try: # inject channel.line("error channel:") channel.log(" hello world!") # if the correct exception was raised except channel.ApplicationError as error: # shouldn't get here assert False, "unreachable" # all done return
def test(): """ Verify that channel buffers get reset correctly after a flush """ # get the channel from journal.ext.journal import Error as error # and the trash can from journal.ext.journal import Trash as trash # make a channel channel = error(name="test.journal.error") # send the output to trash channel.device = trash() # carefully try: # inject channel.log("hello world!") # shouldn't get here assert False, "unreachable" # if the correct exception was raised except channel.ApplicationError as error: # no problem pass # verify that the buffer is empty after the flush assert len(channel.page) == 0 # all done return
def test(): """ Verify that we can suppress all output from channels """ # get the channel from journal.ext.journal import Error as error # suppress all output error.quiet() # make a channel channel = error(name="test.journal.error") # add some metadata channel.notes["time"] = "now" # carefully try: # inject channel.line("error:") channel.log(" a nasty bug was detected") # shouldn't get here assert False, "unreachable" # if the correct exception was raised except channel.ApplicationError as error: # check the description assert str(error) == "test.journal.error: application error" # all done return
def test(): """ Exercise the common use case """ # get the channel from journal.ext.journal import Error as error # and the trash can from journal.ext.journal import Trash as trash # make a channel channel = error(name="test.journal.error") # send the output to trash channel.device = trash() # add some metadata channel.notes["time"] = "now" # carefully try: # inject channel.line("error:") channel.log(" a nasty bug was detected") # shouldn't get here assert False, "unreachable" # if the correct exception was raised except channel.ApplicationError as error: # check the description assert str(error) == "test.journal.error: application error" # all done return
def test(): """ Exercise adding multiple lines at once """ # get the channel from journal.ext.journal import Error as error # and the trash can from journal.ext.journal import Trash as trash # make a channel channel = error(name="test.journal.error") # activate it channel.activate() # but send the output to trash channel.device = trash() # content in a tuple reptuple = ( "report from tuple:", " tuple line 1", " tuple line 2", ) # content in a list replist = [ "report from list:", " list line 1", " list line 2", ] # content in a generator def repgen(): yield "report from generator:" yield " generator line 1" yield " generator line 2" return # carefully try: # inject channel.report(report=reptuple) channel.report(report=replist) channel.report(report=repgen()) # flush channel.log() # shouldn't get here assert False, "unreachable" # if the correct exception was raised except channel.ApplicationError as error: # check the description assert str(error) == "test.journal.error: application error" # all done return
def test(): """ Exercise the simplest use case """ # get the channel from journal.ext.journal import Error as error # and the trash can from journal.ext.journal import Trash as trash # make a channel channel = error(name="test.journal.error") # send the output to trash channel.device = trash() # make the error non-fatal channel.fatal = False # inject channel.log("hello world!") # all done return
def test(): """ Verify that repeated use of the same channel instance works correctly """ # get the channel from journal.ext.journal import Error as error # and the trash can from journal.ext.journal import Trash as trash # make a channel channel = error(name="test.journal.error") # make it non-fatal channel.fatal = False # send the output to trash channel.device = trash() # a few times for _ in range(10): # inject channel.log("hello world!") # all done return