Exemple #1
0
def test():
    """
    Send all channel output to a log file
    """
    # get the channel
    from journal.Error import Error as error

    # send the output to a log file
    error.logfile("error_file.log")

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

    # carefully
    try:
        # inject
        channel.line("error channel:")
        channel.log("    hello world!")
        # shouldn't get here
        assert False, "unreachable"
    # if the correct exception was raised
    except channel.ApplicationError as error:
        # all  good
        pass

    # all done
    return
Exemple #2
0
def test():
    """
    Exercise the error channel with a realistic example
    """
    # get the trash can
    from journal.Trash import Trash as trash
    # and the channel
    from journal.Error import Error as error

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

    # all done
    return
Exemple #3
0
def test():
    """
    Exercise the simplest use case
    """
    # get the trash can
    from journal.Trash import Trash as trash
    # and the channel
    from journal.Error import Error as error

    # make an error channel
    channel = error(name="tests.journal.error")
    # 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.ApplicationError as error:
        # all  good
        pass

    # all done
    return
Exemple #4
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.Error import Error as error

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

    # a few times
    for _ in range(10):
        # 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:
            # all  good
            pass

    # all done
    return
Exemple #5
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.Error import Error as error

    # make a channel
    channel = error(name="tests.journal.error")
    # send the output to the 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.ApplicationError as error:
        # all  good
        pass

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

    # all done
    return
Exemple #6
0
def test():
    """
    Sanity check: verify that the channel is accessible
    """
    # get the channel
    from journal.Error import Error as error

    # make a channel
    channel = error(name="tests.journal.error")
    # verify the channel name
    assert channel.name == "tests.journal.error"
    # the verbosity should be at the default level
    assert channel.verbosity == 1
    # the channel should be active
    assert channel.active == True
    # and fatal
    assert channel.fatal == True

    # 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
Exemple #7
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.Error import Error as error

    # make a channel
    channel = error(name="test.journal.error")
    # 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.ApplicationError as error:
        # verify that the description is correct
        assert str(error) == (
            f"file='{__file__}', line='52', function='test': "
            "application error; aborting...")

    # all done
    return
Exemple #8
0
def test():
    """
    Verify that empty log messages get handled properly
    """
    # get the channel
    from journal.Error import Error as error

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

    # carefully
    try:
        # inject an empty message
        channel.log()
        # shouldn't get here
        assert False, "unreachable"
    # if the correct exception was raised
    except channel.ApplicationError as error:
        # all  good
        pass

    # all done
    return