Skip to content

Commit 9b6b631

Browse files
committed
Improve feature tests
1 parent 40090a9 commit 9b6b631

5 files changed

Lines changed: 41 additions & 43 deletions

File tree

dfetch/commands/add.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,16 @@ def _finalize_add(
314314
def _non_interactive_entry(ctx: _AddContext, overrides: _Overrides) -> ProjectEntry:
315315
"""Build a ``ProjectEntry`` using inferred defaults (no user interaction)."""
316316
if overrides.version:
317-
version = _resolve_raw_version(overrides.version, []) or Version(
317+
branches = ctx.subproject.list_of_branches()
318+
tags = ctx.subproject.list_of_tags()
319+
choices: list[Version] = [
320+
*[
321+
Version(branch=b)
322+
for b in prioritise_default(branches, ctx.default_branch)
323+
],
324+
*[Version(tag=t) for t in sort_tags_newest_first(tags)],
325+
]
326+
version = _resolve_raw_version(overrides.version, choices) or Version(
318327
branch=ctx.default_branch
319328
)
320329
else:

features/add-project-through-cli.feature

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Feature: Add a project to the manifest via the CLI
2424
- name: ext/existing
2525
url: some-remote-server/existing.git
2626
"""
27-
When I add "some-remote-server/MyLib.git"
27+
When I run "dfetch add some-remote-server/MyLib.git"
2828
Then the manifest 'dfetch.yaml' contains entry
2929
"""
3030
- name: MyLib
@@ -42,7 +42,7 @@ Feature: Add a project to the manifest via the CLI
4242
- name: MyLib
4343
url: some-remote-server/MyLib.git
4444
"""
45-
When I add "some-remote-server/MyLib.git"
45+
When I run "dfetch add some-remote-server/MyLib.git"
4646
Then the manifest 'dfetch.yaml' contains entry
4747
"""
4848
- name: MyLib-1
@@ -61,7 +61,7 @@ Feature: Add a project to the manifest via the CLI
6161
- name: ext/lib-b
6262
url: some-remote-server/lib-b.git
6363
"""
64-
When I add "some-remote-server/MyLib.git"
64+
When I run "dfetch add some-remote-server/MyLib.git"
6565
Then the manifest 'dfetch.yaml' contains entry
6666
"""
6767
- name: MyLib
@@ -79,7 +79,7 @@ Feature: Add a project to the manifest via the CLI
7979
- name: ext/existing
8080
url: some-remote-server/existing.git
8181
"""
82-
When I interactively add "some-remote-server/MyLib.git" with inputs
82+
When I run "dfetch add -i some-remote-server/MyLib.git" with inputs
8383
| Question | Answer |
8484
| Project name | my-lib |
8585
| Destination path | libs/my |
@@ -105,7 +105,7 @@ Feature: Add a project to the manifest via the CLI
105105
- name: existing
106106
url: some-remote-server/existing.git
107107
"""
108-
When I interactively add "some-remote-server/MyLib.git" with inputs
108+
When I run "dfetch add -i some-remote-server/MyLib.git" with inputs
109109
| Question | Answer |
110110
| Project name | my-lib |
111111
| Destination path | my-lib |
@@ -130,7 +130,7 @@ Feature: Add a project to the manifest via the CLI
130130
- name: existing
131131
url: some-remote-server/existing.git
132132
"""
133-
When I interactively add "some-remote-server/MyLib.git" with inputs
133+
When I run "dfetch add -i some-remote-server/MyLib.git" with inputs
134134
| Question | Answer |
135135
| Project name | my-lib |
136136
| Destination path | my-lib |
@@ -156,7 +156,7 @@ Feature: Add a project to the manifest via the CLI
156156
- name: existing
157157
url: some-remote-server/existing.git
158158
"""
159-
When I interactively add "some-remote-server/MyLib.git" with inputs
159+
When I run "dfetch add -i some-remote-server/MyLib.git" with inputs
160160
| Question | Answer |
161161
| Project name | my-lib |
162162
| Destination path | my-lib |
@@ -184,7 +184,7 @@ Feature: Add a project to the manifest via the CLI
184184
- name: existing
185185
url: some-remote-server/existing.git
186186
"""
187-
When I interactively add "some-remote-server/MyLib.git" with inputs
187+
When I run "dfetch add -i some-remote-server/MyLib.git" with inputs
188188
| Question | Answer |
189189
| Project name | MyLib |
190190
| Destination path | MyLib |
@@ -210,7 +210,7 @@ Feature: Add a project to the manifest via the CLI
210210
- name: existing
211211
url: some-remote-server/existing.git
212212
"""
213-
When I interactively add "some-remote-server/MyLib.git" with inputs
213+
When I run "dfetch add -i some-remote-server/MyLib.git" with inputs
214214
| Question | Answer |
215215
| Project name | MyLib |
216216
| Destination path | MyLib |
@@ -236,7 +236,7 @@ Feature: Add a project to the manifest via the CLI
236236
- name: existing
237237
url: some-remote-server/existing.git
238238
"""
239-
When I interactively add "some-remote-server/MyLib.git" with inputs
239+
When I run "dfetch add -i some-remote-server/MyLib.git" with inputs
240240
| Question | Answer |
241241
| Project name | MyLib |
242242
| Destination path | MyLib |
@@ -258,9 +258,11 @@ Feature: Add a project to the manifest via the CLI
258258
"""
259259
manifest:
260260
version: '0.0'
261-
projects: []
261+
projects:
262+
- name: ext/existing
263+
url: some-remote-server/existing.git
262264
"""
263-
When I add "some-remote-server/MyLib.git" with options "--name my-lib --dst libs/my-lib"
265+
When I run "dfetch add some-remote-server/MyLib.git --name my-lib --dst libs/my-lib"
264266
Then the manifest 'dfetch.yaml' contains entry
265267
"""
266268
- name: my-lib
@@ -278,7 +280,7 @@ Feature: Add a project to the manifest via the CLI
278280
- name: existing
279281
url: some-remote-server/existing.git
280282
"""
281-
When I interactively add "some-remote-server/MyLib.git" with options "--name my-lib --dst libs/my" and inputs
283+
When I run "dfetch add -i some-remote-server/MyLib.git --name my-lib --dst libs/my" with inputs
282284
| Question | Answer |
283285
| Version | master |
284286
| Source path | |

features/steps/add_steps.py

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Steps for the 'dfetch add' feature tests."""
22

3-
# pylint: disable=function-redefined, missing-function-docstring, import-error, not-callable
4-
# pyright: reportRedeclaration=false, reportAttributeAccessIssue=false, reportCallIssue=false
3+
# pylint: disable=missing-function-docstring, import-error, not-callable
4+
# pyright: reportAttributeAccessIssue=false, reportCallIssue=false
55

66
from collections import deque
77
from unittest.mock import patch
@@ -17,18 +17,6 @@ def _resolve_url(url: str, context) -> str:
1717
return url.replace("some-remote-server", f"file:///{remote_server_path(context)}")
1818

1919

20-
@when('I add "{remote_url}"')
21-
def step_impl(context, remote_url):
22-
url = _resolve_url(remote_url, context)
23-
call_command(context, ["add", url])
24-
25-
26-
@when('I add "{remote_url}" with options "{options}"')
27-
def step_impl(context, remote_url, options):
28-
url = _resolve_url(remote_url, context)
29-
call_command(context, ["add"] + options.split() + [url])
30-
31-
3220
def _run_interactive_add(context, cmd: list[str]) -> None:
3321
"""Run an interactive add command, driving prompts from ``context.table``."""
3422
# Parse the answer table into three buckets:
@@ -70,20 +58,16 @@ def _auto_prompt(_prompt: str, **kwargs) -> str: # type: ignore[return]
7058
call_command(context, cmd)
7159

7260

73-
@when('I interactively add "{remote_url}" with options "{options}" and inputs')
74-
def step_impl(context, remote_url, options):
75-
url = _resolve_url(remote_url, context)
76-
_run_interactive_add(context, ["add", "--interactive"] + options.split() + [url])
77-
78-
79-
@when('I interactively add "{remote_url}" with inputs')
80-
def step_impl(context, remote_url):
81-
url = _resolve_url(remote_url, context)
82-
_run_interactive_add(context, ["add", "--interactive", url])
61+
@when('I run "dfetch {add_args}" with inputs')
62+
def step_interactive_add(context, add_args):
63+
resolved = add_args.replace(
64+
"some-remote-server", f"file:///{remote_server_path(context)}"
65+
)
66+
_run_interactive_add(context, resolved.split())
8367

8468

8569
@then("the manifest '{name}' contains entry")
86-
def step_impl(context, name):
70+
def step_manifest_contains_entry(context, name):
8771
expected = apply_manifest_substitutions(context, context.text)
8872
with open(name, "r", encoding="utf-8") as fh:
8973
actual = fh.read()
@@ -105,15 +89,15 @@ def step_impl(context, name):
10589

10690

10791
@then('the command fails with "{message}"')
108-
def step_impl(context, message):
92+
def step_command_fails_with(context, message):
10993
assert context.cmd_returncode != 0, "Expected command to fail, but it succeeded"
11094
assert (
11195
message in context.cmd_output
11296
), f"Expected error message '{message}' not found in output:\n{context.cmd_output}"
11397

11498

11599
@then("the manifest '{name}' does not contain '{text}'")
116-
def step_impl(_, name, text):
100+
def step_manifest_not_contain(_, name, text):
117101
with open(name, "r", encoding="utf-8") as fh:
118102
actual = fh.read()
119103

features/steps/generic_steps.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,10 @@ def step_impl(context, path=None):
365365
@when('I run "dfetch {args}"')
366366
def step_impl(context, args, path=None):
367367
"""Call a command."""
368-
call_command(context, args.split(), path)
368+
resolved = args.replace(
369+
"some-remote-server", f"file:///{remote_server_path(context)}"
370+
)
371+
call_command(context, resolved.split(), path)
369372

370373

371374
@given('"{path}" in {directory} is changed locally')

tests/test_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ def test_add_create_menu_field_overrides():
867867
parsed = parser.parse_args(
868868
[
869869
"add",
870+
"https://example.com/repo.git",
870871
"--name",
871872
"mylib",
872873
"--dst",
@@ -878,7 +879,6 @@ def test_add_create_menu_field_overrides():
878879
"--ignore",
879880
"docs",
880881
"tests",
881-
"https://example.com/repo.git",
882882
]
883883
)
884884
assert parsed.name == "mylib"

0 commit comments

Comments
 (0)