|
1 | 1 | import os
|
2 |
| -import subprocess |
3 | 2 | from pathlib import Path
|
4 |
| -from textwrap import dedent |
5 | 3 | from typing import Any
|
6 | 4 | from unittest.mock import ANY, MagicMock, Mock, call, patch, sentinel
|
7 | 5 |
|
@@ -55,110 +53,39 @@ class TestModule(OutputConverterBase):
|
55 | 53 | with pytest.raises(TypeError):
|
56 | 54 | TestModule()
|
57 | 55 |
|
58 |
| - @patch("yarf.output.subprocess.run") |
59 |
| - def test_get_yarf_snap_info( |
60 |
| - self, |
61 |
| - mock_subprocess_run: MagicMock, |
62 |
| - ) -> None: |
| 56 | + def test_get_yarf_snap_info(self) -> None: |
63 | 57 | """
|
64 | 58 | Test whether the "get_yarf_snap_info" method is callable and return
|
65 | 59 | results with expected fields.
|
66 | 60 | """
|
67 |
| - mock_subprocess_run.return_value.stdout = dedent( |
68 |
| - """ |
69 |
| - name: yarf |
70 |
| - summary: Yet Another Robot Framework |
71 |
| - publisher: Canonical Certification Team (ce-certification-qa) |
72 |
| - store-url: https://snapcraft.io/yarf |
73 |
| - license: unset |
74 |
| - description: | |
75 |
| - Yet Another Robot Framework (YARF) is an interface that |
76 |
| - allows developers to build complex test scenarios and |
77 |
| - bootstrap them locally, then work towards automated runs. |
78 |
| - commands: |
79 |
| - - yarf |
80 |
| - snap-id: zIV9E2VxqRgGhIuttHs8YkCyWGjIOiRm |
81 |
| - tracking: latest/beta |
82 |
| - refresh-date: 3 days ago, at 16:40 GMT |
83 |
| - channels: |
84 |
| - latest/stable: – |
85 |
| - latest/candidate: – |
86 |
| - latest/beta: 1.0.0 2024-12-03 (124) 206MB - |
87 |
| - latest/edge: 1.0.0 2024-12-03 (124) 206MB - |
88 |
| - installed: 1.0.0 (124) 206MB - |
89 |
| - """ |
90 |
| - ) |
91 |
| - |
92 | 61 | expected_result = {
|
93 |
| - "channel": "latest/beta", |
94 |
| - "version": "1.0.0", |
95 |
| - "revision": "124", |
96 |
| - "date": "2024-12-03", |
| 62 | + "version": "2.0.0", |
| 63 | + "revision": "300", |
97 | 64 | "name": "yarf",
|
98 | 65 | }
|
99 |
| - with patch.dict(os.environ, {"SNAP": str(sentinel.snap_env)}): |
| 66 | + with patch.dict( |
| 67 | + os.environ, |
| 68 | + { |
| 69 | + "SNAP": str(sentinel.snap_env), |
| 70 | + "SNAP_NAME": "yarf", |
| 71 | + "SNAP_VERSION": "2.0.0", |
| 72 | + "SNAP_REVISION": "300", |
| 73 | + }, |
| 74 | + ): |
100 | 75 | result = OutputConverterBase.get_yarf_snap_info()
|
101 | 76 | assert expected_result == result
|
102 | 77 |
|
103 |
| - @patch("yarf.output.subprocess.run") |
104 |
| - def test_get_yarf_snap_info_runtime_error( |
105 |
| - self, |
106 |
| - mock_subprocess_run: MagicMock, |
107 |
| - ) -> None: |
108 |
| - """ |
109 |
| - Test whether the function get_yarf_snap_info raises runtime error when |
110 |
| - subprocess.run raises a CalledProcessError exception. |
111 |
| - """ |
112 |
| - |
113 |
| - mock_subprocess_run.side_effect = subprocess.CalledProcessError( |
114 |
| - returncode=1, |
115 |
| - cmd=["snap", "info", "yarf"], |
116 |
| - output="Error: Could not find snap 'yarf'.", |
117 |
| - ) |
118 |
| - |
119 |
| - with ( |
120 |
| - patch.dict(os.environ, {"SNAP": str(sentinel.snap_env)}), |
121 |
| - pytest.raises(RuntimeError), |
122 |
| - ): |
123 |
| - OutputConverterBase.get_yarf_snap_info() |
124 |
| - |
125 |
| - @patch("yarf.output.subprocess.run") |
126 |
| - def test_get_yarf_snap_info_value_error( |
127 |
| - self, |
128 |
| - mock_subprocess_run: MagicMock, |
129 |
| - ) -> None: |
| 78 | + def test_get_yarf_snap_info_value_error(self) -> None: |
130 | 79 | """
|
131 | 80 | Test whether the function get_yarf_snap_info raises value error when
|
132 | 81 | there is a mismatch between the installed YARF and the snap info.
|
133 | 82 | """
|
134 |
| - |
135 |
| - mock_subprocess_run.return_value.stdout = dedent( |
136 |
| - """ |
137 |
| - name: yarf |
138 |
| - summary: Yet Another Robot Framework |
139 |
| - publisher: Canonical Certification Team (ce-certification-qa) |
140 |
| - store-url: https://snapcraft.io/yarf |
141 |
| - license: unset |
142 |
| - description: | |
143 |
| - Yet Another Robot Framework (YARF) is an interface that |
144 |
| - allows developers to build complex test scenarios and |
145 |
| - bootstrap them locally, then work towards automated runs. |
146 |
| - commands: |
147 |
| - - yarf |
148 |
| - snap-id: zIV9E2VxqRgGhIuttHs8YkCyWGjIOiRm |
149 |
| - tracking: latest/beta |
150 |
| - refresh-date: 3 days ago, at 16:40 GMT |
151 |
| - channels: |
152 |
| - latest/stable: – |
153 |
| - latest/candidate: – |
154 |
| - latest/beta: 1.0.0 2024-12-03 (124) 206MB - |
155 |
| - latest/edge: 1.0.0 2024-12-03 (124) 206MB - |
156 |
| - installed: 9.9.9 (999) 206MB - |
157 |
| - """ |
158 |
| - ) |
159 |
| - |
160 | 83 | with (
|
161 |
| - patch.dict(os.environ, {"SNAP": str(sentinel.snap_env)}), |
| 84 | + patch.dict( |
| 85 | + os.environ, |
| 86 | + {"SNAP": str(sentinel.snap_env), "SNAP_NAME": "yarf"}, |
| 87 | + clear=True, |
| 88 | + ), |
162 | 89 | pytest.raises(ValueError),
|
163 | 90 | ):
|
164 | 91 | OutputConverterBase.get_yarf_snap_info()
|
|
0 commit comments