-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from socrse/add_tests
Parse CSV columns into a MultiIndex
- Loading branch information
Showing
6 changed files
with
99 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- "master" | ||
pull_request: | ||
branches: | ||
- "master" | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.10" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt -r requirements-dev.txt | ||
- name: Test with pytest | ||
run: | | ||
python -m pytest -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pytest | ||
mypy | ||
pandas-stubs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
import pandas as pd | ||
|
||
from utils import parse_google_form, run_stv, count_votes_simple | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def simple_file(): | ||
test_dir = Path(__file__).resolve().parent | ||
return parse_google_form(test_dir / "votes.csv", "Token") | ||
|
||
|
||
def test_parse_csv(simple_file): | ||
assert pd.api.types.is_string_dtype(simple_file.index) | ||
assert simple_file.index.is_unique | ||
assert all(pd.api.types.is_string_dtype(c) for _, c in simple_file.items()) | ||
assert "Resolutions" in simple_file.columns | ||
assert "Resolution 1" in simple_file["Resolutions"] | ||
|
||
|
||
def test_stv(simple_file): | ||
res = run_stv(simple_file, "Rank candidates required", 1) | ||
winners = res.get_winners() | ||
assert len(winners) == 1 | ||
assert winners[0].name == "Person 1" | ||
|
||
|
||
def test_simple(simple_file): | ||
res = count_votes_simple(simple_file["Resolutions"]["Resolution 1"]) | ||
assert res == (2, 3, 2, 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"Timestamp","Token","Rank candidates required [Person 3]","Rank candidates required [Person 2]","Rank candidates required [Person 4]","Rank candidates required [Person 1]","Rank candidates optional [Person 2]","Rank candidates optional [Person 1]","Rank candidates optional [Person 4]","Rank candidates optional [Person 3]","Resolutions [Resolution 1]","Resolutions [Resolution 2]","dropdown","multiple choice","Checkboxes","tickbox grid [Row 1]","tickbox grid [Row 2]","tickbox grid 2 [Row 1]","tickbox grid 2 [Row 2]" | ||
"2023/08/10 11:10:56 am CET","jdjfghdj","3","2","4","1","2","1","4","","Approve","Reject","","","","","","","" | ||
"2023/08/10 11:11:16 am CET","ghghdgn","2","3","4","1","","1","2","3","Reject","Approve","","","","","","","" | ||
"2023/08/10 11:11:41 am CET","jmhmjm","4","3","2","1","1","4","3","2","Abstain","Reject","","","","","","","" | ||
"2023/08/10 11:11:56 am CET","hfgdhdfg","1","4","2","3","","","","","Abstain","Abstain","","","","","","","" | ||
"2023/08/10 11:56:46 am CET","dfgdfadf","3","4","1","2","3","4","2","1","Reject","Approve","","","","","","","" | ||
"2023/08/10 11:57:11 am CET","gdgdv","4","3","2","1","","2","","3","Approve","Abstain","Option 2","Option 2","Option 1;Option 2","Column 1;Column 2","","","" | ||
"2023/08/10 11:58:51 am CET","fghgshds","4","3","2","1","","","","2","Reject","Approve","","","","Column 1","Column 2","Column 2","Column 1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters