def test_apply_rules(param_dict):

    b = BallotMarks(param_dict['input']['marks'])
    b.apply_rules(**param_dict['input']['rules'])

    assert b.marks == param_dict['expected']['marks']
    assert b.unique_marks == param_dict['expected']['unique_marks']
    assert b.unique_candidates == param_dict['expected']['unique_candidates']
Пример #2
0
    def _make_candidate_set(self, rule_set_name: str) -> None:

        if rule_set_name not in self._rule_sets:
            raise RuntimeError(f'rule set {rule_set_name} has not yet been added using add_rule_set().')

        cvr = self._parsed_cvr

        # unpack rules
        rule_set = self._rule_sets[rule_set_name]
        combine_writeins = rule_set['combine_writein_marks']
        exclude_writeins = rule_set['exclude_writein_marks']

        candidate_ballot_marks = BallotMarks(set.union(*[b.unique_candidates for b in cvr['ballot_marks']]))
        candidate_ballot_marks.apply_rules(combine_writein_marks=combine_writeins, exclude_writein_marks=exclude_writeins)

        self._candidate_sets.update({rule_set_name: candidate_ballot_marks})
def test_apply_rules_errors():

    with pytest.raises(RuntimeError):
        b = BallotMarks(['A', 'B', 'C'])
        b.apply_rules()
        b.apply_rules()