Debian Codegraph @

reno/tests/test_semver.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 import collections
16 from unittest import mock
17
18 import fixtures
19 import textwrap
20
21
22 from reno import config
23 from reno import semver
24 from reno.tests import base
25
26
27 class TestSemVer(base.TestCase):
28
29 note_bodies = {
30 'none': textwrap.dedent("""
31 prelude: >
32 This should not cause any version update.
33 """),
34 'major': textwrap.dedent("""
35 upgrade:
36 - This should cause a major version update.
37 """),
38 'minor': textwrap.dedent("""
39 features:
40 - This should cause a minor version update.
41 """),
42 'patch': textwrap.dedent("""
43 fixes:
44 - This should cause a patch version update.
45 """),
46 }
47
48 def _get_note_body(self, filename, sha):
49 return self.note_bodies.get(filename, '')
50
51 def _get_dates(self):
52 return {'1.0.0': 1547874431}
53
54 def setUp(self):
55 super(TestSemVer, self).setUp()
56 self.useFixture(
57 fixtures.MockPatch('reno.scanner.Scanner.get_file_at_commit',
58 new=self._get_note_body)
59 )
60 self.useFixture(
61 fixtures.MockPatch('reno.scanner.Scanner.get_version_dates',
62 new=self._get_dates)
63 )
64 self.c = config.Config('.')
65
66 @mock.patch('reno.scanner.Scanner.get_notes_by_version')
67 def test_same(self, mock_get_notes):
68 mock_get_notes.return_value = collections.OrderedDict([
69 ('1.1.1', []),
70 ])
71 expected = '1.1.1'
72 actual = semver.compute_next_version(self.c)
73 self.assertEqual(expected, actual)
74
75 @mock.patch('reno.scanner.Scanner.get_notes_by_version')
76 def test_same_with_note(self, mock_get_notes):
77 mock_get_notes.return_value = collections.OrderedDict([
78 ('1.1.1', [('none', 'shaA')]),
79 ])
80 expected = '1.1.1'
81 actual = semver.compute_next_version(self.c)
82 self.assertEqual(expected, actual)
83
84 @mock.patch('reno.scanner.Scanner.get_notes_by_version')
85 def test_major_working_copy(self, mock_get_notes):
86 mock_get_notes.return_value = collections.OrderedDict([
87 ('*working-copy*', [('major', 'shaA')]),
88 ('1.1.1', []),
89 ])
90 expected = '2.0.0'
91 actual = semver.compute_next_version(self.c)
92 self.assertEqual(expected, actual)
93
94 @mock.patch('reno.scanner.Scanner.get_notes_by_version')
95 def test_major_working_and_post_release(self, mock_get_notes):
96 mock_get_notes.return_value = collections.OrderedDict([
97 ('*working-copy*', [('none', 'shaA')]),
98 ('1.1.1-1', [('major', 'shaA')]),
99 ])
100 expected = '2.0.0'
101 actual = semver.compute_next_version(self.c)
102 self.assertEqual(expected, actual)
103
104 @mock.patch('reno.scanner.Scanner.get_notes_by_version')
105 def test_major_post_release(self, mock_get_notes):
106 mock_get_notes.return_value = collections.OrderedDict([
107 ('1.1.1-1', [('major', 'shaA')]),
108 ])
109 expected = '2.0.0'
110 actual = semver.compute_next_version(self.c)
111 self.assertEqual(expected, actual)
112
113 @mock.patch('reno.scanner.Scanner.get_notes_by_version')
114 def test_minor_working_copy(self, mock_get_notes):
115 mock_get_notes.return_value = collections.OrderedDict([
116 ('*working-copy*', [('minor', 'shaA')]),
117 ('1.1.1', []),
118 ])
119 expected = '1.2.0'
120 actual = semver.compute_next_version(self.c)
121 self.assertEqual(expected, actual)
122
123 @mock.patch('reno.scanner.Scanner.get_notes_by_version')
124 def test_minor_working_and_post_release(self, mock_get_notes):
125 mock_get_notes.return_value = collections.OrderedDict([
126 ('*working-copy*', [('none', 'shaA')]),
127 ('1.1.1-1', [('minor', 'shaA')]),
128 ])
129 expected = '1.2.0'
130 actual = semver.compute_next_version(self.c)
131 self.assertEqual(expected, actual)
132
133 @mock.patch('reno.scanner.Scanner.get_notes_by_version')
134 def test_minor_post_release(self, mock_get_notes):
135 mock_get_notes.return_value = collections.OrderedDict([
136 ('1.1.1-1', [('minor', 'shaA')]),
137 ])
138 expected = '1.2.0'
139 actual = semver.compute_next_version(self.c)
140 self.assertEqual(expected, actual)
141
142 @mock.patch('reno.scanner.Scanner.get_notes_by_version')
143 def test_patch_working_copy(self, mock_get_notes):
144 mock_get_notes.return_value = collections.OrderedDict([
145 ('*working-copy*', [('patch', 'shaA')]),
146 ('1.1.1', []),
147 ])
148 expected = '1.1.2'
149 actual = semver.compute_next_version(self.c)
150 self.assertEqual(expected, actual)
151
152 @mock.patch('reno.scanner.Scanner.get_notes_by_version')
153 def test_patch_working_and_post_release(self, mock_get_notes):
154 mock_get_notes.return_value = collections.OrderedDict([
155 ('*working-copy*', [('none', 'shaA')]),
156 ('1.1.1-1', [('patch', 'shaA')]),
157 ])
158 expected = '1.1.2'
159 actual = semver.compute_next_version(self.c)
160 self.assertEqual(expected, actual)
161
162 @mock.patch('reno.scanner.Scanner.get_notes_by_version')
163 def test_patch_post_release(self, mock_get_notes):
164 mock_get_notes.return_value = collections.OrderedDict([
165 ('1.1.1-1', [('patch', 'shaA')]),
166 ])
167 expected = '1.1.2'
168 actual = semver.compute_next_version(self.c)
169 self.assertEqual(expected, actual)