22# See LICENSE for details.
33
44import os .path
5+ import unittest
56
67from pathlib import Path
78
@@ -26,57 +27,65 @@ def novcs_commit(message):
2627
2728
2829class TestVCS (TestCase ):
29- def test_vcs (self ):
30- for tt in [
30+ def do_test_vcs (self ,vcs ):
31+ create_project = vcs ["create_project" ]
32+ commit = vcs ["commit" ]
33+
34+ runner = CliRunner ()
35+ with runner .isolated_filesystem ():
36+ create_project ("pyproject.toml" )
37+
38+ write ("changes/000.misc.rst" ,"some change" )
39+
40+ _vcs .stage_newsfile (os .getcwd (),"changes/000.misc.rst" )
41+
42+ commit ("commit 1" )
43+
44+ branches = sorted (_vcs .get_remote_branches ("." ))
45+ self .assertIn (branches , [[], ["main" ,"otherbranch" ]])
46+
47+ if vcs ["name" ]!= "novcs" :
48+ self .assertIn (
49+ _vcs .list_changed_files_compared_to_branch ("." ,"main" ,False ),
50+ [
51+ ["changes/000.misc.rst" ],
52+ [os .path .join ("changes" ,"000.misc.rst" )],
53+ ],
54+ )
55+
56+ write ("changes/001.misc.rst" ,"some change" )
57+ _vcs .remove_files (
58+ os .getcwd (),
59+ [
60+ os .path .abspath (f )
61+ for f in ["changes/000.misc.rst" ,"changes/001.misc.rst" ]
62+ ],
63+ )
64+
65+ def test_git (self ):
66+ self .do_test_vcs (
3167 {
3268"name" :"git" ,
3369"create_project" :test_check .create_project ,
3470"commit" :test_check .commit ,
3571 },
72+ )
73+
74+ @unittest .skipUnless (test_hg .hg_available ,"requires 'mercurial' to be installed" )
75+ def test_mercurial (self ):
76+ self .do_test_vcs (
3677 {
3778"name" :"mercurial" ,
3879"create_project" :test_hg .create_project ,
3980"commit" :test_hg .commit ,
4081 },
82+ )
83+
84+ def test_novcs (self ):
85+ self .do_test_vcs (
4186 {
4287"name" :"novcs" ,
4388"create_project" :novcs_create_project ,
4489"commit" :novcs_commit ,
4590 },
46- ]:
47- with self .subTest (tt ["name" ]):
48- create_project = tt ["create_project" ]
49- commit = tt ["commit" ]
50-
51- runner = CliRunner ()
52- with runner .isolated_filesystem ():
53- create_project ("pyproject.toml" )
54-
55- write ("changes/000.misc.rst" ,"some change" )
56-
57- _vcs .stage_newsfile (os .getcwd (),"changes/000.misc.rst" )
58-
59- commit ("commit 1" )
60-
61- branches = sorted (_vcs .get_remote_branches ("." ))
62- self .assertIn (branches , [[], ["main" ,"otherbranch" ]])
63-
64- if tt ["name" ]!= "novcs" :
65- self .assertIn (
66- _vcs .list_changed_files_compared_to_branch (
67- "." ,"main" ,False
68- ),
69- [
70- ["changes/000.misc.rst" ],
71- [os .path .join ("changes" ,"000.misc.rst" )],
72- ],
73- )
74-
75- write ("changes/001.misc.rst" ,"some change" )
76- _vcs .remove_files (
77- os .getcwd (),
78- [
79- os .path .abspath (f )
80- for f in ["changes/000.misc.rst" ,"changes/001.misc.rst" ]
81- ],
82- )
91+ )