def test(): """ Exercise a fatal warning channel with a realistic example """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Warning import Warning as warning # make a warning channel channel = warning(name="tests.journal.warning") # 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("warning 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.Warning import Warning as warning # make a channel channel = warning(name="tests.journal.warning") # verify the channel name assert channel.name == "tests.journal.warning" # 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.Warning import Warning as warning # make a warning channel channel = warning(name="tests.journal.warning") # inject an empty message 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.Warning import Warning as warning # make a warning channel channel = warning(name="tests.journal.warning") # send the output to trash channel.device = trash() # inject channel.log("hello world!") # all done return
def test(): """ Suppress all warnings """ # get the channel from journal.Warning import Warning as warning # suppress the output warning.quiet() # make a warning channel channel = warning(name="tests.journal.warning") # add some metadata channel.notes["time"] = "now" # inject channel.line("warning channel:") channel.log(" hello world!") # all done return
def test(): """ Send all channel output to a log file """ # get the channel from journal.Warning import Warning as warning # send the output to a log file warning.logfile("warning_file.log") # make a warning channel channel = warning(name="tests.journal.warning") # add some metadata channel.notes["time"] = "now" # inject channel.line("warning 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.Warning import Warning as warning # make a warning channel channel = warning(name="tests.journal.warning") # 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(): """ Verify that the channel buffers get flushed properly after {log} """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Warning import Warning as warning # make a warning channel channel = warning(name="tests.journal.warning") # send the output to trash channel.device = trash() # inject channel.log("hello world!") # verify that the buffer is empty after the flush assert len(channel.page) == 0 # all done return
def test(): """ Exercise the warning channel with a realistic example """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Warning import Warning as warning # make a warning channel channel = warning(name="tests.journal.warning") # send the output to trash channel.device = trash() # add some metadata channel.notes["time"] = "now" # inject channel.line("warning channel:") channel.log(" hello world!") # all done return
def test(): """ Verify that the renderer can trim long file names correctly """ # get the renderer from journal.Alert import Alert as alert # the color spaces from journal.ANSI import ANSI # and a channel from journal.Warning import Warning as warning # make a channel channel = warning(name="tests.journal.debug") # add a fake stack trace channel.notes["filename"] = "a_" + ("very_" * 60) + "long_filename" channel.notes["line"] = "30" channel.notes["function"] = "test" # inject channel.line("warning channel:") channel.line(" hello from a very long file name") # make a palette palette = { "reset": ANSI.x11("normal"), "channel": ANSI.x11("light slate gray"), "warning": ANSI.x11("orange"), "body": "", } # instantiate the renderer renderer = alert() # ask it to do its thing page = '\n'.join(renderer.render(palette=palette, entry=channel.entry)) # show me # print(page) # all done return