|
6 | 6 | import sys |
7 | 7 |
|
8 | 8 | from subprocess import PIPE, Popen, call |
| 9 | +from unittest.mock import patch |
9 | 10 |
|
10 | 11 | from click.testing import CliRunner |
11 | 12 | from twisted.trial.unittest import TestCase |
12 | 13 |
|
| 14 | +from towncrier import check |
13 | 15 | from towncrier.check import _main as towncrier_check |
14 | 16 |
|
15 | 17 |
|
@@ -271,3 +273,47 @@ def test_release_branch(self): |
271 | 273 | # Assert |
272 | 274 | self.assertEqual(0, result.exit_code, (result, result.output)) |
273 | 275 | self.assertIn("Checks SKIPPED: news file changes detected", result.output) |
| 276 | + |
| 277 | + def test_get_default_compare_branch_missingf(self): |
| 278 | + """ |
| 279 | + If there's no recognized remote origin, exit with an error. |
| 280 | + """ |
| 281 | + runner = CliRunner() |
| 282 | + |
| 283 | + with runner.isolated_filesystem(): |
| 284 | + create_project() |
| 285 | + |
| 286 | + result = runner.invoke(towncrier_check) |
| 287 | + |
| 288 | + self.assertEqual(1, result.exit_code) |
| 289 | + self.assertEqual("Could not detect default branch. Aborting.\n", result.output) |
| 290 | + |
| 291 | + def test_get_default_compare_branch_main(self): |
| 292 | + """ |
| 293 | + If there's a remote branch origin/main, prefer it over everything else. |
| 294 | + """ |
| 295 | + runner = CliRunner() |
| 296 | + |
| 297 | + with runner.isolated_filesystem(): |
| 298 | + create_project() |
| 299 | + |
| 300 | + with patch("towncrier.check._run") as m: |
| 301 | + m.return_value = b" origin/master\n origin/main\n\n" |
| 302 | + branch = check.get_default_compare_branch(".", "utf-8") |
| 303 | + |
| 304 | + self.assertEqual("origin/main", branch) |
| 305 | + |
| 306 | + def test_get_default_compare_branch_fallback(self): |
| 307 | + """ |
| 308 | + If there's origin/master and no main, use it. |
| 309 | + """ |
| 310 | + runner = CliRunner() |
| 311 | + |
| 312 | + with runner.isolated_filesystem(): |
| 313 | + create_project() |
| 314 | + |
| 315 | + with patch("towncrier.check._run") as m: |
| 316 | + m.return_value = b" origin/master\n origin/foo\n\n" |
| 317 | + branch = check.get_default_compare_branch(".", "utf-8") |
| 318 | + |
| 319 | + self.assertEqual("origin/master", branch) |
0 commit comments