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

fedora-llvm-team / llvm-snapshots / 11269302141

10 Oct 2024 07:19AM UTC coverage: 61.451% (-8.7%) from 70.198%
11269302141

push

github

web-flow
Get CI green again (#774)

Changes in here check for chroots in a better way and don't allow unexpected names, versions or architectures.

Two tests (`test_create_or_get_todays_github_issue`, `test_flip_label`) that always fail because of missing token are now skipped until I've found a way to get them to work again.

* Add coverage python module
Needed for running `make test-snapshot-manager`.
* Properly handle chroots with regexes
* Fix tests
* Skip two github tests for now because of missing token

25 of 25 new or added lines in 3 files covered. (100.0%)

188 existing lines in 6 files now uncovered.

974 of 1585 relevant lines covered (61.45%)

0.61 hits per line

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

38.67
/snapshot_manager/tests/github_util_test.py
1
""" Tests for github """
2

3
import datetime
1✔
4
import logging
1✔
5
import uuid
1✔
6

7
import pytest
1✔
8
import tests.base_test as base_test
1✔
9

10
import snapshot_manager.github_util as github_util
1✔
11

12

13
class TestGithub(base_test.TestBase):
1✔
14
    @pytest.mark.skip(reason="Skip this for now because of token issue")
1✔
15
    def test_create_or_get_todays_github_issue(self):
1✔
16
        """Creates or gets today's github issue"""
UNCOV
17
        gh = github_util.GithubClient(config=self.config)
×
UNCOV
18
        issue, _ = gh.create_or_get_todays_github_issue(creator="kwk")
×
UNCOV
19
        self.assertIsNotNone(issue)
×
20

UNCOV
21
        marker = "<!--HIDE_COMMMENT-->"
×
UNCOV
22
        comment = gh.create_or_update_comment(
×
23
            issue=issue, comment_body=f"{marker} Comment to be hidden", marker=marker
24
        )
UNCOV
25
        self.assertTrue(gh.minimize_comment_as_outdated(comment))
×
26

UNCOV
27
        marker = "<!--HIDE_AND_UNHIDE_COMMMENT-->"
×
UNCOV
28
        comment = gh.create_or_update_comment(
×
29
            issue=issue,
30
            comment_body=f"{marker} Comment to be hidden and unhidden",
31
            marker=marker,
32
        )
UNCOV
33
        self.assertTrue(gh.minimize_comment_as_outdated(comment))
×
UNCOV
34
        self.assertTrue(gh.unminimize_comment(comment))
×
35

UNCOV
36
        marker = "<!--REACT_TO_COMMMENT-->"
×
UNCOV
37
        comment = gh.create_or_update_comment(
×
38
            issue=issue, comment_body=f"{marker} Comment to react to", marker=marker
39
        )
UNCOV
40
        self.assertTrue(gh.add_comment_reaction(comment, github_util.Reaction.HEART))
×
UNCOV
41
        self.assertTrue(
×
42
            gh.add_comment_reaction(comment, github_util.Reaction.THUMBS_UP)
43
        )
44

45
    def test_get_todays_issue(self):
1✔
46
        """Get today's github issue"""
47
        # Example: Get issue for day in the past
48
        cfg = self.config
1✔
49
        cfg.datetime = datetime.datetime(year=2024, month=2, day=27)
1✔
50
        self.assertEqual("20240227", cfg.yyyymmdd)
1✔
51
        gh = github_util.GithubClient(config=cfg)
1✔
52

53
        issue = gh.get_todays_github_issue(
1✔
54
            strategy="big-merge", github_repo="fedora-llvm-team/llvm-snapshots"
55
        )
56

57
        self.assertIsNotNone(issue)
1✔
58
        self.assertEqual(287, issue.number)
1✔
59

60
        # Example: Get issue when in fact, no issue was created (should be always True for the day after tomorrow)
61
        cfg.datetime = datetime.datetime.now(datetime.UTC) + datetime.timedelta(days=2)
1✔
62
        issue = gh.get_todays_github_issue(
1✔
63
            strategy="big-merge", github_repo="fedora-llvm-team/llvm-snapshots"
64
        )
65
        self.assertIsNone(issue)
1✔
66

67
    @pytest.mark.skip(reason="Skip this for now because of token issue")
1✔
68
    def test_flip_test_label(self):
1✔
UNCOV
69
        gh = github_util.GithubClient(config=self.config)
×
UNCOV
70
        issue = gh.gh_repo.create_issue(
×
71
            title=f"TestGithub.test_flip_test_label {uuid.uuid4()}",
72
            body="This comment is for testing TestGithub.test_flip_test_label",
73
        )
UNCOV
74
        self.assertIsNotNone(issue)
×
75

76
        # Remove all labels
UNCOV
77
        logging.info(f"Removing all labels from issue: {issue.html_url}")
×
UNCOV
78
        for label in issue.get_labels():
×
79
            issue.remove_from_labels(label)
×
UNCOV
80
        self.assertEqual(issue.get_labels().totalCount, 0)
×
81

82
        # Ensure those labels that we need for our test exist
UNCOV
83
        chroot = "fedora-rawhide-x86_64"
×
UNCOV
84
        all_chroots = [chroot]
×
UNCOV
85
        logging.info("Creating test labels")
×
UNCOV
86
        gh.create_labels_for_in_testing(all_chroots)
×
UNCOV
87
        gh.create_labels_for_tests_failed_on(all_chroots)
×
UNCOV
88
        gh.create_labels_for_tested_on(all_chroots)
×
89

UNCOV
90
        in_testing = gh.label_in_testing(chroot=chroot)
×
UNCOV
91
        failed_on = gh.label_failed_on(chroot=chroot)
×
UNCOV
92
        tested_on = gh.label_tested_on(chroot=chroot)
×
93

UNCOV
94
        all_test_states = [in_testing, failed_on, tested_on]
×
UNCOV
95
        for test_state in all_test_states:
×
UNCOV
96
            logging.info(f"Flipping test label for chroot {chroot} to: {test_state}")
×
UNCOV
97
            gh.flip_test_label(issue, chroot, test_state)
×
UNCOV
98
            labels = issue.get_labels()
×
UNCOV
99
            self.assertIsNotNone(labels)
×
UNCOV
100
            self.assertEqual(labels.totalCount, 1)
×
UNCOV
101
            page = labels.get_page(0)
×
UNCOV
102
            self.assertIsNotNone(page)
×
UNCOV
103
            self.assertEqual(page[0].name, test_state)
×
UNCOV
104
        pass
×
105

106
    def test_get_workflow(self):
1✔
107
        gh = github_util.GithubClient(config=self.config)
1✔
108
        repo = gh.github.get_repo("fedora-llvm-team/llvm-snapshots")
1✔
109
        workflow = repo.get_workflow("check-snapshots.yml")
1✔
110
        self.assertIsNotNone(workflow)
1✔
111

112

113
def load_tests(loader, tests, ignore):
1✔
114
    """We want unittest to pick up all of our doctests
115

116
    See https://docs.python.org/3/library/unittest.html#load-tests-protocol
117
    See https://stackoverflow.com/a/27171468
118
    """
119
    import doctest
×
120

121
    import snapshot_manager.github_util
×
122

123
    tests.addTests(doctest.DocTestSuite(snapshot_manager.github_util))
×
124
    return tests
×
125

126

127
if __name__ == "__main__":
1✔
128
    base_test.run_tests()
×
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