File: organization.py

package info (click to toggle)
python-releases 2.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 352 kB
  • sloc: python: 1,580; makefile: 11
file content (570 lines) | stat: -rw-r--r-- 19,083 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
from pytest import skip
from pytest_relaxed import raises
from docutils.nodes import list_item, raw, paragraph, Text

from releases import Issue, construct_releases

from _util import (
    b,
    f,
    s,
    changelog2dict,
    expect_releases,
    make_app,
    release_list,
    releases,
    setup_issues,
)


class organization:
    """
    Organization of issues into releases (parsing)
    """

    def setup_method(self):
        setup_issues(self)

    def _expect_entries(self, all_entries, in_, not_in):
        # Grab 2nd release as 1st is the empty 'beginning of time' one
        entries = releases(*all_entries)[1]["entries"]
        assert len(entries) == len(in_)
        for x in in_:
            assert x in entries
        for x in not_in:
            assert x not in entries

    def feature_releases_include_features_and_support_not_bugs(self):
        self._expect_entries(
            ["1.1.0", self.f, self.b, self.s], [self.f, self.s], [self.b]
        )

    def feature_releases_include_major_bugs(self):
        self._expect_entries(
            ["1.1.0", self.f, self.b, self.mb], [self.f, self.mb], [self.b]
        )

    def bugfix_releases_include_bugs(self):
        self._expect_entries(
            ["1.0.2", self.f, self.b, self.mb], [self.b], [self.mb, self.f]
        )

    def bugfix_releases_include_backported_features(self):
        self._expect_entries(
            ["1.0.2", self.bf, self.b, self.s], [self.b, self.bf], [self.s]
        )

    def bugfix_releases_include_backported_support(self):
        self._expect_entries(
            ["1.0.2", self.f, self.b, self.s, self.bs],
            [self.b, self.bs],
            [self.s, self.f],
        )

    def backported_features_also_appear_in_feature_releases(self):
        entries = ("1.1.0", "1.0.2", self.bf, self.b, self.s)
        # Ensure bf (backported feature) is in BOTH 1.0.2 AND 1.1.0
        expected = {"1.0.2": [self.bf, self.b], "1.1.0": [self.bf, self.s]}
        expect_releases(entries, expected)

    def unmarked_bullet_list_items_treated_as_bugs(self):
        fake = list_item("", paragraph("", "", raw("", "whatever")))
        changelog = releases("1.0.2", self.f, fake)
        entries = changelog[1]["entries"]
        assert len(entries) == 1
        assert self.f not in entries
        assert isinstance(entries[0], Issue)
        assert entries[0].number is None

    def unreleased_items_go_in_unreleased_releases(self):
        changelog = releases(self.f, self.b)
        # Should have two unreleased lists, one feature w/ feature, one bugfix
        # w/ bugfix.
        bugfix, feature = changelog[1:]
        assert len(feature["entries"]) == 1
        assert len(bugfix["entries"]) == 1
        assert self.f in feature["entries"]
        assert self.b in bugfix["entries"]
        assert feature["obj"].number == "unreleased_1.x_feature"
        assert bugfix["obj"].number == "unreleased_1.x_bugfix"

    def issues_consumed_by_releases_are_not_in_unreleased(self):
        changelog = releases("1.0.2", self.f, self.b, self.s, self.bs)
        release = changelog[1]["entries"]
        unreleased = changelog[-1]["entries"]
        assert self.b in release
        assert self.b not in unreleased

    def oddly_ordered_bugfix_releases_and_unreleased_list(self):
        # Release set up w/ non-contiguous feature+bugfix releases; catches
        # funky problems with 'unreleased' buckets
        b2 = b(2)
        f3 = f(3)
        changelog = releases("1.1.1", "1.0.2", self.f, b2, "1.1.0", f3, self.b)
        assert f3 in changelog[1]["entries"]
        assert b2 in changelog[2]["entries"]
        assert b2 in changelog[3]["entries"]

    def release_line_bugfix_specifier(self):
        b50 = b(50)
        b42 = b(42, spec="1.1+")
        f25 = f(25)
        b35 = b(35)
        b34 = b(34)
        f22 = f(22)
        b20 = b(20)
        c = changelog2dict(
            releases(
                "1.2.1",
                "1.1.2",
                "1.0.3",
                b50,
                b42,
                "1.2.0",
                "1.1.1",
                "1.0.2",
                f25,
                b35,
                b34,
                "1.1.0",
                "1.0.1",
                f22,
                b20,
            )
        )
        for rel, issues in (
            ("1.0.1", [b20]),
            ("1.1.0", [f22]),
            ("1.0.2", [b34, b35]),
            ("1.1.1", [b34, b35]),
            ("1.2.0", [f25]),
            ("1.0.3", [b50]),  # the crux - is not b50 + b42
            ("1.1.2", [b50, b42]),
            ("1.2.1", [b50, b42]),
        ):
            err = "Expected {} to contain {!r}, but it contained {!r}"
            got, expected = set(c[rel]), set(issues)
            assert got == expected, err.format(rel, expected, got)

    def releases_can_specify_issues_explicitly(self):
        # Build regular list-o-entries
        b2 = b(2)
        b3 = b(3)
        changelog = release_list(
            "1.0.1", "1.1.1", b3, b2, self.b, "1.1.0", self.f
        )
        # Modify 1.0.1 release to be speshul
        changelog[0][0].append(Text("2, 3"))
        rendered, _ = construct_releases(changelog, make_app())
        # 1.0.1 includes just 2 and 3, not bug 1
        one_0_1 = rendered[3]["entries"]
        one_1_1 = rendered[2]["entries"]
        assert self.b not in one_0_1
        assert b2 in one_0_1
        assert b3 in one_0_1
        # 1.1.1 includes all 3 (i.e. the explicitness of 1.0.1 didn't affect
        # the 1.1 line bucket.)
        assert self.b in one_1_1
        assert b2 in one_1_1
        assert b3 in one_1_1

    def explicit_release_list_split_works_with_unicode(self):
        changelog = release_list("1.0.1", b(17))
        changelog[0][0].append(Text(str("17")))
        # When using naive method calls, this explodes
        construct_releases(changelog, make_app())

    def explicit_feature_release_features_are_removed_from_unreleased(self):
        f1 = f(1)
        f2 = f(2)
        changelog = release_list("1.1.0", f1, f2)
        # Ensure that 1.1.0 specifies feature 2
        changelog[0][0].append(Text("2"))
        rendered = changelog2dict(construct_releases(changelog, make_app())[0])
        # 1.1.0 should have feature 2 only
        assert f2 in rendered["1.1.0"]
        assert f1 not in rendered["1.1.0"]
        # unreleased feature list should still get/see feature 1
        assert f1 in rendered["unreleased_1.x_feature"]
        # now-released feature 2 should not be in unreleased_feature
        assert f2 not in rendered["unreleased_1.x_feature"]

    class unsupported_families_not_included_in_unreleased:
        _entries = (
            f(7),  # should appear in unreleased features for 3.x
            b(6),  # should appear in unreleased bugs for 3.x
            "3.0.0",
            f(5),  # should appear in unreleased features for 2.x
            b(4),  # should appear in unreleased bugs for 2.x
            "2.0.0",
            f(3),  # should appear in unreleased features for 1.x
            b(2),  # should appear in unreleased bugs for 1.x
            "1.0.1",
            b(1),  # prehistory
        )

        def no_actual_hiding_when_given_but_contains_all_families(self):
            # Expectation: everything
            families = [1, 2, 3]
            for option in (None, families):  # Also test default None
                changelog = release_list(*self._entries)
                releases = changelog2dict(
                    construct_releases(
                        changelog, make_app(supported_versions=option)
                    )[0]
                )
                for major in families:
                    for type_ in ("bugfix", "feature"):
                        assert f"unreleased_{major}.x_{type_}" in releases

        def one_old_family_hidden(self):
            changelog = release_list(*self._entries)
            releases = changelog2dict(
                construct_releases(
                    changelog, make_app(supported_versions=[2, 3])
                )[0]
            )
            for type_ in ("bugfix", "feature"):
                assert f"unreleased_1.x_{type_}" not in releases
                assert f"unreleased_2.x_{type_}" in releases
                assert f"unreleased_3.x_{type_}" in releases

        def multiple_old_families_hidden(self):
            changelog = release_list(*self._entries)
            releases = changelog2dict(
                construct_releases(
                    changelog, make_app(supported_versions=[3])
                )[0]
            )
            for type_ in ("bugfix", "feature"):
                assert f"unreleased_1.x_{type_}" not in releases
                assert f"unreleased_2.x_{type_}" not in releases
                assert f"unreleased_3.x_{type_}" in releases

        def in_between_family_hidden_for_mysterious_reasons(self):
            changelog = release_list(*self._entries)
            releases = changelog2dict(
                construct_releases(
                    changelog, make_app(supported_versions=[1, 3])
                )[0]
            )
            for type_ in ("bugfix", "feature"):
                assert f"unreleased_1.x_{type_}" in releases
                assert f"unreleased_2.x_{type_}" not in releases
                assert f"unreleased_3.x_{type_}" in releases

    def explicit_bugfix_releases_get_removed_from_unreleased(self):
        b1 = b(1)
        b2 = b(2)
        changelog = release_list("1.0.1", b1, b2)
        # Ensure that 1.0.1 specifies bug 2
        changelog[0][0].append(Text("2"))
        rendered, _ = construct_releases(changelog, make_app())
        # 1.0.1 should have bug 2 only
        assert b2 in rendered[1]["entries"]
        assert b1 not in rendered[1]["entries"]
        # unreleased bug list should still get/see bug 1
        assert b1 in rendered[2]["entries"]

    @raises(ValueError)
    def explicit_releases_error_on_unfound_issues(self):
        # Just a release - result will have 1.0.0, 1.0.1, and unreleased
        changelog = release_list("1.0.1")
        # No issues listed -> this clearly doesn't exist in any buckets
        changelog[1][0].append(Text("25"))
        # This should asplode
        construct_releases(changelog, make_app())

    def duplicate_issue_numbers_adds_two_issue_items(self):
        test_changelog = releases("1.0.1", self.b, self.b)
        test_changelog = changelog2dict(test_changelog)
        assert len(test_changelog["1.0.1"]) == 2

    def duplicate_zeroes_dont_error(self):
        cl = releases("1.0.1", b(0), b(0))
        cl = changelog2dict(cl)
        assert len(cl["1.0.1"]) == 2

    def issues_are_sorted_by_type_within_releases(self):
        b1 = b(123, major=True)
        b2 = b(124, major=True)
        s1 = s(25)
        s2 = s(26)
        f1 = f(3455)
        f2 = f(3456)

        # Semi random definitely-not-in-desired-order order
        changelog = changelog2dict(releases("1.1", b1, s1, s2, f1, b2, f2))

        # Order should be feature, bug, support. While it doesn't REALLY
        # matter, assert that within each category the order matches the old
        # 'reverse chronological' order.
        assert changelog["1.1"], [f2, f1, b2, b1, s2 == s1]

    def rolling_release_works_without_annotation(self):
        b1 = b(1)
        b2 = b(2)
        f3 = f(3)
        f4 = f(4)
        f5 = f(5)
        b6 = b(6)
        f7 = f(7)
        entries = (
            "2.1.0",
            "2.0.1",
            f7,
            b6,
            "2.0.0",
            f5,
            f4,
            "1.1.0",
            "1.0.1",
            f3,
            b2,
            b1,
        )
        expected = {
            "1.0.1": [b1, b2],
            "1.1.0": [f3],
            "2.0.0": [f4, f5],
            "2.0.1": [b6],
            "2.1.0": [f7],
        }
        expect_releases(entries, expected)

    def plus_annotations_let_old_lines_continue_getting_released(self):
        b9 = b(9)
        f8 = f(8)
        f7 = f(7, spec="1.0+")
        b6 = b(6, spec="1.0+")
        f5 = f(5)
        f4 = f(4)
        f3 = f(3)
        b2 = b(2)
        b1 = b(1)
        entries = (
            "2.1.0",
            "2.0.1",
            "1.2.0",
            "1.1.1",
            "1.0.2",
            b9,
            f8,
            f7,
            b6,
            "2.0.0",
            f5,
            f4,
            "1.1.0",
            "1.0.1",
            f3,
            b2,
            b1,
        )
        expected = {
            "2.1.0": [f7, f8],
            "2.0.1": [b6, b9],
            "1.2.0": [f7],  # but not f8
            "1.1.1": [b6],  # but not b9
            "1.0.2": [b6],  # but not b9
            "2.0.0": [f4, f5],
            "1.1.0": [f3],
            "1.0.1": [b1, b2],
        }
        expect_releases(entries, expected)

    def semver_spec_annotations_allow_preventing_forward_porting(self):
        f9 = f(9, spec=">=1.0")
        f8 = f(8)
        b7 = b(7, spec="<2.0")
        b6 = b(6, spec="1.0+")
        f5 = f(5)
        f4 = f(4)
        f3 = f(3)
        b2 = b(2)
        b1 = b(1)

        entries = (
            "2.1.0",
            "2.0.1",
            "1.2.0",
            "1.1.1",
            "1.0.2",
            f9,
            f8,
            b7,
            b6,
            "2.0.0",
            f5,
            f4,
            "1.1.0",
            "1.0.1",
            f3,
            b2,
            b1,
        )

        expected = {
            "2.1.0": [f8, f9],
            "2.0.1": [b6],  # (but not #7)
            "1.2.0": [f9],  # (but not #8)
            "1.1.1": [b6, b7],
            "1.0.2": [b6, b7],
            "2.0.0": [f4, f5],
            "1.1.0": [f3],
            "1.0.1": [b1, b2],
        }
        expect_releases(entries, expected)

    def bugs_before_major_releases_associate_with_previous_release_only(self):
        b1 = b(1)
        b2 = b(2)
        f3 = f(3)
        f4 = f(4)
        f5 = f(5, spec="<2.0")
        b6 = b(6)

        entries = (
            "2.0.0",
            "1.2.0",
            "1.1.1",
            b6,
            f5,
            f4,
            "1.1.0",
            "1.0.1",
            f3,
            b2,
            b1,
        )

        expected = {
            "2.0.0": [f4],  # but not f5
            "1.2.0": [f5],  # but not f4
            "1.1.1": [b6],
            "1.1.0": [f3],
            "1.0.1": [b1, b2],
        }
        expect_releases(entries, expected)

    def semver_double_ended_specs_work_when_more_than_two_major_versions(self):
        skip()

    def can_disable_default_pin_to_latest_major_version(self):
        skip()

    def features_before_first_release_function_correctly(self):
        f0 = f(0)
        b1 = b(1)
        f2 = f(2)
        entries = ("0.2.0", f2, "0.1.1", b1, "0.1.0", f0)
        expected = {"0.1.0": [f0], "0.1.1": [b1], "0.2.0": [f2]}
        # Make sure to skip typically-implicit 1.0.0 release.
        # TODO: consider removing that entirely; arguably needing it is a bug?
        expect_releases(entries, expected, skip_initial=True)

    def all_bugs_before_first_release_act_featurelike(self):
        b1 = b(1)
        f2 = f(2)
        b3 = b(3)
        implicit = list_item("", paragraph("", "", raw("", "whatever")))
        changelog = changelog2dict(
            releases("0.1.1", b3, "0.1.0", f2, b1, implicit, skip_initial=True)
        )
        first = changelog["0.1.0"]
        second = changelog["0.1.1"]
        assert b1 in first
        assert f2 in first
        assert len(first) == 3  # Meh, hard to assert about the implicit one
        assert second == [b3]

    def specs_and_keywords_play_together_nicely(self):
        b1 = b(1)
        b2 = b(2, major=True, spec="1.0+")
        f3 = f(3)
        # Feature copied to both 1.x and 2.x branches
        f4 = f(4, spec="1.0+")
        # Support item backported to bugfix line + 1.17 + 2.0.0
        s5 = s(5, spec="1.0+", backported=True)
        entries = ("2.0.0", "1.17.0", "1.16.1", s5, f4, f3, b2, b1, "1.16.0")
        expected = {
            "1.16.1": [b1, s5],  # s5 backported ok
            "1.17.0": [b2, f4, s5],  # s5 here too, plus major bug b2
            "2.0.0": [b2, f3, f4, s5],  # all featurelike items here
        }
        expect_releases(entries, expected)

    def changelogs_without_any_releases_display_unreleased_normally(self):
        changelog = releases(self.f, self.b, skip_initial=True)
        # Ensure only the two unreleased 'releases' showed up
        assert len(changelog) == 2
        # And assert that both items appeared in one of them (since there's no
        # real releases at all, the bugfixes are treated as 'major' bugs, as
        # per concepts doc.)
        bugfix, feature = changelog
        assert len(feature["entries"]) == 2
        assert len(bugfix["entries"]) == 0

    class unstable_prehistory:
        def _expect_releases(self, *args, **kwargs):
            """
            expect_releases() wrapper setting unstable_prehistory by default
            """
            kwargs["app"] = make_app(unstable_prehistory=True)
            return expect_releases(*args, **kwargs)

        def all_issue_types_rolled_up_together(self):
            # Pre-1.0-only base case
            entries = ("0.1.1", f(4), b(3), "0.1.0", f(2), b(1))
            expected = {"0.1.1": [b(3), f(4)], "0.1.0": [b(1), f(2)]}
            self._expect_releases(entries, expected, skip_initial=True)

        def does_not_affect_releases_after_1_0(self):
            # Mixed changelog crossing 1.0 boundary
            entries = (
                "1.1.0",
                "1.0.1",
                f(6),
                b(5),
                "1.0.0",
                f(4),
                b(3),
                "0.1.0",
                f(2),
                b(1),
            )
            expected = {
                "1.1.0": [f(6)],
                "1.0.1": [b(5)],
                "1.0.0": [b(3), f(4)],
                "0.1.0": [b(1), f(2)],
            }
            self._expect_releases(entries, expected, skip_initial=True)

        def doesnt_care_if_you_skipped_1_0_entirely(self):
            # Mixed changelog where 1.0 is totally skipped and one goes to 2.0
            entries = (
                "2.1.0",
                "2.0.1",
                f(6),
                b(5),
                "2.0.0",
                f(4),
                b(3),
                "0.1.0",
                f(2),
                b(1),
            )
            expected = {
                "2.1.0": [f(6)],
                "2.0.1": [b(5)],
                "2.0.0": [b(3), f(4)],
                "0.1.0": [b(1), f(2)],
            }
            self._expect_releases(entries, expected, skip_initial=True)

        def explicit_unstable_releases_still_eat_their_issues(self):
            # I.e. an 0.x.y releases using explicit issue listings, works
            # correctly - the explicitly listed issues don't appear in nearby
            # implicit releases.
            skip()