• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Qiskit / ecosystem / 30713661660

01 Aug 2026 06:56PM UTC coverage: 70.42% (+14.6%) from 55.824%
30713661660

push

github

1ucian0
refactor

1926 of 2735 relevant lines covered (70.42%)

0.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.97
/tests/test_cli.py
1
# This code is part of Qiskit.
2
#
3
# (C) Copyright IBM 2026.
4
#
5
# This code is licensed under the Apache License, Version 2.0. You may
6
# obtain a copy of this license in the LICENSE.txt file in the root directory
7
# of this source tree or at https://www.apache.org/licenses/LICENSE-2.0.
8
#
9
# Any modifications or derivative works of this code must retain this
10
# copyright notice, and modified files need to carry a notice indicating
11
# that they have been altered from the originals.
12

13
"""Tests for cli."""
1✔
14

15
import io
1✔
16
import os
1✔
17
import shutil
1✔
18
import tempfile
1✔
19
from unittest import TestCase, mock
1✔
20
from contextlib import redirect_stdout
1✔
21
from pathlib import Path
1✔
22

23
from ecosystem.cli import CliCI, CliMembers
1✔
24
from ecosystem.dao import DAO
1✔
25
from ecosystem.member import Member
1✔
26

27

28
def get_community_repo() -> Member:
1✔
29
    """Return main mock repo."""
30
    return Member(
1✔
31
        name="mock-qiskit",
32
        url="https://github.com/MockQiskit/mock-qiskit",
33
        description="Mock description for repo",
34
        license="Apache 2.0",
35
        labels=["mock", "tests"],
36
        badge="https://qisk.it/e",
37
        maturity="production-ready",
38
    )
39

40

41
def mocked_get_request(*_args, **_kwargs):
1✔
42
    """For mocking a 200 response to a http request"""
43
    return type(
×
44
        "MockResponse",
45
        (object,),
46
        {
47
            "status_code": 200,
48
            "elapsed": 100,
49
            "ok": True,
50
            "created_at": None,
51
            "text": "<title>Qiskit Ecosystem:</title>",
52
        },
53
    )()
54

55

56
class TestCli(TestCase):
1✔
57
    """Test class for cli."""
58

59
    def setUp(self) -> None:
1✔
60
        self.path = Path(tempfile.mkdtemp())
1✔
61
        (self.path / "members").mkdir(parents=True, exist_ok=True)
1✔
62
        with open(self.path / "labels.json", "w") as file:
1✔
63
            file.write("{}")
1✔
64
        self.current_dir = os.path.dirname(os.path.abspath(__file__))
1✔
65
        with open(f"{self.current_dir}/resources/issue.md", "r") as issue_body_file:
1✔
66
            self.issue_body = issue_body_file.read()
1✔
67
        with open(f"{self.current_dir}/resources/issue_2.md", "r") as issue_body_file:
1✔
68
            self.issue_body_2 = issue_body_file.read()
1✔
69
        with open(
1✔
70
            f"{self.current_dir}/resources/issue_skip.md", "r"
71
        ) as issue_body_file:
72
            self.issue_body_skip = issue_body_file.read()
1✔
73
        with open(
1✔
74
            f"{self.current_dir}/resources/issue_extra.md", "r"
75
        ) as issue_body_file:
76
            self.issue_body_extra = issue_body_file.read()
1✔
77

78
    def tearDown(self) -> None:
1✔
79
        shutil.rmtree(self.path)
1✔
80

81
    def test_add_member_from_issue(self):
1✔
82
        """Tests /resources/issue.md parsing function.
83
        Function: Cli
84
                -> parser_issue
85
        """
86

87
        # /resources/issue.md
88
        captured_output = io.StringIO()
1✔
89
        with redirect_stdout(captured_output):
1✔
90
            CliCI.add_member_from_issue(self.issue_body, resources_dir=self.path)
1✔
91

92
        output_value = captured_output.getvalue().split("\n")
