def test(): """ Verify that channels lower in the hierarchy inherit the default state of their parent """ # get the journal import journal # make a channel parent = journal.help(name="test.index.parent") # verify that the state is on assert parent.active is True # it's non-fatal assert parent.fatal is False # and the device is at the default value assert parent.device is journal.help.chronicler.device # deactivate it parent.active = False # make it fatal parent.fatal = True # and set the device to a trash can parent.device = journal.trash() # lookup a name that is lower in the hierarchy child = journal.help(name="test.index.parent.blah.blah.child") # that it's state is the same as the parent assert child.active == parent.active assert child.fatal == parent.fatal # and that it inherited the device correctly assert child.device is parent.device # all done return
def test(): """ Verify access to the channel metadata """ # access import journal # make a channel channel = journal.help("test.channel") # get its metadata notes = channel.notes # adjust the application name notes["application"] = "help_notes" # add something notes["author"] = "michael" # make sure the adjustments stick by getting the value once again notes = channel.notes # and comparing against expectations assert notes["application"] == "help_notes" assert notes["author"] == "michael" assert notes["channel"] == "test.channel" assert notes["severity"] == "help" # all done return
def version(self, plexus, **kwds): """ Print the version of the {project.name} package """ # make a channel channel = journal.help("{project.name}.about.version") # get the package version major, minor, micro, revision = {project.name}.version() # show it channel.line(f"tablet: {{major}}.{{minor}}.{{micro}} rev {{revision}}") # get the bindings lib{project.name} = {project.name}.lib{project.name} # if there are bindings if lib{project.name}: channel.line() channel.line(f"lib{project.name}:") # get the library version major, minor, micro, revision = lib{project.name}.version.dynamic() # show it channel.line(f" library: {{major}}.{{minor}}.{{micro}} rev {{revision}}") # get the version of the bindings major, minor, micro, revision = lib{project.name}.version.static() # show it channel.line(f" bindings: {{major}}.{{minor}}.{{micro}} rev {{revision}}")
def test(): """ Exercise the channel with a realistic example when it is fatal """ # get the journal import journal # make a channel channel = journal.help(name="tests.journal.help") # make it fatal channel.fatal = True # send the output to the trash channel.device = journal.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 the channel initial state """ # get the journal import journal # make a channel channel = journal.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 == True # and non fatal assert channel.fatal == False # the page should be empty assert list(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 access to the channel properties """ # access import journal # make a channel channel = journal.help("test.channel") # verify its name assert channel.name == "test.channel" # check that it is read-only try: # by attempting to modify channel.name = "foo" # hence, we can't get here assert False, "unreachable" # if all goes well except AttributeError as error: # no problem pass # verify its detail is at 1 by default assert channel.detail == 1 # that it can be modified channel.detail = 5 # and the assignment sticks assert channel.detail == 5 # verify its activation state is on by default assert channel.active is True # that it can be modified channel.active = False # and the assignment sticks assert channel.active is False # verify its not fatal assert channel.fatal is False # that it can be modified channel.fatal = True # and the assignment sticks assert channel.fatal is True # verify that the accessible device is the console assert channel.device.name == "cout" # make a trash can trash = journal.trash() # register it as the device channel.device = trash # and verify that the assignment sticks assert channel.device is trash # check the name assert channel.device.name == "trash" # and verify that it's different from the default device held by the class assert channel.device is not channel.defaultDevice # all done return
def help(self, plexus, **kwds): """ Show a help screen """ # make a channel channel = journal.help("pyre.help.command") # build my help screen channel.report(report=self.pyre_help(plexus=plexus)) # and flush channel.log() # all done return 0
def help(self, **kwds): """ Hook for the application help system """ # make a channel channel = journal.help("pyre.help.application") # build the simple description of what i do and render it channel.report(report=self.pyre_help()) # flush channel.log() # and indicate success return 0
def test(): """ Verify that empty log messages get handled properly """ # get the journal import journal # make a channel channel = journal.help(name="tests.journal.help") # inject an empty message channel.log() # all done return
def test(): """ Exercise the simplest non-trivial use case """ # get the journal import journal # make a channel channel = journal.help(name="tests.journal.help") # send the output to the trash channel.device = journal.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 journal import journal # make a channel channel = journal.help(name="tests.journal.help") # send the output to the trash channel.device = journal.trash() # for a few times for _ in range(10): # inject channel.log("hello world!") # all done return
def test(): """ Exercise the channel with a realistic example """ # get the journal import journal # make a channel channel = journal.help(name="tests.journal.help") # send the output to the trash channel.device = journal.trash() # add some metadata channel.notes["time"] = "now" # inject channel.line("help channel:") channel.log(" hello world!") # all done return
def test(): """ Verify that the channel buffers get flushed properly after {log} """ # get the journal import journal # make a channel channel = journal.help(name="tests.journal.help") # send the output to the trash channel.device = journal.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 wide defaults are as expected """ # access import journal # verify that channels are active by default assert journal.help.defaultActive == True # and non-fatal assert journal.help.defaultFatal == False # verify that the channel default device is not set assert journal.help.defaultDevice == None # make a trash can trash = journal.trash() # make it the default device journal.help.defaultDevice = trash # and make sure the assignment sticks assert journal.help.defaultDevice is trash # make a another channel channel = journal.help("test.channel") # verify that its view of its default state is consistent assert channel.defaultActive == journal.help.defaultActive assert channel.defaultFatal == journal.help.defaultFatal # similarly for the default device assert channel.defaultDevice == journal.help.defaultDevice # and now, the instance state assert channel.active == channel.defaultActive assert channel.fatal == channel.defaultFatal assert channel.device == channel.defaultDevice # all done return