Esempio n. 1
0
    def _get_random_reviewers(self, random_number: int,
                              pr_author: str) -> typing.Set[str]:
        choices = {
            **{
                user.lower(): weight
                for user, weight in self.config["users"].items()
            },
            **{
                f"@{team.team}": weight
                for team, weight in self.config["teams"].items()
            },
        }

        try:
            del choices[pr_author.lower()]
        except KeyError:
            pass

        count = min(self.config["random_count"], len(choices))

        return utils.get_random_choices(
            random_number,
            choices,
            count,
        )
    def _get_random_reviewers(self, random_number: int, pr_author: str) -> set:
        if isinstance(self.config["users"], dict):
            user_weights = self.config["users"]
        else:
            user_weights = {user: 1 for user in self.config["users"]}

        if isinstance(self.config["teams"], dict):
            team_weights = self.config["teams"]
        else:
            team_weights = {team: 1 for team in self.config["teams"]}

        choices = {
            **{user.lower(): weight
               for user, weight in user_weights.items()},
            **{f"@{team}": weight
               for team, weight in team_weights.items()},
        }

        try:
            del choices[pr_author.lower()]
        except KeyError:
            pass

        count = min(self.config["random_count"], len(choices))

        return utils.get_random_choices(
            random_number,
            choices,
            count,
        )
Esempio n. 3
0
def test_get_random_choices():
    choices = {
        "jd": 10,
        "sileht": 1,
        "foobar": 3,
    }
    assert utils.get_random_choices(0, choices, 1) == {"foobar"}
    assert utils.get_random_choices(1, choices, 1) == {"foobar"}
    assert utils.get_random_choices(2, choices, 1) == {"foobar"}
    assert utils.get_random_choices(3, choices, 1) == {"jd"}
    assert utils.get_random_choices(4, choices, 1) == {"jd"}
    assert utils.get_random_choices(11, choices, 1) == {"jd"}
    assert utils.get_random_choices(12, choices, 1) == {"jd"}
    assert utils.get_random_choices(13, choices, 1) == {"sileht"}
    assert utils.get_random_choices(14, choices, 1) == {"foobar"}
    assert utils.get_random_choices(15, choices, 1) == {"foobar"}
    assert utils.get_random_choices(16, choices, 1) == {"foobar"}
    assert utils.get_random_choices(17, choices, 1) == {"jd"}
    assert utils.get_random_choices(18, choices, 1) == {"jd"}
    assert utils.get_random_choices(19, choices, 1) == {"jd"}
    assert utils.get_random_choices(20, choices, 1) == {"jd"}
    assert utils.get_random_choices(21, choices, 1) == {"jd"}
    assert utils.get_random_choices(22, choices, 1) == {"jd"}
    assert utils.get_random_choices(23, choices, 1) == {"jd"}
    assert utils.get_random_choices(24, choices, 1) == {"jd"}
    assert utils.get_random_choices(25, choices, 1) == {"jd"}
    assert utils.get_random_choices(26, choices, 1) == {"jd"}
    assert utils.get_random_choices(27, choices, 1) == {"sileht"}
    assert utils.get_random_choices(28, choices, 1) == {"foobar"}
    assert utils.get_random_choices(29, choices, 1) == {"foobar"}
    assert utils.get_random_choices(30, choices, 1) == {"foobar"}
    assert utils.get_random_choices(31, choices, 1) == {"jd"}
    assert utils.get_random_choices(32, choices, 1) == {"jd"}
    assert utils.get_random_choices(23, choices, 2) == {"sileht", "jd"}
    assert utils.get_random_choices(2, choices, 2) == {"jd", "foobar"}
    assert utils.get_random_choices(4, choices, 2) == {"jd", "foobar"}
    assert utils.get_random_choices(0, choices,
                                    3) == {"jd", "sileht", "foobar"}
    with pytest.raises(ValueError):
        assert utils.get_random_choices(4, choices, 4) == {"jd", "sileht"}