This repository has been archived on 2021-05-25. You can view files and clone it, but cannot push or open issues or pull requests.
pyRCV2/tests/test_constraints_validation.py

41 lines
1.6 KiB
Python
Raw Normal View History

2021-05-22 01:38:36 +10:00
# pyRCV2: Preferential vote counting
# Copyright © 2020–2021 Lee Yingtong Li (RunasSudo)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import pytest
import pyRCV2.blt, pyRCV2.con
from pyRCV2.constraints import ConstraintException
def test_constraints_validation_invalid1():
with open('tests/data/prsa1.blt', 'r') as f:
election = pyRCV2.blt.readBLT(f.read())
with open('tests/data/prsa1_invalid1.con', 'r') as f:
election.constraints = pyRCV2.con.readCON(f.read(), election)
with pytest.raises(ConstraintException, match='Candidate "Evans" not assigned to a group in category "Gender"'):
election.validate_constraints()
def test_constraints_validation_invalid2():
with open('tests/data/prsa1.blt', 'r') as f:
election = pyRCV2.blt.readBLT(f.read())
with open('tests/data/prsa1_invalid2.con', 'r') as f:
election.constraints = pyRCV2.con.readCON(f.read(), election)
with pytest.raises(ConstraintException, match='Candidate "Grey" duplicated in category "Gender"'):
election.validate_constraints()