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

Qiskit / ecosystem / 24825078059

23 Apr 2026 08:27AM UTC coverage: 54.375% (-1.4%) from 55.824%
24825078059

Pull #1108

github

web-flow
Merge 3bab41920 into 0e11c3ff6
Pull Request #1108: new section: badge

29 of 38 new or added lines in 4 files covered. (76.32%)

31 existing lines in 4 files now uncovered.

870 of 1600 relevant lines covered (54.37%)

0.54 hits per line

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

98.78
/tests/test_cli.py
1
"""Tests for cli."""
2

3
import io
1✔
4
import os
1✔
5
import shutil
1✔
6
import tempfile
1✔
7
from unittest import TestCase, mock
1✔
8
from contextlib import redirect_stdout
1✔
9
from pathlib import Path
1✔
10

11
from ecosystem.cli import CliCI, CliMembers
1✔
12
from ecosystem.dao import DAO
1✔
13
from ecosystem.member import Member
1✔
14

15

16
def get_community_repo() -> Member:
1✔
17
    """Return main mock repo."""
18
    return Member(
1✔
19
        name="mock-qiskit",
20
        url="https://github.com/MockQiskit/mock-qiskit",
21
        description="Mock description for repo",
22
        licence="Apache 2.0",
23
        labels=["mock", "tests"],
24
        badge="https://qisk.it/e",
25
    )
26

27

28
def mocked_get_request(*_args, **_kwargs):
1✔
29
    """For mocking a 200 response to a http request"""
UNCOV
30
    return type(
×
31
        "MockResponse",
32
        (object,),
33
        {
34
            "status_code": 200,
35
            "elapsed": 100,
36
            "ok": True,
37
            "created_at": None,
38
            "text": "<title>Qiskit Ecosystem:</title>",
39
        },
40
    )()
41

42

43
class TestCli(TestCase):
1✔
44
    """Test class for cli."""
45

46
    def setUp(self) -> None:
1✔
47
        self.path = Path(tempfile.mkdtemp())
1✔
48
        (self.path / "members").mkdir(parents=True, exist_ok=True)
1✔
49
        with open(self.path / "labels.json", "w") as file:
1✔
50
            file.write("{}")
1✔
51
        self.current_dir = os.path.dirname(os.path.abspath(__file__))
1✔
52
        with open(f"{self.current_dir}/resources/issue.md", "r") as issue_body_file:
1✔
53
            self.issue_body = issue_body_file.read()
1✔
54
        with open(f"{self.current_dir}/resources/issue_2.md", "r") as issue_body_file:
1✔
55
            self.issue_body_2 = issue_body_file.read()
1✔
56
        with open(
1✔
57
            f"{self.current_dir}/resources/issue_skip.md", "r"
58
        ) as issue_body_file:
59
            self.issue_body_skip = issue_body_file.read()
1✔
60

61
    def tearDown(self) -> None:
1✔
62
        shutil.rmtree(self.path)
1✔
63

64
    def test_add_member_from_issue(self):
1✔
65
        """Tests /resources/issue.md parsing function.
66
        Function: Cli
67
                -> parser_issue
68
        """
69

70
        # /resources/issue.md
71
        captured_output = io.StringIO()
1✔
72
        with redirect_stdout(captured_output):
1✔
73
            CliCI.add_member_from_issue(self.issue_body, resources_dir=self.path)
1✔
74

75
        output_value = captured_output.getvalue().split("\n")
1✔
76
        self.assertEqual("SUBMISSION_NAME=Qiskit Banana Compiler", output_value[0])
1✔
77

78
        retrieved_repos = DAO(self.path).get_all()
1✔
79
        expected = {
1✔
80
            "name": "Qiskit Banana Compiler",
81
            "url": "https://github.com/somebody/banana-compiler",
82
            "description": "Compile bananas into Qiskit quantum circuits. "
83
            "Supports all modern devices, including Musa × paradisiaca.",
84
            "contact_info": "author@banana-compiler.org",
85
            "labels": ["error mitigation", "quantum information", "optimization"],
86
            "interface": ["Python"],
87
            "website": "https://banana-compiler.org",
88
            "documentation": "https://banana-compiler.org/documentation",
89
            "reference_paper": "https://arxiv.org/abs/5555.22222",
90
            "category": "circuit manipulation",
91
            "packages": [
92
                "https://pypi.org/project/banana-compiler",
93
                "https://pypi.org/project/banana-compiler-hpc",
94
                "https://crates.io/crates/rusty-banana-compiler",
95
                "https://marketplace.visualstudio.com/items?itemName=banana-code-assistance",
96
            ],
97
        }
98
        self.assertEqual(len(retrieved_repos), 1)
1✔
99
        retrieved = list(retrieved_repos)[0].to_dict()
