def mock_inputs(inputs):
def inner(test_func):<EOL><INDENT>def wrapped(*args):<EOL><INDENT>class mock_getpass:<EOL><INDENT>@staticmethod<EOL>def getpass(prompt=b'<STR_LIT>', stream=None):<EOL><INDENT>if callable(inputs['<STR_LIT:password>']):<EOL><INDENT>return inputs['<STR_LIT:password>']()<EOL><DEDENT>return inputs['<STR_LIT:password>']<EOL><DEDENT><DEDENT>def mock_input(prompt):<EOL><INDENT>assert '<STR_LIT>' not in prompt<EOL>response = None<EOL>for key, val in inputs.items():<EOL><INDENT>prompt_msgs = MOCK_INPUT_KEY_TO_PROMPTS.get(key, key)<EOL>if isinstance(prompt_msgs, list):<EOL><INDENT>prompt_msgs = [msg() if callable(msg) else msg for msg in prompt_msgs]<EOL><DEDENT>if prompt in prompt_msgs:<EOL><INDENT>if callable(val):<EOL><INDENT>response = val()<EOL><DEDENT>else:<EOL><INDENT>response = val<EOL><DEDENT>break<EOL><DEDENT><DEDENT>if response is None:<EOL><INDENT>raise ValueError('<STR_LIT>' % prompt)<EOL><DEDENT>return response<EOL><DEDENT>old_getpass = createsuperuser.getpass<EOL>old_input = builtins.input<EOL>createsuperuser.getpass = mock_getpass<EOL>builtins.input = mock_input<EOL>try:<EOL><INDENT>test_func(*args)<EOL><DEDENT>finally:<EOL><INDENT>createsuperuser.getpass = old_getpass<EOL>builtins.input = old_input<EOL><DEDENT><DEDENT>return wrapped<EOL><DEDENT>return inner<EOL>
Decorator to temporarily replace input/getpass to allow interactive
createsuperuser.