Exemplo n.º 1
0
def test():
    """
    Exercise the common use case
    """
    # get the channel
    from journal.ext.journal import Debug as debug
    # and the trash can
    from journal.ext.journal import Trash as trash

    # make a channel
    channel = debug(name="test.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
Exemplo n.º 2
0
def test():
    """
    Verify that we can suppress all journal output
    """
    # get the chronicler
    from journal.ext.journal import Chronicler as chronicler
    # get the channel
    from journal.ext.journal import Debug as debug

    # quiet all channels
    chronicler.quiet()

    # make a channel
    channel = debug(name="test.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
Exemplo n.º 3
0
def test():
    """
    Exercise the common use case with a fatal channel
    """
    # access the parts
    from journal.ext.journal import Trash as trash
    from journal.ext.journal 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
Exemplo n.º 4
0
def test():
    """
    Verify the channel initial state
    """
    # access
    from journal.ext.journal import Debug as debug

    # make a channel
    channel = debug(name="tests.journal.debug")
    # verify the channel name
    assert channel.name == "tests.journal.debug"
    # the detail should be at the default level
    assert channel.detail == 1
    # the channel should be inactive
    assert channel.active is False
    # and non-fatal
    assert channel.fatal is False

    # the page should be empty
    assert tuple(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.º 5
0
def test():
    """
    Exercise adding multiple lines at once
    """
    # get the channel
    from journal.ext.journal import Debug as debug
    # and the trash can
    from journal.ext.journal import Trash as trash

    # 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
Exemplo n.º 6
0
def test():
    """
    Exercise the simplest use case
    """
    # get the channel
    from journal.ext.journal import Debug as debug
    # and the trash can
    from journal.ext.journal import Trash as trash

    # make a channel
    channel = debug(name="test.journal.debug")
    # activate it
    channel.activate()
    # but send the output to trash
    channel.device = trash()

    # inject
    channel.log("hello world!")

    # all done
    return
Exemplo n.º 7
0
def test():
    """
    Verify that reusing the same channel instance works correctly
    """
    # get the channel
    from journal.ext.journal import Debug as debug
    # and the trash can
    from journal.ext.journal import Trash as trash

    # make a channel
    channel = debug(name="test.journal.debug")
    # activate it
    channel.activate()
    # but 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.º 8
0
def test():
    """
    Verify that the message buffers get reset correctly after a flush
    """
    # get the channel
    from journal.ext.journal import Debug as debug
    # and the trash can
    from journal.ext.journal import Trash as trash

    # make a channel
    channel = debug(name="test.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
Exemplo n.º 9
0
def test():
    """
    Send all output from {debug} channels to a log file
    """
    # get the channel
    from journal.ext.journal import Debug as debug

    # send all output to a log file
    debug.logfile(name="debug_file_mode.log", mode="a")

    # make a channel
    channel = debug(name="test.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