|
7 | 7 |
|
8 | 8 | import pytest |
9 | 9 |
|
10 | | -from azpysdk.changelog import changelog, REPO_ROOT, _CHRONUS_MODULE_PATH |
| 10 | +from azpysdk.changelog import changelog, REPO_ROOT, _CHRONUS_MODULE_PATH, _CHANGE_KINDS |
11 | 11 |
|
12 | 12 |
|
13 | 13 | # --------------------------------------------------------------------------- |
@@ -47,6 +47,46 @@ def test_changelog_add_with_package(self): |
47 | 47 | assert args.changelog_command == "add" |
48 | 48 | assert args.package == "sdk/storage/azure-storage-blob" |
49 | 49 |
|
| 50 | + def test_changelog_add_with_kind(self): |
| 51 | + parser = _build_parser() |
| 52 | + args = parser.parse_args(["changelog", "add", "--kind", "breaking"]) |
| 53 | + assert args.kind == "breaking" |
| 54 | + |
| 55 | + def test_changelog_add_with_kind_short(self): |
| 56 | + parser = _build_parser() |
| 57 | + args = parser.parse_args(["changelog", "add", "-k", "feature"]) |
| 58 | + assert args.kind == "feature" |
| 59 | + |
| 60 | + def test_changelog_add_with_message(self): |
| 61 | + parser = _build_parser() |
| 62 | + args = parser.parse_args(["changelog", "add", "--message", "Fixed the bug"]) |
| 63 | + assert args.message == "Fixed the bug" |
| 64 | + |
| 65 | + def test_changelog_add_with_message_short(self): |
| 66 | + parser = _build_parser() |
| 67 | + args = parser.parse_args(["changelog", "add", "-m", "Added new API"]) |
| 68 | + assert args.message == "Added new API" |
| 69 | + |
| 70 | + def test_changelog_add_with_kind_and_message(self): |
| 71 | + parser = _build_parser() |
| 72 | + args = parser.parse_args( |
| 73 | + ["changelog", "add", "sdk/core/azure-core", "--kind", "breaking", "-m", "Removed old API"] |
| 74 | + ) |
| 75 | + assert args.package == "sdk/core/azure-core" |
| 76 | + assert args.kind == "breaking" |
| 77 | + assert args.message == "Removed old API" |
| 78 | + |
| 79 | + def test_changelog_add_invalid_kind_rejected(self): |
| 80 | + parser = _build_parser() |
| 81 | + with pytest.raises(SystemExit): |
| 82 | + parser.parse_args(["changelog", "add", "--kind", "notakind"]) |
| 83 | + |
| 84 | + def test_changelog_add_all_valid_kinds_accepted(self): |
| 85 | + parser = _build_parser() |
| 86 | + for kind in _CHANGE_KINDS: |
| 87 | + args = parser.parse_args(["changelog", "add", "--kind", kind]) |
| 88 | + assert args.kind == kind |
| 89 | + |
50 | 90 | def test_changelog_create(self): |
51 | 91 | parser = _build_parser() |
52 | 92 | args = parser.parse_args(["changelog", "create"]) |
@@ -146,6 +186,50 @@ def test_add_explicit_package_overrides_cwd(self, mock_which, mock_call, _mock_i |
146 | 186 | cmd = mock_call.call_args[0][0] |
147 | 187 | assert cmd == ["/usr/bin/npx", "--no", "chronus", "add", "sdk/core/azure-core"] |
148 | 188 |
|
| 189 | + @patch("azpysdk.changelog.changelog._is_chronus_installed", return_value=True) |
| 190 | + @patch("azpysdk.changelog.subprocess.call", return_value=0) |
| 191 | + @patch("azpysdk.changelog.shutil.which", return_value="/usr/bin/npx") |
| 192 | + def test_add_with_kind_passes_flag(self, mock_which, mock_call, _mock_installed): |
| 193 | + """The --kind flag should be forwarded to chronus.""" |
| 194 | + parser = _build_parser() |
| 195 | + args = parser.parse_args(["changelog", "add", "--kind", "breaking"]) |
| 196 | + with patch("os.getcwd", return_value=REPO_ROOT): |
| 197 | + result = args.func(args) |
| 198 | + assert result == 0 |
| 199 | + cmd = mock_call.call_args[0][0] |
| 200 | + assert cmd == ["/usr/bin/npx", "--no", "chronus", "add", "--kind", "breaking"] |
| 201 | + |
| 202 | + @patch("azpysdk.changelog.changelog._is_chronus_installed", return_value=True) |
| 203 | + @patch("azpysdk.changelog.subprocess.call", return_value=0) |
| 204 | + @patch("azpysdk.changelog.shutil.which", return_value="/usr/bin/npx") |
| 205 | + def test_add_with_message_passes_flag(self, mock_which, mock_call, _mock_installed): |
| 206 | + """The --message flag should be forwarded to chronus.""" |
| 207 | + parser = _build_parser() |
| 208 | + args = parser.parse_args(["changelog", "add", "-m", "Fixed upload bug"]) |
| 209 | + with patch("os.getcwd", return_value=REPO_ROOT): |
| 210 | + result = args.func(args) |
| 211 | + assert result == 0 |
| 212 | + cmd = mock_call.call_args[0][0] |
| 213 | + assert cmd == ["/usr/bin/npx", "--no", "chronus", "add", "--message", "Fixed upload bug"] |
| 214 | + |
| 215 | + @patch("azpysdk.changelog.changelog._is_chronus_installed", return_value=True) |
| 216 | + @patch("azpysdk.changelog.subprocess.call", return_value=0) |
| 217 | + @patch("azpysdk.changelog.shutil.which", return_value="/usr/bin/npx") |
| 218 | + def test_add_with_kind_message_and_package(self, mock_which, mock_call, _mock_installed): |
| 219 | + """All flags (package, --kind, --message) should be forwarded together.""" |
| 220 | + parser = _build_parser() |
| 221 | + args = parser.parse_args([ |
| 222 | + "changelog", "add", "sdk/core/azure-core", |
| 223 | + "--kind", "breaking", "-m", "Removed deprecated API", |
| 224 | + ]) |
| 225 | + result = args.func(args) |
| 226 | + assert result == 0 |
| 227 | + cmd = mock_call.call_args[0][0] |
| 228 | + assert cmd == [ |
| 229 | + "/usr/bin/npx", "--no", "chronus", "add", "sdk/core/azure-core", |
| 230 | + "--kind", "breaking", "--message", "Removed deprecated API", |
| 231 | + ] |
| 232 | + |
149 | 233 | @patch("azpysdk.changelog.changelog._is_chronus_installed", return_value=True) |
150 | 234 | @patch("azpysdk.changelog.subprocess.call", return_value=0) |
151 | 235 | @patch("azpysdk.changelog.shutil.which", return_value="/usr/bin/npx") |
|
0 commit comments