def test():
    """
    Exercise a non-fatal firewall channel with a realistic example
    """
    # get the trash can
    from journal.ext.journal import Trash as trash
    # and the channel
    from journal.ext.journal 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 any exception was raised
    except channel.FirewallError as error:
        # shouldn't get here
        assert False, "unreachable"

    # all done
    return
Example #2
0
def test():
    """
    Verify that channel buffers reset correctly after a flush
    """
    # get the channel
    from journal.ext.journal import Firewall as firewall
    # and the trash can
    from journal.ext.journal import Trash as trash

    # make a channel
    channel = firewall(name="test.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
Example #3
0
def test():
    """
    Exercise the common use case
    """
    # get the channel
    from journal.ext.journal import Firewall as firewall
    # and the trash can
    from journal.ext.journal import Trash as trash

    # make a channel
    channel = firewall(name="test.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:
        # check the description
        assert str(error) == "test.journal.firewall: FIREWALL BREACHED!"

    # all done
    return
Example #4
0
def test():
    """
    Exercise a fatal info channel with a realistic example
    """
    # get the trash can
    from journal.ext.journal import Trash as trash
    # and the channel
    from journal.ext.journal 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
Example #5
0
def test():
    """
    Exercise a non-fatal error channel with a realistic example
    """
    # get the trash can
    from journal.ext.journal import Trash as trash
    # and the channel
    from journal.ext.journal import Error as error

    # make an error channel
    channel = error(name="tests.journal.error")
    # 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("error channel:")
        channel.log("    hello world!")
    # if the correct exception was raised
    except channel.ApplicationError as error:
        # shouldn't get here
        assert False, "unreachable"

    # all done
    return
Example #6
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
Example #7
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
Example #8
0
def test():
    """
    Exercise adding multiple lines at once
    """
    # get the channel
    from journal.ext.journal import Firewall as firewall
    # and the trash can
    from journal.ext.journal import Trash as trash

    # make a channel
    channel = firewall(name="test.journal.firewall")
    # 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.FirewallError as error:
        # check the description
        assert str(error) == "test.journal.firewall: FIREWALL BREACHED!"

    # all done
    return
Example #9
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
Example #10
0
def test():
    """
    Exercise the simplest use case
    """
    # get the trash can
    from journal.ext.journal import Trash as trash
    # and the channel
    from journal.ext.journal 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
Example #11
0
def test():
    """
    Exercise the simplest use case
    """
    # get the trash can
    from journal.ext.journal import Trash as trash
    # and the channel
    from journal.ext.journal 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
Example #12
0
def test():
    """
    Exercise the simplest use case
    """
    # get the trash can
    from journal.ext.journal import Trash as trash
    # and the channel
    from journal.ext.journal 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
Example #13
0
def test():
    """
    Verify that repeated access to the same channel does not accumulate extraneous material
    """
    # get the trash can
    from journal.ext.journal import Trash as trash
    # and the channel
    from journal.ext.journal 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
Example #14
0
def test():
    """
    Exercise the simplest use case
    """
    # get the channel
    from journal.ext.journal import Firewall as firewall
    # and the trash can
    from journal.ext.journal import Trash as trash

    # make a channel
    channel = firewall(name="test.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
Example #15
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
Example #16
0
def test():
    """
    Verify that the channel buffers get flushed properly after {log}
    """
    # get the trash can
    from journal.ext.journal import Trash as trash
    # and the channel
    from journal.ext.journal 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
Example #17
0
def test():
    """
    Exercise the info channel with a realistic example
    """
    # get the trash can
    from journal.ext.journal import Trash as trash
    # and the channel
    from journal.ext.journal 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
Example #18
0
def test():
    """
    Exercise the help channel with a realistic example
    """
    # get the trash can
    from journal.ext.journal import Trash as trash
    # and the channel
    from journal.ext.journal 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
Example #19
0
def test():
    """
    Verify that repeated use of the same channel instance works correctly
    """
    # get the channel
    from journal.ext.journal import Error as error
    # and the trash can
    from journal.ext.journal import Trash as trash

    # make a channel
    channel = error(name="test.journal.error")
    # 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
Example #20
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
Example #21
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