def test(): """ Exercise a fatal debug channel with a realistic example """ # access the parts from journal.Trash import Trash as trash from journal.Debug import Debug as debug # make a debug channel channel = debug(name="tests.journal.debug") # activate it channel.active = True # make it fatal channel.fatal = True # but 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("debug channel:") channel.log(" hello world!") # this should be unreachable assert False, "unreachable" # if all goes well, the channel raised an error except channel.DebugError: # all good pass # all done return
def test(): """ Verify the channel initial state """ # get the channel from journal.Debug import Debug as debug # make a channel channel = debug(name="tests.journal.debug") # verify the channel name assert channel.name == "tests.journal.debug" # the verbosity should be at the default level assert channel.verbosity == 1 # the channel should be inactive assert channel.active == False # and non-fatal assert channel.fatal == 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(): """ Exercise the developer facing renderer """ # get the renderer from journal.Bland import Bland as bland # the color spaces from journal.ANSI import ANSI # and a channel from journal.Debug import Debug as debug # get the chronicler metadata gmeta = debug.chronicler.notes # add some gmeta["application"] = "bland" gmeta["author"] = "michael" # make a channel channel = debug(name="tests.journal.debug") # generate a fake stack trace channel.notes["filename"] = "bland_sanity" channel.notes["line"] = 29 channel.notes["function"] = "test" # add some metadata channel.notes["time"] = "now" channel.notes["device"] = "null" # inject channel.line("debug channel:") channel.line(" hello world!") # make a palette palette = { "reset": ANSI.x11("normal"), "channel": ANSI.x11("light slate gray"), "debug": ANSI.x11("steel blue"), "body": "", } # instantiate the renderer renderer = bland() # ask it to do its thing page = '\n'.join(renderer.render(palette=palette, entry=channel.entry)) # and show me # print(page) # all done return
def test(): """ Verify that empty log messages get handled properly """ # and the channel from journal.Debug import Debug as debug # make a debug channel channel = debug(name="tests.journal.debug") # activate it channel.activate() # 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.Debug import Debug as debug # make a channel channel = debug(name="test.journal.debug") # 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(): """ Verify that message injection is handled properly """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Debug import Debug as debug # make a debug channel channel = debug(name="tests.journal.debug") # activate it channel.activate() # but send the output to trash channel.device = trash() # inject channel.log("hello world!") # all done return
def test(): """ Verify that the renderer can trim long file names correctly """ # get the renderer from journal.Memo import Memo as memo # the color spaces from journal.ANSI import ANSI # and a channel from journal.Debug import Debug as debug # make a channel channel = debug(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("debug channel:") channel.line(" hello from a very long file name") # make a palette palette = { "reset": ANSI.x11("normal"), "channel": ANSI.x11("light slate gray"), "debug": ANSI.x11("steel blue"), "body": "", } # instantiate the renderer renderer = memo() # ask it to do its thing page = '\n'.join(renderer.render(palette=palette, entry=channel.entry)) # show me # print(page) # 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.Debug import Debug as debug # make a channel channel = debug(name="tests.journal.debug") # activate it channel.activate() # but send the output to trash channel.device = trash() # for a few times for _ in range(10): # inject channel.log("hello world!") # all done return
def test(): """ Exercise the debug channel with a realistic example """ # access the parts from journal.Trash import Trash as trash from journal.Debug import Debug as debug # make a debug channel channel = debug(name="tests.journal.debug") # activate it channel.activate() # but send the output to trash channel.device = trash() # add some metadata channel.notes["time"] = "now" # inject channel.line("debug channel:") channel.log(" hello world!") # all done return
def test(): """ Send all channel output to a log file """ # access the channel from journal.Debug import Debug as debug # send the output to a log file debug.logfile("debug_file.log") # make a channel channel = debug(name="tests.journal.debug") # activate it channel.activate() # add some metadata channel.notes["time"] = "now" # inject channel.line("debug channel:") channel.log(" hello world!") # all done return
def test(): """ Suppress all debug output """ # access the channel from journal.Debug import Debug as debug # suppress the output debug.quiet() # make a channel channel = debug(name="tests.journal.debug") # activate it channel.activate() # add some metadata channel.notes["time"] = "now" # inject channel.line("debug channel:") 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.Debug import Debug as debug # make a debug channel channel = debug(name="tests.journal.debug") # activate it channel.activate() # but 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