@@ -22,27 +22,34 @@ def tester(
2222 return command_tester_factory ("source add" , poetry = poetry_with_source )
2323
2424
25+ def _get_source_warning (priority : Priority ) -> str :
26+ if priority is Priority .SECONDARY :
27+ return (
28+ "Warning: Priority 'secondary' is deprecated. Consider changing the"
29+ " priority to one of the non-deprecated values: 'primary',"
30+ " 'supplemental', 'explicit'."
31+ )
32+ elif priority is Priority .DEFAULT :
33+ return (
34+ "Warning: Priority 'default' is deprecated. You can achieve"
35+ " the same effect by changing the priority to 'primary' and putting"
36+ " the source first."
37+ )
38+ return ""
39+
40+
2541def assert_source_added_legacy (
2642 tester : CommandTester ,
2743 poetry : Poetry ,
2844 source_existing : Source ,
2945 source_added : Source ,
3046) -> None :
31- secondary_deprecated_str = (
32- ""
33- if source_added .priority is not Priority .SECONDARY
34- else (
35- "\n Warning: Priority 'secondary' is deprecated. Consider changing the"
36- " priority to one of the non-deprecated values: 'default', 'primary',"
37- " 'supplemental', 'explicit'."
38- )
39- )
40- assert (
41- tester .io .fetch_error ().strip ()
42- == "Warning: Priority was set through a deprecated flag (--default or"
43- " --secondary). Consider using --priority next time."
44- + secondary_deprecated_str
47+ warning = (
48+ "Warning: Priority was set through a deprecated flag (--default or"
49+ " --secondary). Consider using --priority next time.\n "
50+ + _get_source_warning (source_added .priority )
4551 )
52+ assert tester .io .fetch_error ().strip () == warning
4653 assert (
4754 tester .io .fetch_output ().strip ()
4855 == f"Adding source with name { source_added .name } ."
@@ -59,6 +66,7 @@ def assert_source_added(
5966 source_existing : Source ,
6067 source_added : Source ,
6168) -> None :
69+ assert tester .io .fetch_error ().strip () == _get_source_warning (source_added .priority )
6270 assert (
6371 tester .io .fetch_output ().strip ()
6472 == f"Adding source with name { source_added .name } ."
@@ -126,9 +134,9 @@ def test_source_add_second_default_fails(
126134 tester .execute (f"--priority=default { source_default .name } 1 { source_default .url } " )
127135 assert (
128136 tester .io .fetch_error ().strip ()
129- == f"Source with name { source_default .name } is already set to "
130- " default. Only one default source can be configured at a "
131- " time."
137+ == f"{ _get_source_warning ( source_default .priority ) } \n "
138+ f"Source with name { source_default . name } is already set to default. "
139+ " Only one default source can be configured at a time."
132140 )
133141 assert tester .status_code == 1
134142
@@ -238,7 +246,7 @@ def test_source_add_existing_legacy(
238246 tester .io .fetch_error ().strip ()
239247 == "Warning: Priority was set through a deprecated flag"
240248 " (--default or --secondary). Consider using --priority next"
241- " time."
249+ f " time.\n { _get_source_warning ( Priority . DEFAULT ) } "
242250 )
243251 assert (
244252 tester .io .fetch_output ().strip ()
@@ -313,16 +321,17 @@ def test_source_add_existing_fails_due_to_other_default(
313321 poetry_with_source : Poetry ,
314322) -> None :
315323 tester .execute (f"--priority=default { source_default .name } { source_default .url } " )
324+ tester .io .fetch_error ()
316325 tester .io .fetch_output ()
317326
318327 name = getattr (source_existing .name , modifier )()
319328 tester .execute (f"--priority=default { name } { source_existing .url } " )
320329
321330 assert (
322331 tester .io .fetch_error ().strip ()
323- == f"Source with name { source_default .name } is already set to "
324- " default. Only one default source can be configured at a "
325- " time."
332+ == f"{ _get_source_warning ( source_default .priority ) } \n "
333+ f"Source with name { source_default . name } is already set to default. "
334+ " Only one default source can be configured at a time."
326335 )
327336 assert tester .io .fetch_output ().strip () == ""
328337 assert tester .status_code == 1
0 commit comments