Skip to content

Commit 248051f

Browse files
committed
More regex
1 parent de6185f commit 248051f

File tree

1 file changed

+105
-3
lines changed

1 file changed

+105
-3
lines changed

tests/test_git.py

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,45 @@ def test_set_remote(git_repo, repo_name, new_repo_url):
208208
def extract_status(value):
209209
"""Returns `git status -sb --porcelain=2` extracted to a dict"""
210210
pattern = re.compile(
211-
r"""
212-
^.*branch.oid\W+(?P<branch_oid>[a-f0-9]{40})[\n\r]?
213-
\#\W+branch.head[\W]+(?P<branch_head>[\w-]*)
211+
r"""[\n\r]?
212+
(
213+
#
214+
\W+
215+
branch.oid\W+
216+
(?P<branch_oid>
217+
[a-f0-9]{40}
218+
)
219+
)?
220+
(
221+
#
222+
\W+
223+
branch.head
224+
[\W]+
225+
(?P<branch_head>
226+
[\w-]*
227+
)
228+
229+
)?
230+
(
231+
#
232+
\W+
233+
branch.upstream
234+
[\W]+
235+
(?P<branch_upstream>
236+
[/\w-]*
237+
)
238+
)?
239+
(
240+
#
241+
\W+
242+
branch.ab
243+
[\W]+
244+
(?P<branch_ab>
245+
\+(?P<branch_ahead>\d+)
246+
\W{1}
247+
\-(?P<branch_behind>\d+)
248+
)
249+
)?
214250
""",
215251
re.VERBOSE | re.MULTILINE,
216252
)
@@ -230,3 +266,69 @@ def test_extract_status():
230266
"branch_oid": 'd4ccd4d6af04b53949f89fbf0cdae13719dc5a08',
231267
"branch_head": 'fix-current-remote-name',
232268
}.items() <= extract_status(FIXTURE_A).items()
269+
270+
271+
@pytest.mark.parametrize(
272+
'fixture,expected_result',
273+
[
274+
[
275+
"""
276+
# branch.oid de6185fde0806e5c7754ca05676325a1ea4d6348
277+
# branch.head fix-current-remote-name
278+
# branch.upstream origin/fix-current-remote-name
279+
# branch.ab +0 -0
280+
1 .M N... 100644 100644 100644 91082f119279b6f105ee9a5ce7795b3bdbe2b0de 91082f119279b6f105ee9a5ce7795b3bdbe2b0de CHANGES
281+
1 .M N... 100644 100644 100644 302ca2c18d4c295ce217bff5f93e1ba342dc6665 302ca2c18d4c295ce217bff5f93e1ba342dc6665 tests/test_git.py
282+
""", # NOQA: E501
283+
{
284+
"branch_oid": 'de6185fde0806e5c7754ca05676325a1ea4d6348',
285+
"branch_head": 'fix-current-remote-name',
286+
"branch_upstream": 'origin/fix-current-remote-name',
287+
"branch_ab": '+0 -0',
288+
"branch_ahead": '0',
289+
"branch_behind": '0',
290+
},
291+
],
292+
[
293+
'# branch.upstream moo/origin/myslash/remote',
294+
{"branch_upstream": 'moo/origin/myslash/remote',},
295+
],
296+
],
297+
)
298+
def test_extract_status_b(fixture, expected_result):
299+
assert expected_result.items() <= extract_status(textwrap.dedent(fixture)).items()
300+
301+
302+
@pytest.mark.parametrize(
303+
'fixture,expected_result',
304+
[
305+
[
306+
'# branch.ab +1 -83',
307+
{"branch_ab": '+1 -83', "branch_ahead": '1', "branch_behind": '83',},
308+
],
309+
[
310+
"""
311+
# branch.ab +0 -0
312+
""",
313+
{"branch_ab": '+0 -0', "branch_ahead": '0', "branch_behind": '0',},
314+
],
315+
[
316+
"""
317+
# branch.ab +1 -83
318+
""",
319+
{"branch_ab": '+1 -83', "branch_ahead": '1', "branch_behind": '83',},
320+
],
321+
[
322+
"""
323+
# branch.ab +9999999 -9999999
324+
""",
325+
{
326+
"branch_ab": '+9999999 -9999999',
327+
"branch_ahead": '9999999',
328+
"branch_behind": '9999999',
329+
},
330+
],
331+
],
332+
)
333+
def test_extract_status_c(fixture, expected_result):
334+
assert expected_result.items() <= extract_status(textwrap.dedent(fixture)).items()

0 commit comments

Comments
 (0)