Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/buildrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: 'Setup python'
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.12'
- name: 'Setup Rust'
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: 'Clone pyapp'
Expand All @@ -27,6 +27,7 @@ jobs:
- name: 'Build'
run: |
pip install hatch
hatch run test
hatch build
wget https://github.com/indygreg/python-build-standalone/releases/download/20240415/cpython-3.12.3%2B20240415-x86_64_v3-unknown-linux-gnu-install_only.tar.gz -O my_cpython.tar.gz
tar -xzf my_cpython.tar.gz
Expand Down Expand Up @@ -72,6 +73,7 @@ jobs:
- name: 'Build'
run: |
pip install hatch
hatch run test
hatch build
Invoke-WebRequest "https://github.com/indygreg/python-build-standalone/releases/download/20240415/cpython-3.12.3%2B20240415-x86_64-pc-windows-msvc-install_only.tar.gz" -OutFile "my_cpython.tar.gz"
tar -xzf my_cpython.tar.gz
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Run tests

on: [push]
jobs:
test:
name: "Run tests and build"
runs-on: "ubuntu-latest"
steps:
- name: 'Checkout code'
uses: actions/checkout@v4
- name: 'Setup python'
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: 'Install pip and run test suite'
run: |
pip install hatch
hatch run test
hatch build
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ cov-report = [
"- coverage combine",
"coverage report",
]
cov-html = [
"coverage html",
]
cov = [
"test-cov",
"cov-report",
Expand Down
1 change: 1 addition & 0 deletions tests/Kandidatenlijsten_GR2022_WestMaasenWaal.eml.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/Kandidatenlijsten_TK2025_Haarlem.eml.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/Kandidatenlijsten_TK2025_Nijmegen.eml.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/Telling_GR2022_WestMaasenWaal.eml.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/Telling_TK2025_gemeente_West_Maas_en_Waal.eml.xml

Large diffs are not rendered by default.

283 changes: 283 additions & 0 deletions tests/osv4-3_telling_gr2022westmaasenwaal_gemeente_westmaasenwaal.csv

Large diffs are not rendered by default.

1,133 changes: 1,133 additions & 0 deletions tests/osv4-3_telling_tk2025_gemeente_westmaasenwaal.csv

Large diffs are not rendered by default.

104 changes: 104 additions & 0 deletions tests/test_eml2csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import os
from pathlib import Path

import pytest

from eml2csv import eml2csv
from eml2csv.lib import InvalidInputException

tests_path = Path("tests")


def test_tk25_output_csv_matches_oracle_file(tmp_path):
output_csv = "osv4-3_telling_tk2025_gemeente_westmaasenwaal.csv"
eml2csv(
counts_eml_path="tests/Telling_TK2025_gemeente_West_Maas_en_Waal.eml.xml",
candidates_eml_path="tests/Kandidatenlijsten_TK2025_Nijmegen.eml.xml",
output_csv_path=str(tmp_path / output_csv),
)

expected = open(tests_path / output_csv).readlines()
actual = open(tmp_path / output_csv).readlines()

assert expected == actual, f"Output file differences: {tmp_path / output_csv}"


def test_gr22_output_csv_matches_oracle_file(tmp_path):
output_csv = "osv4-3_telling_gr2022westmaasenwaal_gemeente_westmaasenwaal.csv"
eml2csv(
counts_eml_path="tests/Telling_GR2022_WestMaasenWaal.eml.xml",
candidates_eml_path="tests/Kandidatenlijsten_GR2022_WestMaasenWaal.eml.xml",
output_csv_path=str(tmp_path / output_csv),
)

expected = open(tests_path / output_csv).readlines()
actual = open(tmp_path / output_csv).readlines()

assert expected == actual, f"Output file differences: {tmp_path / output_csv}"

@pytest.fixture
def change_to_tmp_path(tmp_path):
# Output csv is written to current directory,
# so we have to change the current directory to the temp directory
# while still having a valid path to our input files.
cwd = Path.cwd()
os.chdir(tmp_path)
yield cwd, tmp_path
os.chdir(cwd)

def test_tk25_output_csv_file_generated(change_to_tmp_path):
output_csv = "osv4-3_telling_tk2025_gemeente_westmaasenwaal.csv"
old_path, new_path = change_to_tmp_path

assert os.listdir(new_path) == []

eml2csv(
counts_eml_path=str(old_path / "tests/Telling_TK2025_gemeente_West_Maas_en_Waal.eml.xml"),
candidates_eml_path=str(old_path / "tests/Kandidatenlijsten_TK2025_Nijmegen.eml.xml"),
output_csv_path=None,
)

assert os.listdir(new_path) == [output_csv]

expected = open(old_path / "tests" / output_csv).readlines()
actual = open(new_path / output_csv).readlines()

assert expected == actual, f"Output file differences: {new_path / output_csv}"


def test_counts_file_is_not_an_eml_510b():
with pytest.raises(InvalidInputException, match=r"was not an EML counts file \(510b\)"):
eml2csv(
counts_eml_path="tests/Kandidatenlijsten_TK2025_Nijmegen.eml.xml",
candidates_eml_path="tests/Kandidatenlijsten_TK2025_Nijmegen.eml.xml",
output_csv_path=None,
)


def test_candidates_file_is_not_an_eml_230b():
with pytest.raises(InvalidInputException, match=r"was not an EML candidates file \(230b\)"):
eml2csv(
counts_eml_path="tests/Telling_TK2025_gemeente_West_Maas_en_Waal.eml.xml",
candidates_eml_path="tests/Telling_TK2025_gemeente_West_Maas_en_Waal.eml.xml",
output_csv_path=None,
)


def test_contest_ids_do_not_match():
with pytest.raises(InvalidInputException,
match=r"Contest ids did not match! Counts file was 6 while candidates file was 10"):
eml2csv(
counts_eml_path="tests/Telling_TK2025_gemeente_West_Maas_en_Waal.eml.xml",
candidates_eml_path="tests/Kandidatenlijsten_TK2025_Haarlem.eml.xml",
output_csv_path=None,
)

def test_election_ids_do_not_match():
with pytest.raises(InvalidInputException,
match=r"Election ids did not match! Counts file was TK2025 while candidates file was GR2022_WestMaasenWaal"):
eml2csv(
counts_eml_path="tests/Telling_TK2025_gemeente_West_Maas_en_Waal.eml.xml",
candidates_eml_path="tests/Kandidatenlijsten_GR2022_WestMaasenWaal.eml.xml",
output_csv_path=None,
)