civics-cdf-validator 1.69.dev3__tar.gz → 1.69.dev5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {civics_cdf_validator-1.69.dev3/civics_cdf_validator.egg-info → civics_cdf_validator-1.69.dev5}/PKG-INFO +1 -1
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5/civics_cdf_validator.egg-info}/PKG-INFO +1 -1
- civics_cdf_validator-1.69.dev5/rulesets/election_results_rules.py +108 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/version.py +1 -1
- civics_cdf_validator-1.69.dev3/rulesets/election_results_rules.py +0 -54
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/CONTRIBUTING.md +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/LICENSE-2.0.txt +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/MANIFEST.in +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/README.md +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/__init__.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/base.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/civics_cdf_validator.egg-info/SOURCES.txt +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/civics_cdf_validator.egg-info/dependency_links.txt +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/civics_cdf_validator.egg-info/entry_points.txt +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/civics_cdf_validator.egg-info/requires.txt +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/civics_cdf_validator.egg-info/top_level.txt +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/gpunit_rules.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/loggers.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/office_utils.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rules.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rulesets/__init__.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rulesets/committee_rules.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rulesets/common_rules.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rulesets/election_dates_rules.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rulesets/election_rules.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rulesets/metadata_rules.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rulesets/officeholder_rules.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rulesets/rule_util.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rulesets/voter_information_rules.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/setup.cfg +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/setup.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/stats.py +0 -0
- {civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/validator.py +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Copyright 2026 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
"""Validation rules for election results feeds of the CDF XML validator."""
|
|
15
|
+
|
|
16
|
+
from civics_cdf_validator import base
|
|
17
|
+
from civics_cdf_validator import loggers
|
|
18
|
+
from civics_cdf_validator.rulesets import election_rules
|
|
19
|
+
from lxml import etree
|
|
20
|
+
|
|
21
|
+
_REQUIRED_CONTEST_RESULTS_FIELDS = (
|
|
22
|
+
"CurrentResultsReportingStage",
|
|
23
|
+
"ResultsReportingStageCollection",
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
_SUB_UNITS_FIELD_NAMES = ("SubUnitsReported", "TotalSubUnits")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class RequiredContestResultsFieldsSet(base.SchemaRule):
|
|
30
|
+
"""Checks that every Contest sets its results reporting stage fields.
|
|
31
|
+
|
|
32
|
+
Election results feeds must set CurrentResultsReportingStage and
|
|
33
|
+
ResultsReportingStageCollection on every Contest.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def elements(self) -> list[str]:
|
|
37
|
+
return ["Contest"] + list(self.get_all_subtypes("Contest"))
|
|
38
|
+
|
|
39
|
+
def check(self, element: etree._Element) -> None:
|
|
40
|
+
missing_fields = [
|
|
41
|
+
field
|
|
42
|
+
for field in _REQUIRED_CONTEST_RESULTS_FIELDS
|
|
43
|
+
if element.find(field) is None
|
|
44
|
+
]
|
|
45
|
+
if missing_fields:
|
|
46
|
+
raise loggers.ElectionError.from_message(
|
|
47
|
+
f"Contest {element.get('objectId')} is missing required field(s)"
|
|
48
|
+
f" {', '.join(missing_fields)}. Election results feeds must set"
|
|
49
|
+
f" {', '.join(_REQUIRED_CONTEST_RESULTS_FIELDS)} on every Contest.",
|
|
50
|
+
[element],
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class DataSourcesRequired(base.BaseRule):
|
|
55
|
+
"""Checks that the ElectionReport sets a DataSourceCollection.
|
|
56
|
+
|
|
57
|
+
Election results feeds must set a DataSourceCollection on the ElectionReport
|
|
58
|
+
so that their results can be attributed to their data sources.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def elements(self) -> list[str]:
|
|
62
|
+
return ["ElectionReport"]
|
|
63
|
+
|
|
64
|
+
def check(self, element: etree._Element) -> None:
|
|
65
|
+
if element.find("DataSourceCollection") is None:
|
|
66
|
+
raise loggers.ElectionError.from_message(
|
|
67
|
+
"ElectionReport is missing required field DataSourceCollection."
|
|
68
|
+
" Election results feeds must set DataSourceCollection on the"
|
|
69
|
+
" ElectionReport.",
|
|
70
|
+
[element],
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class ValidatePercentReporting(base.SchemaRule):
|
|
75
|
+
"""Checks that every Contest sets the fields used for its percent reporting.
|
|
76
|
+
|
|
77
|
+
Election results feeds must set either EstimatedExpectedVotePercentage or
|
|
78
|
+
both SubUnitsReported and TotalSubUnits on every Contest.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
def elements(self) -> list[str]:
|
|
82
|
+
return ["Contest"] + list(self.get_all_subtypes("Contest"))
|
|
83
|
+
|
|
84
|
+
def check(self, element: etree._Element) -> None:
|
|
85
|
+
if element.find("EstimatedExpectedVotePercentage") is not None:
|
|
86
|
+
return
|
|
87
|
+
missing_sub_units_fields = [
|
|
88
|
+
field for field in _SUB_UNITS_FIELD_NAMES if element.find(field) is None
|
|
89
|
+
]
|
|
90
|
+
if missing_sub_units_fields:
|
|
91
|
+
raise loggers.ElectionError.from_message(
|
|
92
|
+
f"Contest {element.get('objectId')} is missing field(s)"
|
|
93
|
+
" EstimatedExpectedVotePercentage,"
|
|
94
|
+
f" {', '.join(missing_sub_units_fields)}."
|
|
95
|
+
" Election results feeds must set either"
|
|
96
|
+
" EstimatedExpectedVotePercentage or both SubUnitsReported and"
|
|
97
|
+
" TotalSubUnits on every Contest.",
|
|
98
|
+
[element],
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
ELECTION_RESULTS_RULES = election_rules.ELECTION_RULES + (
|
|
103
|
+
# go/keep-sorted start
|
|
104
|
+
DataSourcesRequired,
|
|
105
|
+
RequiredContestResultsFieldsSet,
|
|
106
|
+
ValidatePercentReporting,
|
|
107
|
+
# go/keep-sorted end
|
|
108
|
+
)
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# Copyright 2026 Google LLC
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
"""Validation rules for election results feeds of the CDF XML validator."""
|
|
15
|
-
|
|
16
|
-
from civics_cdf_validator import base
|
|
17
|
-
from civics_cdf_validator import loggers
|
|
18
|
-
from civics_cdf_validator.rulesets import election_rules
|
|
19
|
-
from lxml import etree
|
|
20
|
-
|
|
21
|
-
_REQUIRED_CONTEST_RESULTS_FIELDS = (
|
|
22
|
-
"CurrentResultsReportingStage",
|
|
23
|
-
"ResultsReportingStageCollection",
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class RequiredContestResultsFieldsSet(base.SchemaRule):
|
|
28
|
-
"""Checks that every Contest sets its results reporting stage fields.
|
|
29
|
-
|
|
30
|
-
Election results feeds must set CurrentResultsReportingStage and
|
|
31
|
-
ResultsReportingStageCollection on every Contest.
|
|
32
|
-
"""
|
|
33
|
-
|
|
34
|
-
def elements(self) -> list[str]:
|
|
35
|
-
return ["Contest"] + list(self.get_all_subtypes("Contest"))
|
|
36
|
-
|
|
37
|
-
def check(self, element: etree._Element) -> None:
|
|
38
|
-
missing_fields = [
|
|
39
|
-
field
|
|
40
|
-
for field in _REQUIRED_CONTEST_RESULTS_FIELDS
|
|
41
|
-
if element.find(field) is None
|
|
42
|
-
]
|
|
43
|
-
if missing_fields:
|
|
44
|
-
raise loggers.ElectionError.from_message(
|
|
45
|
-
f"Contest {element.get('objectId')} is missing required field(s)"
|
|
46
|
-
f" {', '.join(missing_fields)}. Election results feeds must set"
|
|
47
|
-
f" {', '.join(_REQUIRED_CONTEST_RESULTS_FIELDS)} on every Contest.",
|
|
48
|
-
[element],
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
ELECTION_RESULTS_RULES = election_rules.ELECTION_RULES + (
|
|
53
|
-
RequiredContestResultsFieldsSet,
|
|
54
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rulesets/committee_rules.py
RENAMED
|
File without changes
|
|
File without changes
|
{civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rulesets/election_dates_rules.py
RENAMED
|
File without changes
|
{civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rulesets/election_rules.py
RENAMED
|
File without changes
|
{civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rulesets/metadata_rules.py
RENAMED
|
File without changes
|
{civics_cdf_validator-1.69.dev3 → civics_cdf_validator-1.69.dev5}/rulesets/officeholder_rules.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|