Skip to content

Commit 773ce32

Browse files
committed
alternate vcs: Fix unitests
1 parent 986d17c commit 773ce32

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

src/towncrier/_vcs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ def _get_mod(base_directory: str):
1212
from . import _hg
1313

1414
return _hg
15-
else:
15+
elif base_directory == "/":
1616
from . import _novcs
1717

1818
return _novcs
19+
else:
20+
return _get_mod(os.path.dirname(base_directory))
1921

2022

2123
def get_default_compare_branch(

src/towncrier/test/test_check.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -401,24 +401,6 @@ def test_get_default_compare_branch_missing(self):
401401
self.assertEqual(1, result.exit_code)
402402
self.assertEqual("Could not detect default branch. Aborting.\n", result.output)
403403

404-
def test_get_default_compare_branch_main(self):
405-
"""
406-
If there's a remote branch origin/main, prefer it over everything else.
407-
"""
408-
branch = check._get_default_compare_branch(["origin/master", "origin/main"])
409-
410-
self.assertEqual("origin/main", branch)
411-
412-
def test_get_default_compare_branch_fallback(self):
413-
"""
414-
If there's origin/master and no main, use it and warn about it.
415-
"""
416-
with warnings.catch_warnings(record=True) as w:
417-
branch = check._get_default_compare_branch(["origin/master", "origin/foo"])
418-
419-
self.assertEqual("origin/master", branch)
420-
self.assertTrue(w[0].message.args[0].startswith('Using "origin/master'))
421-
422404
@with_isolated_runner
423405
def test_in_different_dir_with_nondefault_newsfragments_directory(self, runner):
424406
"""
@@ -429,8 +411,7 @@ def test_in_different_dir_with_nondefault_newsfragments_directory(self, runner):
429411
Path("pyproject.toml").write_text(
430412
# Important to customize `config.directory` because the default
431413
# already supports this scenario.
432-
"[tool.towncrier]\n"
433-
+ 'directory = "changelog.d"\n'
414+
"[tool.towncrier]\n" + 'directory = "changelog.d"\n'
434415
)
435416
subproject1 = Path("foo")
436417
(subproject1 / "foo").mkdir(parents=True)

src/towncrier/test/test_git.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from twisted.trial.unittest import TestCase
66

77
from towncrier import _git
8+
import warnings
89

910

1011
class TestGit(TestCase):
@@ -13,3 +14,21 @@ def test_empty_remove(self):
1314
If remove_files gets an empty list, it returns gracefully.
1415
"""
1516
_git.remove_files([])
17+
18+
def test_get_default_compare_branch_main(self):
19+
"""
20+
If there's a remote branch origin/main, prefer it over everything else.
21+
"""
22+
branch = _git.get_default_compare_branch(["origin/master", "origin/main"])
23+
24+
self.assertEqual("origin/main", branch)
25+
26+
def test_get_default_compare_branch_fallback(self):
27+
"""
28+
If there's origin/master and no main, use it and warn about it.
29+
"""
30+
with warnings.catch_warnings(record=True) as w:
31+
branch = _git.get_default_compare_branch(["origin/master", "origin/foo"])
32+
33+
self.assertEqual("origin/master", branch)
34+
self.assertTrue(w[0].message.args[0].startswith('Using "origin/master'))

0 commit comments

Comments
 (0)