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

fedora-llvm-team / llvm-snapshots / 8759795041

19 Apr 2024 09:26PM UTC coverage: 67.159% (-2.1%) from 69.287%
8759795041

Pull #425

github

kwk
test: fix test_flip_test_label test
Pull Request #425: Retest

47 of 128 new or added lines in 5 files covered. (36.72%)

3 existing lines in 2 files now uncovered.

1000 of 1489 relevant lines covered (67.16%)

0.67 hits per line

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

91.04
/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
import snapshot_manager.github_util as github_util
1✔
9

10

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

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

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

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

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

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

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

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

66
    def test_flip_test_label(self):
1✔
67
        gh = github_util.GithubClient(config=self.config)
1✔
68
        issue = gh.gh_repo.create_issue(
1✔
69
            title=f"TestGithub.test_flip_test_label {uuid.uuid4()}",
70
            body="This comment is for testing TestGithub.test_flip_test_label",
71
        )
72
        self.assertIsNotNone(issue)
1✔
73

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

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

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

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

104

105
def load_tests(loader, tests, ignore):
1✔
106
    """We want unittest to pick up all of our doctests
107

108
    See https://docs.python.org/3/library/unittest.html#load-tests-protocol
109
    See https://stackoverflow.com/a/27171468
110
    """
111
    import doctest
×
112

113
    import snapshot_manager.github_util
×
114

115
    tests.addTests(doctest.DocTestSuite(snapshot_manager.github_util))
×
116
    return tests
×
117

118

119
if __name__ == "__main__":
1✔
120
    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