File: test_whatsnew.py

package info (click to toggle)
pypy3 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,848 kB
  • sloc: python: 1,291,746; ansic: 74,281; asm: 5,187; cpp: 3,017; sh: 2,533; makefile: 544; xml: 243; lisp: 45; csh: 21; awk: 4
file content (116 lines) | stat: -rw-r--r-- 3,633 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
import py
import pypy
from commands import getoutput, getstatusoutput
ROOT = py.path.local(pypy.__file__).dirpath().dirpath()


def parse_doc(s):
    startrev = None
    branches = set()
    def parseline(line):
        _, value = line.split(':', 1)
        return value.strip()
    #
    for line in s.splitlines():
        if line.startswith('.. startrev:'):
            startrev = parseline(line)
        elif line.startswith('.. branch:'):
            branches.add(parseline(line))
    branches.discard('default')
    return startrev, branches

def get_merged_branches(path, startrev, endrev, current_branch=None):
    errcode, wc_branch = getstatusoutput('hg branch')
    if errcode != 0:
        py.test.skip('no Mercurial repo')
    if current_branch is None:
        current_branch = wc_branch

    # X = take all the merges which are descendants of startrev and are on default
    # revset = all the parents of X which are not on default
    # ===>
    # revset contains all the branches which have been merged to default since
    # startrev
    revset = "parents(%s::%s and \
                      merge() and \
                      branch('%s')) and \
              not branch('%s')" % (startrev, endrev,
                                   current_branch, current_branch)
    cmd = r'hg log -R "%s" -r "%s" --template "{branches}\n"' % (path, revset)
    out = getoutput(cmd)
    branches = set()
    for item in out.splitlines():
        item = item.strip()
        if not item.startswith('release-'):
            branches.add(item)
    branches.discard("default")
    return branches, current_branch


def test_parse_doc():
    s = """
=====
Title
=====

.. startrev: 12345

bla bla bla bla

.. branch: foobar

xxx yyy zzz

.. branch: hello

qqq www ttt

.. branch: default

"default" should be ignored and not put in the set of documented branches
"""
    startrev, branches = parse_doc(s)
    assert startrev == '12345'
    assert branches == set(['foobar', 'hello'])

def test_get_merged_branches():
    branches, _ = get_merged_branches(ROOT, 'f34f0c11299f', '79770e0c2f93',
                                      'default')
    assert branches == set(['numpy-indexing-by-arrays-bool',
                            'better-jit-hooks-2',
                            'numpypy-ufuncs'])

def test_whatsnew():
    doc = ROOT.join('pypy', 'doc')
    #whatsnew_list = doc.listdir('whatsnew-*.rst')
    #whatsnew_list.sort()
    #last_whatsnew = whatsnew_list[-1].read()
    last_whatsnew = doc.join('whatsnew-pypy3-head.rst').read()
    startrev, documented = parse_doc(last_whatsnew)
    merged, branch = get_merged_branches(ROOT, startrev, '')
    merged.discard('default')
    merged.discard('py3.5')
    merged.discard('')
    not_documented = merged.difference(documented)
    not_merged = documented.difference(merged)
    print 'Branches merged but not documented:'
    print '\n'.join(not_documented)
    print
    print 'Branches documented but not merged:'
    print '\n'.join(not_merged)
    print
    assert not not_documented
    if branch == 'py3.5':
        assert not not_merged
    else:
        assert branch in documented, 'Please document this branch before merging: %s' % branch

def test_startrev_on_default():
    doc = ROOT.join('pypy', 'doc')
    last_whatsnew = doc.join('whatsnew-head.rst').read()
    startrev, documented = parse_doc(last_whatsnew)
    errcode, wc_branch = getstatusoutput(
        "hg log -r %s --template '{branch}'" % startrev)
    if errcode != 0:
        py.test.skip('no Mercurial repo')
    assert wc_branch in ('default', "'default'") # sometimes the ' leaks (windows)