Beispiel #1
0
def test():
    """
    Verify we can make firewalls non-fatal
    """
    # get the journal
    import journal

    # make a firewall channel
    channel = journal.firewall(name="tests.journal.firewall")
    # make it non-fatal
    channel.fatal = False
    # send the output to the trash
    channel.device = journal.trash()
    # add some metadata
    channel.notes["time"] = "now"

    # carefully
    try:
        # inject
        channel.line("firewall:")
        channel.log("    a nasty bug was detected")
    # if the correct exception was raised
    except channel.FirewallError as error:
        # shouldn't get here
        assert False, "unreachable"

    # all done
    return
Beispiel #2
0
def test():
    """
    Exercise a channel with a realistic example when the channel is fatal
    """
    # the journal
    import journal

    # make a channel
    channel = journal.debug(name="tests.journal.debug")
    # activate it
    channel.active = True
    # make it fatal
    channel.fatal = True
    # but 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("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
Beispiel #3
0
def test():
    """
    Verify that the channel buffers are cleared after flushing a message; this is a non-trivial
    test because it guarantees that the implementation handles the transaction correctly
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.error(name="test.journal.error")
    # send the output to the trash
    channel.device = journal.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:
        # no problem
        pass

    # verify that the buffer is empty after the flush
    assert len(channel.page) == 0

    # all done
    return
Beispiel #4
0
def test():
    """
    Exercise the common use case
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.firewall(name="test.journal.firewall")
    # send the output to the trash
    channel.device = journal.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
Beispiel #5
0
def test():
    """
    Verify that channels lower in the hierarchy inherit their parent default state
    """
    # get the journal
    import journal

    # make a channel
    parent = journal.error(name="test.index.parent")
    # verify that the state is off
    assert parent.active is True
    # that it is fatal
    assert parent.fatal is True
    # and the device is at the default value
    assert parent.device is parent.chronicler.device

    # deactivate it
    parent.active = False
    # make it non fatal
    parent.fatal = False
    # set the device to a trash can
    parent.device = journal.trash()

    # lookup a name that is lower in the hierarchy
    child = journal.error(name="test.index.parent.blah.blah.child")
    # that its 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
Beispiel #6
0
def test():
    """
    Exercise the channel with a realistic example when it is fatal
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.warning(name="tests.journal.warning")
    # 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("warning 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
Beispiel #7
0
def test():
    """
    Exercise the usual test case
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.error(name="test.journal.error")
    # send the output to the trash
    channel.device = journal.trash()

    # add some metadata
    channel.notes["time"] = "now"

    # carefully
    try:
        # inject
        channel.line("error:")
        channel.log("    a nasty bug was detected")
        # shouldn't get here
        assert False, "unreachable"
    # if the correct exception was raised
    except channel.ApplicationError as error:
        # check the description
        assert str(error) == "test.journal.error: application error"

    # all done
    return
Beispiel #8
0
def test():
    """
    Verify that flushing clears the message buffers
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.firewall(name="test.journal.firewall")
    # send the output to the trash
    channel.device = journal.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
Beispiel #9
0
def test():
    """
    Exercise the usual test case with an non-fatal channel
    """
    # get the journal
    import journal

    # make an error channel
    channel = journal.error(name="tests.journal.error")
    # make it non-fatal
    channel.fatal = False
    # send the output to the trash
    channel.device = journal.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
Beispiel #10
0
def test():
    """
    Verify access to the channel properties
    """
    # access
    import journal

    # make a channel
    channel = journal.warning("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 verbosity is at 1 by default
    assert channel.verbosity == 1
    # that it can be modified
    channel.verbosity = 5
    # and the assignment sticks
    assert channel.verbosity == 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
Beispiel #11
0
def test():
    """
    Exercise adding multiple lines at once
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.error(name="test.journal.error")
    # activate it
    channel.activate()
    # but send the output to trash
    channel.device = journal.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:
        # check the description
        assert str(error) == "test.journal.error: application error"

    # all done
    return
