|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# Copyright (C) 2020 Greenbone Networks GmbH |
|
3
|
|
|
# |
|
4
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later |
|
5
|
|
|
# |
|
6
|
|
|
# This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
# it under the terms of the GNU General Public License as published by |
|
8
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
# (at your option) any later version. |
|
10
|
|
|
# |
|
11
|
|
|
# This program is distributed in the hope that it will be useful, |
|
12
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
# GNU General Public License for more details. |
|
15
|
|
|
# |
|
16
|
|
|
# You should have received a copy of the GNU General Public License |
|
17
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
|
|
19
|
|
|
import unittest |
|
20
|
|
|
|
|
21
|
|
|
from pathlib import Path |
|
22
|
|
|
from unittest.mock import MagicMock |
|
23
|
|
|
|
|
24
|
|
|
import tomlkit |
|
25
|
|
|
from gvm.version import update_pyproject_version |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
class UpdatePyprojectVersionTestCase(unittest.TestCase): |
|
29
|
|
View Code Duplication |
def test_empty_pyproject_toml(self): |
|
|
|
|
|
|
30
|
|
|
fake_path_class = MagicMock(spec=Path) |
|
31
|
|
|
fake_path = fake_path_class.return_value |
|
32
|
|
|
fake_path.read_text.return_value = "" |
|
33
|
|
|
|
|
34
|
|
|
update_pyproject_version('20.04dev1', pyproject_toml_path=fake_path) |
|
35
|
|
|
|
|
36
|
|
|
text = fake_path.write_text.call_args[0][0] |
|
37
|
|
|
|
|
38
|
|
|
toml = tomlkit.parse(text) |
|
39
|
|
|
|
|
40
|
|
|
self.assertEqual(toml['tool']['poetry']['version'], '20.4.dev1') |
|
41
|
|
|
|
|
42
|
|
View Code Duplication |
def test_empty_tool_section(self): |
|
|
|
|
|
|
43
|
|
|
fake_path_class = MagicMock(spec=Path) |
|
44
|
|
|
fake_path = fake_path_class.return_value |
|
45
|
|
|
fake_path.read_text.return_value = "[tool]" |
|
46
|
|
|
|
|
47
|
|
|
update_pyproject_version('20.04dev1', pyproject_toml_path=fake_path) |
|
48
|
|
|
|
|
49
|
|
|
text = fake_path.write_text.call_args[0][0] |
|
50
|
|
|
|
|
51
|
|
|
toml = tomlkit.parse(text) |
|
52
|
|
|
|
|
53
|
|
|
self.assertEqual(toml['tool']['poetry']['version'], '20.4.dev1') |
|
54
|
|
|
|
|
55
|
|
View Code Duplication |
def test_empty_tool_poetry_section(self): |
|
|
|
|
|
|
56
|
|
|
fake_path_class = MagicMock(spec=Path) |
|
57
|
|
|
fake_path = fake_path_class.return_value |
|
58
|
|
|
fake_path.read_text.return_value = "[tool.poetry]" |
|
59
|
|
|
|
|
60
|
|
|
update_pyproject_version('20.04dev1', pyproject_toml_path=fake_path) |
|
61
|
|
|
|
|
62
|
|
|
text = fake_path.write_text.call_args[0][0] |
|
63
|
|
|
|
|
64
|
|
|
toml = tomlkit.parse(text) |
|
65
|
|
|
|
|
66
|
|
|
self.assertEqual(toml['tool']['poetry']['version'], '20.4.dev1') |
|
67
|
|
|
|
|
68
|
|
View Code Duplication |
def test_override_existing_version(self): |
|
|
|
|
|
|
69
|
|
|
fake_path_class = MagicMock(spec=Path) |
|
70
|
|
|
fake_path = fake_path_class.return_value |
|
71
|
|
|
fake_path.read_text.return_value = '[tool.poetry]\nversion = "1.2.3"' |
|
72
|
|
|
|
|
73
|
|
|
update_pyproject_version('20.04dev1', pyproject_toml_path=fake_path) |
|
74
|
|
|
|
|
75
|
|
|
text = fake_path.write_text.call_args[0][0] |
|
76
|
|
|
|
|
77
|
|
|
toml = tomlkit.parse(text) |
|
78
|
|
|
|
|
79
|
|
|
self.assertEqual(toml['tool']['poetry']['version'], '20.4.dev1') |
|
80
|
|
|
|