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(): """ Exercise the user facing renderer """ # get the renderer from journal.Alert import Alert as alert # the color spaces from journal.ANSI import ANSI # and a channel from journal.Informational import Informational as info # get the chronicler metadata gmeta = info.chronicler.notes # add some gmeta["application"] = "alert" gmeta["author"] = "michael" # make an info channel channel = info(name="tests.journal.info") # generate a fake stack trace channel.notes["filename"] = "memo_sanity" channel.notes["line"] = 29 channel.notes["function"] = "test" # add some metadata channel.notes["time"] = "now" channel.notes["device"] = "null" # inject channel.line("info channel:") channel.line(" hello world!") # make a palette palette = { "reset": ANSI.x11("normal"), "channel": ANSI.x11("light slate gray"), "info": ANSI.x11("steel blue"), "body": "", } # instantiate the renderer renderer = alert() # 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(): """ Check a few of the miscellaneous color names """ # access the color map from journal.ANSI import ANSI # and the control sequence generator from journal.CSI import CSI # verify the contents of the {gray} color table # the reset sequence assert ANSI.misc("normal") == CSI.reset() # my picks assert ANSI.misc("amber") == CSI.csi24(0xff, 0xbf, 0x00) assert ANSI.misc("sage") == CSI.csi24(176, 208, 176) # all done return
def test(): """ Check that the color tables respond well when asked for color names that don't exist """ # access the color map from journal.ANSI import ANSI # ask for a very strange color name assert ANSI.x11("a-very-unlikely-color-name") == "" # 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 we can detect ANSI compatible terminals correctly """ # for the command line import sys # access the color map from journal.ANSI import ANSI # pull the expected value from the command line expectation = bool(int(sys.argv[1])) if len(sys.argv) > 1 else True # ask the color map observation = ANSI.compatible() # verify that the two match assert expectation == observation # all done return
def test(): """ Check a few of the canonical greay tones """ # access the color map from journal.ANSI import ANSI # and the control sequence generator from journal.CSI import CSI # verify the contents of the {gray} color table # the reset sequence assert ANSI.gray("normal") == CSI.reset() # verify the contents of the {gray} color table assert ANSI.gray("gray10") == CSI.csi24(red=0x19, green=0x19, blue=0x19) assert ANSI.gray("gray30") == CSI.csi24(red=0x4c, green=0x4c, blue=0x4c) assert ANSI.gray("gray41") == CSI.csi24(red=0x69, green=0x69, blue=0x69) assert ANSI.gray("gray50") == CSI.csi24(red=0x80, green=0x80, blue=0x80) assert ANSI.gray("gray66") == CSI.csi24(red=0xa9, green=0xa9, blue=0xa9) assert ANSI.gray("gray75") == CSI.csi24(red=0xbe, green=0xbe, blue=0xbe) # all done return
def test(): """ Check a few of the canonical X11 color names """ # access the color map from journal.ANSI import ANSI # and the control sequence generator from journal.CSI import CSI # verify some colors assert ANSI.x11("normal") == CSI.reset() assert ANSI.x11("burlywood") == CSI.csi24(0xde, 0xb8, 0x87) assert ANSI.x11("dark goldenrod") == CSI.csi24(0xb8, 0x86, 0x0b) assert ANSI.x11("dark khaki") == CSI.csi24(0xbd, 0xb7, 0x6b) assert ANSI.x11("dark orange") == CSI.csi24(0xff, 0x8c, 0x00) assert ANSI.x11("dark sea green") == CSI.csi24(0x8f, 0xbc, 0x8f) assert ANSI.x11("firebrick") == CSI.csi24(0xb2, 0x22, 0x22) assert ANSI.x11("hot pink") == CSI.csi24(0xff, 0x69, 0xb4) assert ANSI.x11("indian red") == CSI.csi24(0xcd, 0x5c, 0x5c) assert ANSI.x11("lavender") == CSI.csi24(0xe6, 0xe6, 0xfa) assert ANSI.x11("light green") == CSI.csi24(0x90, 0xee, 0x90) assert ANSI.x11("light steel blue") == CSI.csi24(0xb0, 0xc4, 0xde) assert ANSI.x11("light slate gray") == CSI.csi24(0x77, 0x88, 0x99) assert ANSI.x11("lime green") == CSI.csi24(0x32, 0xcd, 0x32) assert ANSI.x11("navajo white") == CSI.csi24(0xff, 0xde, 0xad) assert ANSI.x11("olive drab") == CSI.csi24(0x6b, 0x8e, 0x23) assert ANSI.x11("peach puff") == CSI.csi24(0xff, 0xda, 0xb9) assert ANSI.x11("steel blue") == CSI.csi24(0x46, 0x82, 0xb4) # all done return
def test(): """ Check a few of the canonical ANSI color names """ # access the color map from journal.ANSI import ANSI # and the control sequence generator from journal.CSI import CSI # verify the contents of the {ansi} color table # the reset sequence assert ANSI.ansi("normal") == CSI.reset() # regular colors assert ANSI.ansi("black") == CSI.csi3(code=30) assert ANSI.ansi("red") == CSI.csi3(code=31) assert ANSI.ansi("green") == CSI.csi3(code=32) assert ANSI.ansi("brown") == CSI.csi3(code=33) assert ANSI.ansi("blue") == CSI.csi3(code=34) assert ANSI.ansi("purple") == CSI.csi3(code=35) assert ANSI.ansi("cyan") == CSI.csi3(code=36) assert ANSI.ansi("light-gray") == CSI.csi3(code=37) # bright colors assert ANSI.ansi("dark-gray") == CSI.csi3(code=30, bright=True) assert ANSI.ansi("light-red") == CSI.csi3(code=31, bright=True) assert ANSI.ansi("light-green") == CSI.csi3(code=32, bright=True) assert ANSI.ansi("yellow") == CSI.csi3(code=33, bright=True) assert ANSI.ansi("light-blue") == CSI.csi3(code=34, bright=True) assert ANSI.ansi("light-purple") == CSI.csi3(code=35, bright=True) assert ANSI.ansi("light-cyan") == CSI.csi3(code=36, bright=True) assert ANSI.ansi("white") == CSI.csi3(code=37, bright=True) # all done return