def test(): """ Exercise a fatal help channel with a realistic example """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Help import Help as help # make a help channel channel = help(name="tests.journal.help") # make it fatal channel.fatal = True # send the output to trash channel.device = trash() # add some metadata channel.notes["time"] = "now" # we asked for this to be fatal, so carefully try: # inject something channel.line("help channel:") channel.log(" hello world!") # this should be unreachable assert False, "unreachable" # if all goes well except channel.ApplicationError: # all good pass # all done return
def test(): """ Verify te channel state """ # get the channel from journal.Help import Help as help # make a channel channel = help(name="tests.journal.help") # verify the channel name assert channel.name == "tests.journal.help" # the detail should be at the default level assert channel.detail == 1 # the channel should be active assert channel.active is True # and non-fatal assert channel.fatal is False # the page should be empty assert 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(): """ Verify that empty log messages get handled properly """ # get the channel from journal.Help import Help as help # make a help channel channel = help(name="tests.journal.help") # inject an empty message channel.log() # all done return
def test(): """ Exercise adding multiple lines at once """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Help import Help as help # make a channel channel = help(name="test.journal.help") # 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 # inject channel.report(report=reptuple) channel.report(report=replist) channel.report(report=repgen()) # flush channel.log() # all done return
def test(): """ Exercise the simplest use case """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Help import Help as help # make a help channel channel = help(name="tests.journal.help") # send the output to trash channel.device = trash() # inject channel.log("hello world!") # all done return
def test(): """ Suppress all helps """ # get the channel from journal.Help import Help as help # suppress the output help.quiet() # make a help channel channel = help(name="tests.journal.help") # add some metadata channel.notes["time"] = "now" # inject channel.line("help channel:") channel.log(" hello world!") # all done return
def test(): """ Send all channel output to a log file """ # get the channel from journal.Help import Help as help # send the output to a log file help.logfile("help_file.log") # make a help channel channel = help(name="tests.journal.help") # add some metadata channel.notes["time"] = "now" # inject channel.line("help channel:") channel.log(" hello world!") # all done return
def test(): """ Verify that repeated access to the same channel does not accumulate extraneous material """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Help import Help as help # make a help channel channel = help(name="tests.journal.help") # send the output to trash channel.device = trash() # a few times for _ in range(10): # inject channel.log("hello world!") # all done return
def test(): """ Exercise the help channel with a realistic example """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Help import Help as help # make a help channel channel = help(name="tests.journal.help") # send the output to trash channel.device = trash() # add some metadata channel.notes["time"] = "now" # inject channel.line("help channel:") channel.log(" hello world!") # all done return