1✔
93
        self.assertEqual("SUBMISSION_NAME=Qiskit Banana Compiler", output_value[0])
1✔
94

95
        retrieved_repos = DAO(self.path).get_all()
1✔
96
        expected = {
1✔
97
            "name": "Qiskit Banana Compiler",
98
            "url": "https://github.com/somebody/banana-compiler",
99
            "description": "Compile bananas into Qiskit quantum circuits. "
100
            "Supports all modern devices, including Musa × paradisiaca.",
101
            "contact_info": "author@banana-compiler.org",
102
            "labels": ["error mitigation", "quantum information", "optimization"],
103
            "interfaces": ["Python"],
104
            "website": "https://banana-compiler.org",
105
            "documentation": "https://banana-compiler.org/documentation",
106
            "reference_paper": "https://arxiv.org/abs/5555.22222",
107
            "category": "circuit manipulation",
108
            "maturity": "production-ready",
109
            "packages": [
110
                "https://pypi.org/project/banana-compiler",
111
                "https://pypi.org/project/banana-compiler-hpc",
112
                "https://crates.io/crates/rusty-banana-compiler",
113
                "https://marketplace.visualstudio.com/items?itemName=banana-code-assistance",
114
            ],
115
        }
116
        self.assertEqual(len(retrieved_repos), 1)
1✔
117
        retrieved = list(retrieved_repos)[0].to_dict()
1✔
118
        self.assertIsInstance(retrieved.pop("uuid"), str)
1✔
119
        self.assertDictEqual(expected, retrieved)
1✔
120

121
    def test_add_member_from_issue_2(self):
1✔
122
        """Tests /resources/issue_2.md parsing function.
123
        Function: Cli
124
                -> parser_issue
125
        """
126

127
        # /resources/issue_2.md
128
        captured_output = io.StringIO()
1✔
129
        with redirect_stdout(captured_output):
1✔
130
            CliCI.add_member_from_issue(self.issue_body_2, resources_dir=self.path)
1✔
131

132
        output_value = captured_output.getvalue().split("\n")
1✔
133
        self.assertEqual("SUBMISSION_NAME=Qiskit Banana Compiler", output_value[0])
1✔
134

135
        retrieved_repos = DAO(self.path).get_all()
1✔
136
        expected = {
1✔
137
            "name": "Qiskit Banana Compiler",
138
            "url": "https://github.com/somebody/banana-compiler",
139
            "description": "Compile bananas into Qiskit quantum circuits. "
140
            "Supports all modern devices, including Musa × paradisiaca.",
141
            "labels": [],
142
            "interfaces": ["Other"],
143
            "category": "circuit manipulation",
144
            "maturity": "production-ready",
145
            "packages": [],
146
        }
147
        self.assertEqual(len(retrieved_repos), 1)
1✔
148
        retrieved = list(retrieved_repos)[0].to_dict()
1✔
149
        self.assertIsInstance(retrieved.pop("uuid"), str)
1✔
150
        self.assertDictEqual(expected, retrieved)
1✔
151

152
    def test_add_member_from_issue_skip(self):
1✔
153
        """Tests /resources/issue_skip.md parsing function.
154
        An issue with skip checks
155
        """
156

157
        # /resources/issue_skip.md
158
        captured_output = io.StringIO()
1✔
159
        with redirect_stdout(captured_output):
1✔
160
            CliCI.add_member_from_issue(self.issue_body_skip, resources_dir=self.path)
1✔
161

162
        output_value = captured_output.getvalue().split("\n")
1✔
163
        self.assertEqual("SUBMISSION_NAME=Qiskit Banana Compiler", output_value[0])
1✔
164

165
        retrieved_repos = DAO(self.path).get_all()
