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"
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'
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"
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'
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>")
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() ])
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>" )
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
def test_make_banner_with_context(): context = {'foo': 42} result = konch.make_banner(context=context) assert konch.format_context(context) in result
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
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
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
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