Beispiel #1
0
def test_log_for_one_arg():
    """Only log, when at most one argument is given."""
    with patch.object(log, "debug") as debug:
        log_sometimes(1)
        log_sometimes(2, 3)
        log_sometimes(4)
        log_sometimes(5, 6, 7)
        log_sometimes(8, 9, 10, 11)
        debug.assert_any_call("1")
        debug.assert_any_call("4")
        assert debug.call_count == 2
Beispiel #2
0
#!/usr/bin/env python
from __future__ import print_function
import logging

import logic


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)

    longstring = "this is a long string to be shortened"
    print("[{name}] Shortening long string {} -> {}".format(
        longstring, logic.shorten(longstring), name=logic.shorten.__name__))

    print()
    messages = [("one", "two", "three"), ("four",), (7,), ("whynot")]
    for args in messages:
        print("[{name}] Logging {} ...".format(
            args,
            name=logic.log_sometimes.__name__),
        )
        logic.log_sometimes(*args)
    print("Done logging.")

    print()
    print("[{name}] Quoting {} -> {}".format(
        "blub", logic.rst_quote("blub"), name=logic.rst_quote.__name__))