1- import configparser
21from pathlib import Path
32
4- from click .testing import CliRunner
5-
63from repo_man .commands .add import add
74
85
9- def test_add_clean_confirm ():
10- runner = CliRunner ()
11-
6+ def test_add_clean_confirm (runner , get_config ):
127 with runner .isolated_filesystem ():
138 (Path ("." ) / "some-repo" ).mkdir ()
14- config = configparser .ConfigParser ()
15- config .read ("repo-man.cfg" )
9+ config = get_config ()
1610 result = runner .invoke (add , ["some-repo" , "-t" , "some-type" ], input = "Y\n Y\n " , obj = config )
1711 assert result .exit_code == 0
1812 assert (
@@ -37,13 +31,10 @@ def test_add_clean_confirm():
3731 )
3832
3933
40- def test_add_clean_no_confirm_new_file ():
41- runner = CliRunner ()
42-
34+ def test_add_clean_no_confirm_new_file (runner , get_config ):
4335 with runner .isolated_filesystem ():
4436 (Path ("." ) / "some-repo" ).mkdir ()
45- config = configparser .ConfigParser ()
46- config .read ("repo-man.cfg" )
37+ config = get_config ()
4738 result = runner .invoke (add , ["some-repo" , "-t" , "some-type" ], input = "\n " , obj = config )
4839 assert result .exit_code == 1
4940 assert (
@@ -54,9 +45,7 @@ def test_add_clean_no_confirm_new_file():
5445 )
5546
5647
57- def test_add_with_existing_file ():
58- runner = CliRunner ()
59-
48+ def test_add_with_existing_file (runner , get_config ):
6049 with runner .isolated_filesystem ():
6150 with open ("repo-man.cfg" , "w" ) as config_file :
6251 config_file .write (
@@ -67,8 +56,7 @@ def test_add_with_existing_file():
6756 )
6857
6958 (Path ("." ) / "some-repo" ).mkdir ()
70- config = configparser .ConfigParser ()
71- config .read ("repo-man.cfg" )
59+ config = get_config ()
7260 result = runner .invoke (add , ["some-repo" , "-t" , "some-type" ], input = "Y\n " , obj = config )
7361 assert result .exit_code == 0
7462 assert (
@@ -96,9 +84,7 @@ def test_add_with_existing_file():
9684 )
9785
9886
99- def test_add_with_existing_file_and_type ():
100- runner = CliRunner ()
101-
87+ def test_add_with_existing_file_and_type (runner , get_config ):
10288 with runner .isolated_filesystem ():
10389 with open ("repo-man.cfg" , "w" ) as config_file :
10490 config_file .write (
@@ -109,8 +95,7 @@ def test_add_with_existing_file_and_type():
10995 )
11096
11197 (Path ("." ) / "some-repo" ).mkdir ()
112- config = configparser .ConfigParser ()
113- config .read ("repo-man.cfg" )
98+ config = get_config ()
11499 result = runner .invoke (add , ["some-repo" , "-t" , "some-type" ], obj = config )
115100 assert result .exit_code == 0
116101 assert result .output == ""
@@ -127,9 +112,7 @@ def test_add_with_existing_file_and_type():
127112 )
128113
129114
130- def test_add_multiple_types ():
131- runner = CliRunner ()
132-
115+ def test_add_multiple_types (runner , get_config ):
133116 with runner .isolated_filesystem ():
134117 with open ("repo-man.cfg" , "w" ) as config_file :
135118 config_file .write (
@@ -140,8 +123,7 @@ def test_add_multiple_types():
140123 )
141124
142125 (Path ("." ) / "some-repo" ).mkdir ()
143- config = configparser .ConfigParser ()
144- config .read ("repo-man.cfg" )
126+ config = get_config ()
145127 result = runner .invoke (add , ["some-repo" , "-t" , "some-type" , "-t" , "some-other-type" ], input = "Y\n " , obj = config )
146128 assert result .exit_code == 0
147129 assert (
@@ -170,9 +152,7 @@ def test_add_multiple_types():
170152 )
171153
172154
173- def test_add_no_action_needed ():
174- runner = CliRunner ()
175-
155+ def test_add_no_action_needed (runner , get_config ):
176156 with runner .isolated_filesystem ():
177157 with open ("repo-man.cfg" , "w" ) as config_file :
178158 config_file .write (
@@ -183,8 +163,7 @@ def test_add_no_action_needed():
183163 )
184164
185165 (Path ("." ) / "some-repo" ).mkdir ()
186- config = configparser .ConfigParser ()
187- config .read ("repo-man.cfg" )
166+ config = get_config ()
188167 result = runner .invoke (add , ["some-repo" , "-t" , "some-type" ], obj = config )
189168 assert result .exit_code == 0
190169 assert result .output == ""
0 commit comments