File: test_semver.py

package info (click to toggle)
python-reno 4.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 776 kB
  • sloc: python: 5,263; makefile: 21; sh: 10
file content (169 lines) | stat: -rw-r--r-- 6,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
# -*- coding: utf-8 -*-

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import collections
from unittest import mock

import fixtures
import textwrap


from reno import config
from reno import semver
from reno.tests import base


class TestSemVer(base.TestCase):

    note_bodies = {
        'none': textwrap.dedent("""
        prelude: >
          This should not cause any version update.
        """),
        'major': textwrap.dedent("""
        upgrade:
          - This should cause a major version update.
        """),
        'minor': textwrap.dedent("""
        features:
          - This should cause a minor version update.
        """),
        'patch': textwrap.dedent("""
        fixes:
          - This should cause a patch version update.
        """),
    }

    def _get_note_body(self, filename, sha):
        return self.note_bodies.get(filename, '')

    def _get_dates(self):
        return {'1.0.0': 1547874431}

    def setUp(self):
        super(TestSemVer, self).setUp()
        self.useFixture(
            fixtures.MockPatch('reno.scanner.Scanner.get_file_at_commit',
                               new=self._get_note_body)
        )
        self.useFixture(
            fixtures.MockPatch('reno.scanner.Scanner.get_version_dates',
                               new=self._get_dates)
        )
        self.c = config.Config('.')

    @mock.patch('reno.scanner.Scanner.get_notes_by_version')
    def test_same(self, mock_get_notes):
        mock_get_notes.return_value = collections.OrderedDict([
            ('1.1.1', []),
        ])
        expected = '1.1.1'
        actual = semver.compute_next_version(self.c)
        self.assertEqual(expected, actual)

    @mock.patch('reno.scanner.Scanner.get_notes_by_version')
    def test_same_with_note(self, mock_get_notes):
        mock_get_notes.return_value = collections.OrderedDict([
            ('1.1.1', [('none', 'shaA')]),
        ])
        expected = '1.1.1'
        actual = semver.compute_next_version(self.c)
        self.assertEqual(expected, actual)

    @mock.patch('reno.scanner.Scanner.get_notes_by_version')
    def test_major_working_copy(self, mock_get_notes):
        mock_get_notes.return_value = collections.OrderedDict([
            ('*working-copy*', [('major', 'shaA')]),
            ('1.1.1', []),
        ])
        expected = '2.0.0'
        actual = semver.compute_next_version(self.c)
        self.assertEqual(expected, actual)

    @mock.patch('reno.scanner.Scanner.get_notes_by_version')
    def test_major_working_and_post_release(self, mock_get_notes):
        mock_get_notes.return_value = collections.OrderedDict([
            ('*working-copy*', [('none', 'shaA')]),
            ('1.1.1-1', [('major', 'shaA')]),
        ])
        expected = '2.0.0'
        actual = semver.compute_next_version(self.c)
        self.assertEqual(expected, actual)

    @mock.patch('reno.scanner.Scanner.get_notes_by_version')
    def test_major_post_release(self, mock_get_notes):
        mock_get_notes.return_value = collections.OrderedDict([
            ('1.1.1-1', [('major', 'shaA')]),
        ])
        expected = '2.0.0'
        actual = semver.compute_next_version(self.c)
        self.assertEqual(expected, actual)

    @mock.patch('reno.scanner.Scanner.get_notes_by_version')
    def test_minor_working_copy(self, mock_get_notes):
        mock_get_notes.return_value = collections.OrderedDict([
            ('*working-copy*', [('minor', 'shaA')]),
            ('1.1.1', []),
        ])
        expected = '1.2.0'
        actual = semver.compute_next_version(self.c)
        self.assertEqual(expected, actual)

    @mock.patch('reno.scanner.Scanner.get_notes_by_version')
    def test_minor_working_and_post_release(self, mock_get_notes):
        mock_get_notes.return_value = collections.OrderedDict([
            ('*working-copy*', [('none', 'shaA')]),
            ('1.1.1-1', [('minor', 'shaA')]),
        ])
        expected = '1.2.0'
        actual = semver.compute_next_version(self.c)
        self.assertEqual(expected, actual)

    @mock.patch('reno.scanner.Scanner.get_notes_by_version')
    def test_minor_post_release(self, mock_get_notes):
        mock_get_notes.return_value = collections.OrderedDict([
            ('1.1.1-1', [('minor', 'shaA')]),
        ])
        expected = '1.2.0'
        actual = semver.compute_next_version(self.c)
        self.assertEqual(expected, actual)

    @mock.patch('reno.scanner.Scanner.get_notes_by_version')
    def test_patch_working_copy(self, mock_get_notes):
        mock_get_notes.return_value = collections.OrderedDict([
            ('*working-copy*', [('patch', 'shaA')]),
            ('1.1.1', []),
        ])
        expected = '1.1.2'
        actual = semver.compute_next_version(self.c)
        self.assertEqual(expected, actual)

    @mock.patch('reno.scanner.Scanner.get_notes_by_version')
    def test_patch_working_and_post_release(self, mock_get_notes):
        mock_get_notes.return_value = collections.OrderedDict([
            ('*working-copy*', [('none', 'shaA')]),
            ('1.1.1-1', [('patch', 'shaA')]),
        ])
        expected = '1.1.2'
        actual = semver.compute_next_version(self.c)
        self.assertEqual(expected, actual)

    @mock.patch('reno.scanner.Scanner.get_notes_by_version')
    def test_patch_post_release(self, mock_get_notes):
        mock_get_notes.return_value = collections.OrderedDict([
            ('1.1.1-1', [('patch', 'shaA')]),
        ])
        expected = '1.1.2'
        actual = semver.compute_next_version(self.c)
        self.assertEqual(expected, actual)