1✔
100
        self.assertIsInstance(retrieved.pop("uuid"), str)
1✔
101
        self.assertDictEqual(expected, retrieved)
1✔
102

103
    def test_add_member_from_issue_2(self):
1✔
104
        """Tests /resources/issue_2.md parsing function.
105
        Function: Cli
106
                -> parser_issue
107
        """
108

109
        # /resources/issue_2.md
110
        captured_output = io.StringIO()
1✔
111
        with redirect_stdout(captured_output):
1✔
112
            CliCI.add_member_from_issue(self.issue_body_2, resources_dir=self.path)
1✔
113

114
        output_value = captured_output.getvalue().split("\n")
1✔
115
        self.assertEqual("SUBMISSION_NAME=Qiskit Banana Compiler", output_value[0])
1✔
116

117
        retrieved_repos = DAO(self.path).get_all()
1✔
118
        expected = {
1✔
119
            "name": "Qiskit Banana Compiler",
120
            "url": "https://github.com/somebody/banana-compiler",
121
            "description": "Compile bananas into Qiskit quantum circuits. "
122
            "Supports all modern devices, including Musa × paradisiaca.",
123
            "labels": [],
124
            "interface": ["Other"],
125
            "category": "circuit manipulation",
126
            "packages": [],
127
        }
128
        self.assertEqual(len(retrieved_repos), 1)
1✔
129
        retrieved = list(retrieved_repos)[0].to_dict()
1✔
130
        self.assertIsInstance(retrieved.pop("uuid"), str)
1✔
131
        self.assertDictEqual(expected, retrieved)
1✔
132

133
    def test_add_member_from_issue_skip(self):
1✔
134
        """Tests /resources/issue_skip.md parsing function.
135
        An issue with skip checks
136
        """
137

138
        # /resources/issue_skip.md
139
        captured_output = io.StringIO()
1✔
140
        with redirect_stdout(captured_output):
1✔
141
            CliCI.add_member_from_issue(self.issue_body_skip, resources_dir=self.path)
1✔
142

143
        output_value = captured_output.getvalue().split("\n")
1✔
144
        self.assertEqual("SUBMISSION_NAME=Qiskit Banana Compiler", output_value[0])
1✔
145

146
        retrieved_repos = DAO(self.path).get_all()
1✔
147
        expected = {
1✔
148
            "name": "Qiskit Banana Compiler",
149
            "url": "https://github.com/somebody/banana-compiler",
150
            "description": "Compile bananas into Qiskit quantum circuits. "
151
            "Supports all modern devices, including Musa × paradisiaca.",
152
            "labels": [],
153
            "interface": ["Python"],
154
            "category": "circuit manipulation",
155
            "packages": [],
156
            "checks": {
157
                "010": {
158
                    "importance": "RECOMMENDATION",
159
                    "xfailed": 'This project is allow to have "test" in its name',
160
                },
161
                "COC": {
162
                    "importance": "CRITICAL",
163
                    "xfailed": "This project does not need to agree the CoC",
164
                },
165
            },
166
        }
167
        self.assertEqual(len(retrieved_repos), 1)
1✔
168
        retrieved = list(retrieved_repos)[0].to_dict()
1✔
169
        self.assertIsInstance(retrieved.pop("uuid"), str)
1✔
170
        self.assertDictEqual(expected, retrieved)
1✔
171

172
    @mock.patch("requests.get", new=mocked_get_request)
1✔
173
    def test_create_badge_endpoints(self):
1✔
174
        """Tests creating badges."""
175
        commu_success = get_community_repo()
1✔
176
        dao = DAO(self.path)
1✔
177

178
        # insert entry
179
        dao.write(commu_success)
1✔
180

181
        cli_members = CliMembers(root_path=os.path.join(self.current_dir, ".."))
1✔
182
        cli_members.resources_dir = self.path
1✔
183
        cli_members.current_dir = self.path
1✔
184
        cli_members.dao = dao
1✔
185

186
        # create badge endpoints
187
        cli_members.create_badge_endpoints()
1✔
188

189
        # gets a short url and updates the list in qisk.it/ecosystem-badges
190
        cli_members.update_badge_list()
1✔
191

192
        badges_folder_path = f"{cli_members.current_dir}/badges"
1✔
193
        self.assertTrue(
1✔
194
            os.path.isfile(f"{badges_folder_path}/{commu_success.short_uuid}")
195
        )
196

197
        # check version status
198
        with open(
1✔
199
            f"{badges_folder_path}/{commu_success.short_uuid}", "r"
200
        ) as json_blueviolet:
201
            json_success = json_blueviolet.read()
1✔
202
        self.assertTrue('"color": "6929C4"' in json_success)
1✔
203

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

© 2026 Coveralls, Inc