8
8
from click .testing import CliRunner
9
9
10
10
from libvcs .sync .git import GitSync
11
+ from vcspull .__about__ import __version__
11
12
from vcspull .cli import cli
12
13
from vcspull .cli .sync import EXIT_ON_ERROR_MSG , NO_REPOS_FOR_TERM_MSG
13
14
@@ -99,11 +100,96 @@ def test_sync_cli_repo_term_non_existent(
99
100
assert needle not in output
100
101
101
102
103
+ class SyncFixture (t .NamedTuple ):
104
+ test_id : str
105
+ sync_args : list [str ]
106
+ expected_exit_code : int
107
+ expected_in_output : "ExpectedOutput" = None
108
+ expected_not_in_output : "ExpectedOutput" = None
109
+
110
+
111
+ SYNC_REPO_FIXTURES = [
112
+ # Empty (root command)
113
+ SyncFixture (
114
+ test_id = "empty" ,
115
+ sync_args = [],
116
+ expected_exit_code = 0 ,
117
+ expected_in_output = ["Options:" , "Commands:" ],
118
+ ),
119
+ # Version
120
+ SyncFixture (
121
+ test_id = "--version" ,
122
+ sync_args = ["--version" ],
123
+ expected_exit_code = 0 ,
124
+ expected_in_output = [__version__ , ", libvcs" ],
125
+ ),
126
+ SyncFixture (
127
+ test_id = "-V" ,
128
+ sync_args = ["-V" ],
129
+ expected_exit_code = 0 ,
130
+ expected_in_output = [__version__ , ", libvcs" ],
131
+ ),
132
+ # Help
133
+ SyncFixture (
134
+ test_id = "--help" ,
135
+ sync_args = ["--help" ],
136
+ expected_exit_code = 0 ,
137
+ expected_in_output = ["Options:" , "Commands:" ],
138
+ ),
139
+ SyncFixture (
140
+ test_id = "-h" ,
141
+ sync_args = ["-h" ],
142
+ expected_exit_code = 0 ,
143
+ expected_in_output = ["Options:" , "Commands:" ],
144
+ ),
145
+ # Sync
146
+ SyncFixture (
147
+ test_id = "sync--empty" ,
148
+ sync_args = ["sync" ],
149
+ expected_exit_code = 0 ,
150
+ expected_in_output = "Options:" ,
151
+ expected_not_in_output = "Commands:" ,
152
+ ),
153
+ # Sync: Help
154
+ SyncFixture (
155
+ test_id = "sync---help" ,
156
+ sync_args = ["sync" , "--help" ],
157
+ expected_exit_code = 0 ,
158
+ expected_in_output = "Options:" ,
159
+ expected_not_in_output = "Commands:" ,
160
+ ),
161
+ SyncFixture (
162
+ test_id = "sync--h" ,
163
+ sync_args = ["sync" , "-h" ],
164
+ expected_exit_code = 0 ,
165
+ expected_in_output = "Options:" ,
166
+ expected_not_in_output = "Commands:" ,
167
+ ),
168
+ # Sync: Repo terms
169
+ SyncFixture (
170
+ test_id = "sync--one-repo-term" ,
171
+ sync_args = ["sync" , "my_git_repo" ],
172
+ expected_exit_code = 0 ,
173
+ expected_in_output = "my_git_repo" ,
174
+ ),
175
+ ]
176
+
177
+
178
+ @pytest .mark .parametrize (
179
+ list (SyncFixture ._fields ),
180
+ SYNC_REPO_FIXTURES ,
181
+ ids = [test .test_id for test in SYNC_REPO_FIXTURES ],
182
+ )
102
183
def test_sync (
103
184
user_path : pathlib .Path ,
104
185
config_path : pathlib .Path ,
105
186
tmp_path : pathlib .Path ,
106
187
git_repo : GitSync ,
188
+ test_id : str ,
189
+ sync_args : list [str ],
190
+ expected_exit_code : int ,
191
+ expected_in_output : "ExpectedOutput" ,
192
+ expected_not_in_output : "ExpectedOutput" ,
107
193
) -> None :
108
194
runner = CliRunner ()
109
195
with runner .isolated_filesystem (temp_dir = tmp_path ):
@@ -124,10 +210,21 @@ def test_sync(
124
210
yaml_config .write_text (yaml_config_data , encoding = "utf-8" )
125
211
126
212
# CLI can sync
127
- result = runner .invoke (cli , [ "sync" , "my_git_repo" ] )
128
- assert result .exit_code == 0
213
+ result = runner .invoke (cli , sync_args )
214
+ assert result .exit_code == expected_exit_code
129
215
output = "" .join (list (result .output ))
130
- assert "my_git_repo" in output
216
+
217
+ if expected_in_output is not None :
218
+ if isinstance (expected_in_output , str ):
219
+ expected_in_output = [expected_in_output ]
220
+ for needle in expected_in_output :
221
+ assert needle in output
222
+
223
+ if expected_not_in_output is not None :
224
+ if isinstance (expected_not_in_output , str ):
225
+ expected_not_in_output = [expected_not_in_output ]
226
+ for needle in expected_not_in_output :
227
+ assert needle not in output
131
228
132
229
133
230
class SyncBrokenFixture (t .NamedTuple ):
0 commit comments