def preprocesses_given_bindings_and_adds_them(subject, bindings, mocker): processed = [bind('a'), bind('b')] mocker.patch.object(Keymap, '_preprocess', return_value=processed) subject.extend(*bindings) Keymap._preprocess.assert_called_with(tuple(bindings)) assert list(iter(subject)) == processed
def injects_common_context_to_bindings(binding1): bindings = [binding1, bind('x')] contexts = [context('abc').equal(42), context('def').any().equal(55)] result = Keymap(common_context=contexts)._preprocess(bindings) assert result[0].context == binding1.context + contexts assert result[1].context == contexts
def flattens_nested_keymaps(subject, bindings): nested = [Keymap(bind('x'), Keymap(bind('y'))), bind('z')] assert subject._preprocess(nested) == bindings
def flattens_nested_tuples(subject, bindings): nested = (bind('x'), (bind('y'), (bind('z'),))) assert subject._preprocess(nested) == bindings
def flattens_nested_lists(subject, bindings): nested = [bind('x'), [bind('y'), [bind('z')]]] assert subject._preprocess(nested) == bindings
def binding1(): return (bind('x').to('fire') .when('foo').any().true() .also('bar').true() .also('baz').all().false())
def bindings(): return [bind('x'), bind('y'), bind('z')]