Exemplo n.º 1
0
def test():
    """
    Exercise a fatal 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")
    # 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:
        # to inject something
        channel.line("info 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
Exemplo n.º 2
0
def test():
    """
    Verify the channel state
    """
    # get the channel
    from journal.Informational import Informational as info

    # make a channel
    channel = info(name="tests.journal.info")
    # verify the channel name
    assert channel.name == "tests.journal.info"
    # the detail should be at the default level
    assert channel.detail == 1
    # it 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
Exemplo n.º 3
0
def test():
    """
    Verify that empty log messages get handled properly
    """
    # get the channel
    from journal.Informational import Informational as info

    # make an info channel
    channel = info(name="tests.journal.info")

    # inject an empty message
    channel.log()

    # all done
    return
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
def test():
    """
    Suppress all info output
    """
    # get the channel
    from journal.Informational import Informational as info

    # suppress the output
    info.quiet()

    # make an info channel
    channel = info(name="tests.journal.info")
    # add some metadata
    channel.notes["time"] = "now"

    # inject
    channel.line("info channel:")
    channel.log("    hello world!")

    # all done
    return
Exemplo n.º 8
0
def test():
    """
    Send all channel output to a log file
    """
    # get the channel
    from journal.Informational import Informational as info

    # send the output to a log file
    info.logfile("info_file.log")

    # make an info channel
    channel = info(name="tests.journal.info")
    # add some metadata
    channel.notes["time"] = "now"

    # inject
    channel.line("info channel:")
    channel.log("    hello world!")

    # all done
    return
Exemplo n.º 9
0
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
Exemplo n.º 10
0
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
Exemplo n.º 11
0
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