1✔
166
        expected = {
1✔
167
            "name": "Qiskit Banana Compiler",
168
            "url": "https://github.com/somebody/banana-compiler",
169
            "description": "Compile bananas into Qiskit quantum circuits. "
170
            "Supports all modern devices, including Musa × paradisiaca.",
171
            "labels": [],
172
            "interfaces": ["Python"],
173
            "category": "SDK",
174
            "maturity": "production-ready",
175
            "packages": [],
176
            "checks": {
177
                "010": {
178
                    "importance": "RECOMMENDATION",
179
                    "xfailed": 'This project is allow to have "test" in its name',
180
                },
181
                "COC": {
182
                    "importance": "CRITICAL",
183
                    "xfailed": "This project does not need to agree the CoC",
184
                },
185
            },
186
        }
187
        self.assertEqual(len(retrieved_repos), 1)
1✔
188
        retrieved = list(retrieved_repos)[0].to_dict()
1✔
189
        self.assertIsInstance(retrieved.pop("uuid"), str)
1✔
190
        self.assertDictEqual(expected, retrieved)
1✔
191

192
    def test_add_member_from_issue_extra(self):
1✔
193
        """Tests /resources/issue_extra.md parsing function.
194
        An issue with extra sections that can be ignored
195
        (like in https://github.com/Qiskit/ecosystem/issues/1123)
196
        """
197

198
        # /resources/issue_extra.md
199
        captured_output = io.StringIO()
1✔
200
        with redirect_stdout(captured_output):
1✔
201
            CliCI.add_member_from_issue(self.issue_body_extra, resources_dir=self.path)
1✔
202

203
        output_value = captured_output.getvalue().split("\n")
1✔
204
        self.assertEqual("SUBMISSION_NAME=Qiskit Banana Compiler", output_value[0])
1✔
205

206
        retrieved_repos = DAO(self.path).get_all()
1✔
207
        expected = {
1✔
208
            "name": "Qiskit Banana Compiler",
209
            "url": "https://github.com/somebody/banana-compiler",
210
            "description": "Compile bananas into Qiskit quantum circuits. "
211
            "Supports all modern devices, including Musa × paradisiaca.",
212
            "labels": [],
213
            "interfaces": ["Python"],
214
            "category": "SDK",
215
            "maturity": "production-ready",
216
            "packages": [],
217
        }
218
        self.assertEqual(len(retrieved_repos), 1)
1✔
219
        retrieved = list(retrieved_repos)[0].to_dict()
1✔
220
        self.assertIsInstance(retrieved.pop("uuid"), str)
1✔
221
        self.assertDictEqual(expected, retrieved)
1✔
222

223
    @mock.patch("requests.get", new=mocked_get_request)
1✔
224
    def test_create_badge_endpoints(self):
1✔
225
        """Tests creating badges."""
226
        commu_success = get_community_repo()
1✔
227
        dao = DAO(self.path)
1✔
228

229
        # insert entry
230
        dao.write(commu_success)
1✔
231

232
        cli_members = CliMembers(root_path=os.path.join(self.current_dir, ".."))
1✔
233
        cli_members.resources_dir = self.path
1✔
234
        cli_members.current_dir = self.path
1✔
235
        cli_members.dao = dao
1✔
236

237
        # create badge endpoints
238
        cli_members.create_badge_endpoints()
1✔
239

240
        # gets a short url and updates the list in qisk.it/ecosystem-badges
241
        cli_members.update_badge_list()
1✔
242

243
        badges_folder_path = f"{cli_members.current_dir}/badges"
1✔
244
        self.assertTrue(
1✔
245
            os.path.isfile(f"{badges_folder_path}/{commu_success.short_uuid}")
246
        )
247

248
        # check version status
249
        with open(
1✔
250
            f"{badges_folder_path}/{commu_success.short_uuid}", "r"
251
        ) as json_blueviolet:
252
            json_success = json_blueviolet.read()
1✔
253
        self.assertTrue('"color": "6929C4"' in json_success)
1✔
254

255
        os.remove(f"{badges_folder_path}/{commu_success.short_uuid}")
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc