Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for click 8.x (cookiecutter#1569)
* Make read_user_dict compatible with click 8.x The `read_user_dict` function uses a "default" sentinel instead of the actual default value. Being a JSON dict, the latter would often be hard to type. Under click 8.x, the default value for `click.prompt` is passed to the `read_proc` callback. We use this callback to load JSON from the user input, and this would choke on an input like "default" (without quotes). Therefore, change the callback to return the default value when it receives the "default" sentinel. Under click 7.x (which is our minimum version), the default value for `click.prompt` is returned as-is. Therefore, continue to handle the case where `click.prompt` returns "default" instead of the actual default value, but only if we're actually running under click 7.x. (Checking for click 7.x is only done for clarity. Under click 8.x, `click.prompt` would never return "default", even if a user entered it as a valid JSON string. This is because our callback requires a dict, not a string.) * test: Expect read_user_dict to call click.prompt with partial object Previously, tests for `read_user_dict` expected `process_json` to be passed to click.prompt directly. Instead, we now pass an instance of `functools.partial`, so adapt the mock to reflect that. * test: Avoid mocking `click.prompt` when testing defaults Do not mock `click.prompt` when testing that `read_user_dict` returns the proper default value (rather than the sentinel "default"). Mocking `click.prompt` prevents our callback from running, and under click >= 8.0 we process the sentinel in the callback. Instead, use `click.testing.CliRunner` to fake standard input. * test: Adapt regression test for default handling Expect `json.loads` not to be called with the sentinel ("default"). Previously, the test expected `process_json` not to be called, but under click >= 8.0 that is now where we handle the sentinel. * Update dependencies for click 8.x
- Loading branch information