def test(): """ Exercise the simplest use case """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Error import Error as error # make an error channel channel = error(name="tests.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: # all good pass # all done return
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 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.Error import Error as error # make an error channel channel = error(name="tests.journal.error") # send the output to trash channel.device = trash() # a few times for _ in range(10): # 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: # all good pass # all done return
def test(): """ Exercise the firewall channel with a realistic example """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Firewall import Firewall as firewall # make a firewall channel channel = firewall(name="tests.journal.firewall") # send the output to trash channel.device = trash() # add some metadata channel.notes["time"] = "now" # carefully try: # inject channel.line("firewall:") channel.log(" a nasty bug was detected") # shouldn't get here assert False, "unreachable" # if the correct exception was raised except channel.FirewallError as error: # verify that the description is correct assert str(error) == ( f"file='{__file__}', line='29', function='test': " "firewall breached; aborting..." ) # all done return
def test(): """ Exercise a non-fatal firewall channel with a realistic example """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Firewall import Firewall as firewall # make a firewall channel channel = firewall(name="tests.journal.firewall") # 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("firewall:") channel.log(" a nasty bug was detected") # if an exception was raised except channel.FirewallError as error: # shouldn't get here assert False, "unreachable" # all done return
def test(): """ Exercise the error channel with a realistic example """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Error import Error as error # make an error channel channel = error(name="tests.journal.error") # 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!") # shouldn't get here assert False, "unreachable" # if the correct exception was raised except channel.ApplicationError as error: # all good pass # 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.Firewall import Firewall as firewall # make a firewall channel channel = firewall(name="tests.journal.firewall") # 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.FirewallError as error: # no problem pass # verify that the buffer is empty after the flush assert len(channel.page) == 0 # all done return
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(): """ Exercise adding multiple lines at once """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Error import Error as error # 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: # verify that the description is correct assert str(error) == ( f"file='{__file__}', line='52', function='test': " "application error; aborting...") # all done return
def test(): """ Verify that we can access the {trash} device """ # get the device from journal.Trash import Trash as trash # instantiate and verify the name assert trash().name == "trash" # 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.Informational import Informational as info # make a channel channel = info(name="test.journal.info") # 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.Informational import Informational as info # make an info channel channel = info(name="tests.journal.info") # send the output to trash channel.device = trash() # inject channel.log("hello world!") # all done return
def test(): """ Exercise getting/setting the global device """ # get the chronicler from journal.Chronicler import Chronicler as chronicler # and the trash can from journal.Trash import Trash as trash # make a new device custom = trash() # install it chronicler.device = custom # verify that it was installed correctly assert chronicler.device is custom # 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(): """ 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(): """ 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.Informational import Informational as info # make an info channel channel = info(name="tests.journal.info") # 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 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 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 message injection is handled properly """ # get the channel from journal.Null import Null as null # and the trash can from journal.Trash import Trash as trash # make a null channel channel = null(name="tests.journal.null") # 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 message injection is handled properly """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Firewall import Firewall as firewall # make a firewall channel channel = firewall(name="tests.journal.firewall") # send the output to trash channel.device = trash() # make the firewall non-fatal channel.fatal = False # inject channel.log("hello world!") # 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 channel buffers get flushed properly after {log} """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Informational import Informational as info # make an info channel channel = info(name="tests.journal.info") # 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(): """ 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 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
def test(): """ Exercise the info channel with a realistic example """ # get the trash can from journal.Trash import Trash as trash # and the channel from journal.Informational import Informational as info # make an info channel channel = info(name="tests.journal.info") # send the output to trash channel.device = trash() # add some metadata channel.notes["time"] = "now" # inject channel.line("info channel:") 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(): """ 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.Firewall import Firewall as firewall # make a firewall channel channel = firewall(name="tests.journal.firewall") # 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
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(): """ Verify that we can control the default device """ # the trash can from journal.Trash import Trash as trash # get the channel from journal.Channel import Channel as channel # ask it for the default device builtin = channel.getDefaultDevice() # make new device custom = trash() # install it old = channel.setDefaultDevice(device=custom) # check that the default device is what we just installed assert channel.getDefaultDevice() is custom # and the device we just replaced was the original built-in one assert old is builtin # 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