Skip to content

Commit 40053ef

Browse files
authored
Fix type checking for tests (#43)
1 parent 12eac36 commit 40053ef

File tree

9 files changed

+34
-38
lines changed

9 files changed

+34
-38
lines changed

test/test_edit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
from pathlib import Path
22
from unittest.mock import Mock, patch
33

4-
import typer
4+
from typer import testing
55

66
from repo_man.cli import cli
77

88

9-
def test_edit_clean(runner: typer.testing.CliRunner) -> None:
9+
def test_edit_clean(runner: testing.CliRunner) -> None:
1010
with runner.isolated_filesystem():
1111
result = runner.invoke(cli, ["edit"])
1212
assert result.exit_code == 1
1313
assert result.output == "No repo-man.cfg file found.\n"
1414

1515

1616
@patch("repo_man.commands.edit.typer.edit")
17-
def test_edit_when_config_present(mock_edit: Mock, runner: typer.testing.CliRunner) -> None:
17+
def test_edit_when_config_present(mock_edit: Mock, runner: testing.CliRunner) -> None:
1818
with runner.isolated_filesystem():
1919
Path("repo-man.cfg").touch()
2020
result = runner.invoke(cli, ["edit"])

test/test_implode.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from pathlib import Path
22

3-
import typer
3+
from typer import testing
44

55
from repo_man.cli import cli
66

77

8-
def test_implode_when_config_present_confirm(runner: typer.testing.CliRunner) -> None:
8+
def test_implode_when_config_present_confirm(runner: testing.CliRunner) -> None:
99
with runner.isolated_filesystem():
1010
Path("repo-man.cfg").touch()
1111

@@ -15,14 +15,14 @@ def test_implode_when_config_present_confirm(runner: typer.testing.CliRunner) ->
1515
assert not Path("repo-man.cfg").exists()
1616

1717

18-
def test_implode_when_config_not_present_confirm(runner: typer.testing.CliRunner) -> None:
18+
def test_implode_when_config_not_present_confirm(runner: testing.CliRunner) -> None:
1919
with runner.isolated_filesystem():
2020
result = runner.invoke(cli, ["implode", "."], input="Y\n")
2121
assert result.exit_code == 0
2222
assert result.output == "Are you sure you want to do this? [y/N]: Y\n"
2323

2424

25-
def test_implode_when_config_present_no_confirm(runner: typer.testing.CliRunner) -> None:
25+
def test_implode_when_config_present_no_confirm(runner: testing.CliRunner) -> None:
2626
with runner.isolated_filesystem():
2727
Path("repo-man.cfg").touch()
2828

test/test_init.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from pathlib import Path
22

3-
import typer
3+
from typer import testing
44

55
from repo_man.cli import cli
66

77

8-
def test_init_clean(runner: typer.testing.CliRunner) -> None:
8+
def test_init_clean(runner: testing.CliRunner) -> None:
99
with runner.isolated_filesystem():
1010
assert not Path("repo-man.cfg").exists()
1111

@@ -15,7 +15,7 @@ def test_init_clean(runner: typer.testing.CliRunner) -> None:
1515
assert Path("repo-man.cfg").exists()
1616

1717

18-
def test_init_with_existing_confirm(runner: typer.testing.CliRunner) -> None:
18+
def test_init_with_existing_confirm(runner: testing.CliRunner) -> None:
1919
with runner.isolated_filesystem():
2020
with open("repo-man.cfg", "w") as config_file:
2121
config_file.write(
@@ -33,7 +33,7 @@ def test_init_with_existing_confirm(runner: typer.testing.CliRunner) -> None:
3333
assert config_file.read() == ""
3434

3535

36-
def test_init_with_existing_no_confirm(runner: typer.testing.CliRunner) -> None:
36+
def test_init_with_existing_no_confirm(runner: testing.CliRunner) -> None:
3737
with runner.isolated_filesystem():
3838
with open("repo-man.cfg", "w") as config_file:
3939
config_file.write(

test/test_list_repos.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from collections.abc import Callable
33
from unittest.mock import Mock, patch
44

5-
import typer
5+
from typer import testing
66

77
from repo_man.cli import cli
88

99

10-
def test_list_repos_clean(runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]) -> None:
10+
def test_list_repos_clean(runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]) -> None:
1111
with runner.isolated_filesystem():
1212
config = get_config()
1313
result = runner.invoke(cli, ["list", "-t", "all"], obj=config)
@@ -16,7 +16,7 @@ def test_list_repos_clean(runner: typer.testing.CliRunner, get_config: Callable[
1616

1717

1818
def test_list_repos_with_matches(
19-
runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
19+
runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
2020
) -> None:
2121
with runner.isolated_filesystem():
2222
with open("repo-man.cfg", "w") as config_file:
@@ -42,7 +42,7 @@ def test_list_repos_with_matches(
4242

4343
@patch("repo_man.commands.list_repos.click.echo_via_pager")
4444
def test_list_repos_when_long(
45-
mock_echo_via_pager: Mock, runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
45+
mock_echo_via_pager: Mock, runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
4646
) -> None:
4747
all_repos = """some-repo-1
4848
some-repo-2
@@ -90,7 +90,7 @@ def test_list_repos_when_long(
9090

9191

9292
def test_list_repos_for_multiple_tags(
93-
runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
93+
runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
9494
) -> None:
9595
with runner.isolated_filesystem():
9696
with open("repo-man.cfg", "w") as config_file:
@@ -118,7 +118,7 @@ def test_list_repos_for_multiple_tags(
118118

119119

120120
def test_list_repos_when_invalid_type(
121-
runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
121+
runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
122122
) -> None:
123123
with runner.isolated_filesystem():
124124
with open("repo-man.cfg", "w") as config_file:

test/test_remove.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from collections.abc import Callable
33
from pathlib import Path
44

5-
import typer
5+
from typer import testing
66

77
from repo_man.cli import cli
88

99

10-
def test_remove_clean(runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]) -> None:
10+
def test_remove_clean(runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]) -> None:
1111
with runner.isolated_filesystem():
1212
Path("some-repo").mkdir()
1313

@@ -29,7 +29,7 @@ def test_remove_clean(runner: typer.testing.CliRunner, get_config: Callable[[],
2929

3030

3131
def test_remove_when_invalid_type(
32-
runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
32+
runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
3333
) -> None:
3434
with runner.isolated_filesystem():
3535
Path("some-repo").mkdir()
@@ -61,7 +61,7 @@ def test_remove_when_invalid_type(
6161

6262

6363
def test_remove_when_unused_type(
64-
runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
64+
runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
6565
) -> None:
6666
with runner.isolated_filesystem():
6767
Path("some-repo").mkdir()

test/test_sniff.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from collections.abc import Callable
33
from pathlib import Path
44

5-
import typer
5+
from typer import testing
66

77
from repo_man.cli import cli
88

99

10-
def test_known(runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]) -> None:
10+
def test_known(runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]) -> None:
1111
with runner.isolated_filesystem():
1212
with open("repo-man.cfg", "w") as config_file:
1313
config_file.write(
@@ -34,7 +34,7 @@ def test_known(runner: typer.testing.CliRunner, get_config: Callable[[], configp
3434
assert result.output == "bar\nfoo\n"
3535

3636

37-
def test_unconfigured(runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]) -> None:
37+
def test_unconfigured(runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]) -> None:
3838
with runner.isolated_filesystem():
3939
Path("some-repo").mkdir()
4040
Path("some-other-repo").mkdir()
@@ -55,7 +55,7 @@ def test_unconfigured(runner: typer.testing.CliRunner, get_config: Callable[[],
5555
assert result.output == "some-other-repo\n"
5656

5757

58-
def test_duplicates(runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]) -> None:
58+
def test_duplicates(runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]) -> None:
5959
with runner.isolated_filesystem():
6060
with open("repo-man.cfg", "w") as config_file:
6161
config_file.write(

test/test_types.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from collections.abc import Callable
33
from pathlib import Path
44

5-
import typer
5+
from typer import testing
66

77
from repo_man.cli import cli
88

99

10-
def test_types_clean(runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]) -> None:
10+
def test_types_clean(runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]) -> None:
1111
with runner.isolated_filesystem():
1212
Path("some-repo").mkdir()
1313
config = get_config()
@@ -16,9 +16,7 @@ def test_types_clean(runner: typer.testing.CliRunner, get_config: Callable[[], c
1616
assert result.output == "No repo-man.cfg file found.\n"
1717

1818

19-
def test_types_when_configured(
20-
runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
21-
) -> None:
19+
def test_types_when_configured(runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]) -> None:
2220
with runner.isolated_filesystem():
2321
Path("some-repo").mkdir()
2422

@@ -42,7 +40,7 @@ def test_types_when_configured(
4240

4341

4442
def test_types_when_not_configured(
45-
runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
43+
runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
4644
) -> None:
4745
with runner.isolated_filesystem():
4846
Path("some-repo").mkdir()
@@ -62,9 +60,7 @@ def test_types_when_not_configured(
6260
assert result.output == ""
6361

6462

65-
def test_types_when_ignored(
66-
runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
67-
) -> None:
63+
def test_types_when_ignored(runner: testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]) -> None:
6864
with runner.isolated_filesystem():
6965
Path("some-repo").mkdir()
7066

test/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import typer
1+
from typer import testing
22

33
from repo_man.utils import get_valid_repo_types
44

55

6-
def test_get_valid_repo_types(runner: typer.testing.CliRunner) -> None:
6+
def test_get_valid_repo_types(runner: testing.CliRunner) -> None:
77
with runner.isolated_filesystem():
88
with open("repo-man.cfg", "w") as config_file:
99
config_file.write(

test/test_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from unittest.mock import patch
22

3-
import typer
3+
from typer import testing
44

55
from repo_man.cli import cli
66

77

88
@patch("repo_man.cli.RELEASE_VERSION", "0.0.0")
9-
def test_version(runner: typer.testing.CliRunner) -> None:
9+
def test_version(runner: testing.CliRunner) -> None:
1010
result = runner.invoke(cli, ["--version"])
1111
assert result.exit_code == 0
1212
assert result.output.strip() == "0.0.0"

0 commit comments

Comments
 (0)