Beispiel #12
0
def test():
    """
    Verify that the trash can is accessible
    """
    # access
    import journal

    # make a trash can
    trash = journal.trash()
    # verify its name is what we expect
    assert trash.name == "trash"

    # all done
    return
Beispiel #13
0
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
Beispiel #14
0
def test():
    """
    Exercise adding multiple lines at once
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.debug(name="test.journal.debug")
    # activate it
    channel.activate()
    # but send the output to trash
    channel.device = journal.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
Beispiel #15
0
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.info(name="tests.journal.info")
    # 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
Beispiel #16
0
def test():
    """
    Verify that we can inject simple messages correctly
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.error(name="test.journal.error")
    # make it non-fatal
    channel.fatal = False
    # send the output to the trash
    channel.device = journal.trash()

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

    # all done
    return
Beispiel #17
0
def test():
    """
    Exercise the simplest non-trivial use case
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.firewall(name="test.journal.firewall")
    # send the output to the trash
    channel.device = journal.trash()
    # make the firewall non-fatal
    channel.fatal = False

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

    # all done
    return
Beispiel #18
0
def test():
    """
    Verify that the channel buffers get flushed properly after {log}
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.info(name="tests.journal.info")
    # 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
Beispiel #19
0
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
Beispiel #20
0
def test():
    """
    Exercise the common use case
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.info(name="tests.journal.info")
    # send the output to the trash
    channel.device = journal.trash()
    # add some metadata
    channel.notes["time"] = "now"

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

    # all done
    return
Beispiel #21
0
def test():
    """
    Verify that content is flushed correctly when the same channel instance is used multiple times
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.firewall(name="test.journal.firewall")
    # make it non-fatal
    channel.fatal = False
    # send the output to the trash
    channel.device = journal.trash()

    # a few times
    for _ in range(10):
        # inject
        channel.log("hello world!")

    # all done
    return
Beispiel #22
0
def test():
    """
    Verify that content is flushed correctly when the same channel instance is used multiple times
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.debug(name="test.journal.debug")
    # activate it
    channel.activate()
    # but 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
Beispiel #23
0
def test():
    """
    Verify that the message buffers reset correctly after flushing
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.debug(name="test.journal.debug")
    # activate it
    channel.activate()
    # but 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
Beispiel #24
0
def test():
    """
    Verify that the channel wide defaults are as expected
    """
    # access
    import journal

    # verify that firewall channels are active by default
    assert journal.firewall.defaultActive == True
    # and fatal
    assert journal.firewall.defaultFatal == True
    # verify that the channel default device is not set
    assert journal.firewall.defaultDevice == None

    # make a trash can
    trash = journal.trash()
    # make it the default device
    journal.firewall.defaultDevice = trash
    # and make sure the assignment sticks
    assert journal.firewall.defaultDevice is trash

    # make a channel
    channel = journal.firewall("test.channel")
    # verify that its view of its default state is consistent
    assert channel.defaultActive == journal.firewall.defaultActive
    assert channel.defaultFatal == journal.firewall.defaultFatal
    # similarly for the default device
    assert channel.defaultDevice == journal.firewall.defaultDevice

    # and now, the instance state
    assert channel.active == channel.defaultActive
    assert channel.fatal == channel.defaultFatal
    assert channel.device == channel.defaultDevice

    # all done
    return
Beispiel #25
0
def test():
    """
    Verify that we can set the global default device
    """
    # access
    import journal

    # get the global state
    chronicler = journal.chronicler

    # verify that the default device is the console
    assert chronicler.device.name == "cout"

    # make a trash can
    trash = journal.trash()
    # set it as the device
    chronicler.device = trash
    # verify the assignment sticks
    assert chronicler.device is trash
    # and that the name is correct
    assert chronicler.device.name == "trash"

    # all done
    return