Merge ~jugmac00/lpci:show_error_message_when_no_output_files into lpci:main

Proposed by Jürgen Gmach
Status: Merged
Merged at revision: 68132166033768a97cf4994ef1480d07c1740b4c
Proposed branch: ~jugmac00/lpci:show_error_message_when_no_output_files
Merge into: lpci:main
Diff against target: 98 lines (+58/-6)
3 files modified
NEWS.rst (+3/-0)
lpcraft/commands/run.py (+8/-6)
lpcraft/commands/tests/test_run.py (+47/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+416301@code.launchpad.net

Commit message

Show error message when there are no matching output files

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/NEWS.rst b/NEWS.rst
2index 03d30e4..7af12cc 100644
3--- a/NEWS.rst
4+++ b/NEWS.rst
5@@ -7,6 +7,9 @@ Version history
6
7 - Add note that containers will not be deleted automatically.
8
9+- Show error message when there are no matching output files,
10+ see https://bugs.launchpad.net/lpcraft/+bug/1962774
11+
12 0.0.3 (2022-02-23)
13 ====================
14
15diff --git a/lpcraft/commands/run.py b/lpcraft/commands/run.py
16index 8292f47..950549b 100644
17--- a/lpcraft/commands/run.py
18+++ b/lpcraft/commands/run.py
19@@ -107,13 +107,15 @@ def _copy_output_paths(
20
21 filtered_paths: Set[PurePath] = set()
22 for path_pattern in output.paths:
23- filtered_paths.update(
24- PurePath(name)
25- for name in fnmatch.filter(
26- [str(path) for path in remote_paths],
27- path_pattern,
28+ paths = [str(path) for path in remote_paths]
29+ result = fnmatch.filter(paths, path_pattern)
30+ if not result:
31+ raise CommandError(
32+ f"{path_pattern} has not matched any output files."
33 )
34- )
35+ for name in result:
36+ filtered_paths.add(PurePath(name))
37+
38 resolved_paths = _resolve_symlinks(
39 instance,
40 [remote_cwd / path for path in sorted(filtered_paths)],
41diff --git a/lpcraft/commands/tests/test_run.py b/lpcraft/commands/tests/test_run.py
42index afc2796..19cb494 100644
43--- a/lpcraft/commands/tests/test_run.py
44+++ b/lpcraft/commands/tests/test_run.py
45@@ -890,6 +890,53 @@ class TestRun(RunBaseTestCase):
46 @patch("lpcraft.env.get_managed_environment_project_path")
47 @patch("lpcraft.commands.run.get_provider")
48 @patch("lpcraft.commands.run.get_host_architecture", return_value="amd64")
49+ def test_shows_error_message_when_no_output_files(
50+ self,
51+ mock_get_host_architecture,
52+ mock_get_provider,
53+ mock_get_project_path,
54+ ):
55+ target_path = Path(self.useFixture(TempDir()).path)
56+ launcher = Mock(spec=launch)
57+ provider = self.makeLXDProvider(lxd_launcher=launcher)
58+ mock_get_provider.return_value = provider
59+ execute_run = LocalExecuteRun(self.tmp_project_path)
60+ launcher.return_value.execute_run = execute_run
61+ mock_get_project_path.return_value = self.tmp_project_path
62+ config = dedent(
63+ """
64+ pipeline:
65+ - build
66+
67+ jobs:
68+ build:
69+ series: focal
70+ architectures: amd64
71+ run: |
72+ true
73+ output:
74+ paths: ["*.whl"]
75+ """
76+ )
77+ Path(".launchpad.yaml").write_text(config)
78+
79+ result = self.run_command(
80+ "run", "--output-directory", str(target_path)
81+ )
82+
83+ self.assertThat(
84+ result,
85+ MatchesStructure.byEquality(
86+ exit_code=1,
87+ errors=[
88+ CommandError("*.whl has not matched any output files.")
89+ ],
90+ ),
91+ )
92+
93+ @patch("lpcraft.env.get_managed_environment_project_path")
94+ @patch("lpcraft.commands.run.get_provider")
95+ @patch("lpcraft.commands.run.get_host_architecture", return_value="amd64")
96 def test_reads_properties(
97 self,
98 mock_get_host_architecture,

Subscribers

People subscribed via source and target branches