-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #459 from python-jsonschema/enhance-testing
Minor testing enhancements
- Loading branch information
Showing
7 changed files
with
85 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import pytest | ||
from click.testing import CliRunner | ||
|
||
|
||
@pytest.fixture | ||
def runner() -> CliRunner: | ||
return CliRunner(mix_stderr=False) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import click | ||
import pytest | ||
|
||
from check_jsonschema.cli.warnings import deprecation_warning_callback | ||
|
||
|
||
@click.command("foo") | ||
@click.option( | ||
"--bar", | ||
is_flag=True, | ||
callback=deprecation_warning_callback("--bar", is_flag=True), | ||
) | ||
@click.option( | ||
"--baz", | ||
callback=deprecation_warning_callback( | ||
"--baz", append_message="Use --frob instead!" | ||
), | ||
) | ||
def mycli(bar, baz): | ||
print(bar) | ||
if baz: | ||
print(baz) | ||
|
||
|
||
def test_deprecation_warning_callback_on_missing_opts(runner): | ||
result = runner.invoke(mycli, []) | ||
assert result.exit_code == 0 | ||
assert result.stdout == "False\n" | ||
|
||
|
||
def test_deprecation_warning_callback_on_flag(runner): | ||
with pytest.warns( | ||
UserWarning, | ||
match="'--bar' is deprecated and will be removed in a future release", | ||
): | ||
result = runner.invoke(mycli, ["--bar"], catch_exceptions=False) | ||
assert result.exit_code == 0, result.stdout | ||
assert result.stdout == "True\n" | ||
|
||
|
||
def test_deprecation_warning_callback_added_message(runner): | ||
with pytest.warns( | ||
UserWarning, | ||
match=( | ||
"'--baz' is deprecated and will be removed in a future release. " | ||
"Use --frob instead!" | ||
), | ||
): | ||
result = runner.invoke(mycli, ["--baz", "ok"], catch_exceptions=False) | ||
assert result.exit_code == 0, result.stdout | ||
assert result.stdout == "False\nok\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters