@@ -22,27 +22,34 @@ def tester(
22
22
return command_tester_factory ("source add" , poetry = poetry_with_source )
23
23
24
24
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
+
25
41
def assert_source_added_legacy (
26
42
tester : CommandTester ,
27
43
poetry : Poetry ,
28
44
source_existing : Source ,
29
45
source_added : Source ,
30
46
) -> 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 )
45
51
)
52
+ assert tester .io .fetch_error ().strip () == warning
46
53
assert (
47
54
tester .io .fetch_output ().strip ()
48
55
== f"Adding source with name { source_added .name } ."
@@ -59,6 +66,7 @@ def assert_source_added(
59
66
source_existing : Source ,
60
67
source_added : Source ,
61
68
) -> None :
69
+ assert tester .io .fetch_error ().strip () == _get_source_warning (source_added .priority )
62
70
assert (
63
71
tester .io .fetch_output ().strip ()
64
72
== f"Adding source with name { source_added .name } ."
@@ -126,9 +134,9 @@ def test_source_add_second_default_fails(
126
134
tester .execute (f"--priority=default { source_default .name } 1 { source_default .url } " )
127
135
assert (
128
136
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."
132
140
)
133
141
assert tester .status_code == 1
134
142
@@ -238,7 +246,7 @@ def test_source_add_existing_legacy(
238
246
tester .io .fetch_error ().strip ()
239
247
== "Warning: Priority was set through a deprecated flag"
240
248
" (--default or --secondary). Consider using --priority next"
241
- " time."
249
+ f " time.\n { _get_source_warning ( Priority . DEFAULT ) } "
242
250
)
243
251
assert (
244
252
tester .io .fetch_output ().strip ()
@@ -313,16 +321,17 @@ def test_source_add_existing_fails_due_to_other_default(
313
321
poetry_with_source : Poetry ,
314
322
) -> None :
315
323
tester .execute (f"--priority=default { source_default .name } { source_default .url } " )
324
+ tester .io .fetch_error ()
316
325
tester .io .fetch_output ()
317
326
318
327
name = getattr (source_existing .name , modifier )()
319
328
tester .execute (f"--priority=default { name } { source_existing .url } " )
320
329
321
330
assert (
322
331
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."
326
335
)
327
336
assert tester .io .fetch_output ().strip () == ""
328
337
assert tester .status_code == 1
0 commit comments