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

fedora-llvm-team / llvm-snapshots / 9129321498

17 May 2024 01:50PM UTC coverage: 69.211% (+1.5%) from 67.674%
9129321498

push

github

kwk
Add pre-commit: https://github.com/asottile/pyupgrade

2 of 2 new or added lines in 1 file covered. (100.0%)

73 existing lines in 9 files now uncovered.

1052 of 1520 relevant lines covered (69.21%)

0.69 hits per line

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

91.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 tests.base_test as base_test
1✔
8

9
import snapshot_manager.github_util as github_util
1✔
10

11

12
class TestGithub(base_test.TestBase):
1✔
13
    def test_create_or_get_todays_github_issue(self):
1✔
14
        """Creates or gets today's github issue"""
15
        gh = github_util.GithubClient(config=self.config)
1✔
16
        issue, _ = gh.create_or_get_todays_github_issue(
1✔
17
            maintainer_handle="kwk", creator="kwk"
18
        )
19
        self.assertIsNotNone(issue)
1✔
20

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

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

36
        marker = "<!--REACT_TO_COMMMENT-->"
1✔
37
        comment = gh.create_or_update_comment(
1✔
38
            issue=issue, comment_body=f"{marker} Comment to react to", marker=marker
39
        )
40
        self.assertTrue(gh.add_comment_reaction(comment, github_util.Reaction.HEART))
1✔
41
        self.assertTrue(
1✔
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
    def test_flip_test_label(self):
1✔
68
        gh = github_util.GithubClient(config=self.config)
1✔
69
        issue = gh.gh_repo.create_issue(
1✔
70
            title=f"TestGithub.test_flip_test_label {uuid.uuid4()}",
71
            body="This comment is for testing TestGithub.test_flip_test_label",
72
        )
73
        self.assertIsNotNone(issue)
1✔
74

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

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

89
        in_testing = gh.label_in_testing(chroot=chroot)
1✔
90
        failed_on = gh.label_failed_on(chroot=chroot)
1✔
91
        tested_on = gh.label_tested_on(chroot=chroot)
1✔
92

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

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

111

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

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

UNCOV
120
    import snapshot_manager.github_util
×
121

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

125

126
if __name__ == "__main__":
1✔
UNCOV
127
    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