Example #1
0
def test_custom_formatter():
    context = {"foo": 42, "bar": 24}

    def my_formatter(ctx):
        return "*".join(sorted(ctx.keys()))

    assert konch.format_context(context, formatter=my_formatter) == "bar*foo"
Example #2
0
def test_custom_formatter():
    context = {'foo': 42, 'bar': 24}

    def my_formatter(ctx):
        return '*'.join(sorted(ctx.keys()))

    assert konch.format_context(context, formatter=my_formatter) == 'bar*foo'
Example #3
0
def test_custom_formatter():
    context = {"foo": 42, "bar": 24}

    def my_formatter(ctx):
        return "*".join(sorted(ctx.keys()))

    assert konch.format_context(context, formatter=my_formatter) == "bar*foo"
Example #4
0
def test_short_formatter():
    class Foo:
        def __repr__(self):
            return "<Foo>"

    context = {"foo": Foo(), "bar": 42}

    assert konch.format_context(context, formatter="short") == "\nContext:\nbar, foo"
Example #5
0
def test_short_formatter():
    class Foo(object):
        def __repr__(self):
            return '<Foo>'

    context = {'foo': Foo(), 'bar': 42}

    assert konch.format_context(context,
                                formatter='short') == '\nContext:\nbar, foo'
Example #6
0
def test_short_formatter():
    class Foo:
        def __repr__(self):
            return "<Foo>"

    context = {"foo": Foo(), "bar": 42}

    assert konch.format_context(context,
                                formatter="short") == "\nContext:\nbar, foo"
Example #7
0
def test_full_formatter():
    class Foo:
        def __repr__(self):
            return "<Foo>"

    context = {"foo": Foo(), "bar": 42}

    assert (konch.format_context(
        context, formatter="full") == "\nContext:\nbar: 42\nfoo: <Foo>")
Example #8
0
def test_format_context():
    context = {
        'my_number': 42,
        'my_func': lambda x: x,
    }
    result = konch.format_context(context)
    assert result == '\n'.join([
        '{0}: {1!r}'.format(key, value)
        for key, value in context.items()
    ])
Example #9
0
def test_full_formatter():
    class Foo:
        def __repr__(self):
            return "<Foo>"

    context = {"foo": Foo(), "bar": 42}

    assert (
        konch.format_context(context, formatter="full")
        == "\nContext:\nbar: 42\nfoo: <Foo>"
    )
Example #10
0
def test_make_banner_hide_context():
    context = {'foo': 42}
    result = konch.make_banner(context=context, hide_context=True)
    assert konch.format_context(context) not in result
Example #11
0
def test_make_banner_with_context():
    context = {'foo': 42}
    result = konch.make_banner(context=context)
    assert konch.format_context(context) in result
Example #12
0
def test_make_banner_hide_context():
    context = {'foo': 42}
    result = konch.make_banner(context=context, context_format='hide')
    assert konch.format_context(context) not in result
Example #13
0
def test_make_banner_includes_full_context_by_default():
    context = {'foo': 42}
    result = konch.make_banner(context=context)
    assert konch.format_context(context, formatter='full') in result
Example #14
0
def test_make_banner_hide_context():
    context = {"foo": 42}
    result = konch.make_banner(context=context, context_format="hide")
    assert konch.format_context(context) not in result
Example #15
0
def test_make_banner_hide_context():
    context = {"foo": 42}
    result = konch.make_banner(context=context, context_format="hide")
    assert konch.format_context(context) not in result
Example #16
0
def test_make_banner_includes_full_context_by_default():
    context = {"foo": 42}
    result = konch.make_banner(context=context)
    assert konch.format_context(context, formatter="full") in result