civics-cdf-validator 1.68.dev10__tar.gz → 1.68.dev12__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.68.dev10/civics_cdf_validator.egg-info → civics_cdf_validator-1.68.dev12}/PKG-INFO +1 -1
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/base.py +35 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12/civics_cdf_validator.egg-info}/PKG-INFO +1 -1
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/civics_cdf_validator.egg-info/SOURCES.txt +1 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rules.py +3 -0
- civics_cdf_validator-1.68.dev12/rulesets/election_results_rules.py +53 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/validator.py +1 -1
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/version.py +1 -1
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/CONTRIBUTING.md +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/LICENSE-2.0.txt +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/MANIFEST.in +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/README.md +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/__init__.py +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/civics_cdf_validator.egg-info/dependency_links.txt +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/civics_cdf_validator.egg-info/entry_points.txt +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/civics_cdf_validator.egg-info/requires.txt +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/civics_cdf_validator.egg-info/top_level.txt +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/gpunit_rules.py +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/loggers.py +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/office_utils.py +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/__init__.py +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/committee_rules.py +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/common_rules.py +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/election_dates_rules.py +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/election_rules.py +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/metadata_rules.py +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/officeholder_rules.py +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/rule_util.py +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/voter_information_rules.py +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/setup.cfg +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/setup.py +0 -0
- {civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/stats.py +0 -0
|
@@ -16,6 +16,7 @@ limitations under the License.
|
|
|
16
16
|
|
|
17
17
|
from __future__ import print_function
|
|
18
18
|
|
|
19
|
+
import collections
|
|
19
20
|
from collections.abc import Set
|
|
20
21
|
import datetime
|
|
21
22
|
import functools
|
|
@@ -111,6 +112,40 @@ class BaseRule(SchemaHandler):
|
|
|
111
112
|
def get_element_names_for_type(self, element_type: str) -> set[str]:
|
|
112
113
|
return self.get_element_names_for_types({element_type})
|
|
113
114
|
|
|
115
|
+
def get_all_subtypes(self, base_type: str) -> set[str]:
|
|
116
|
+
"""Returns every schema type that extends base_type, at any depth."""
|
|
117
|
+
direct_subtypes = collections.defaultdict(set)
|
|
118
|
+
for complex_type in self.schema_tree.iterfind(
|
|
119
|
+
f"{{{self._XSCHEMA_NAMESPACE}}}complexType"
|
|
120
|
+
):
|
|
121
|
+
extension = complex_type.find(
|
|
122
|
+
f"*/{{{self._XSCHEMA_NAMESPACE}}}extension"
|
|
123
|
+
)
|
|
124
|
+
if extension is None:
|
|
125
|
+
continue
|
|
126
|
+
parent_type = extension.get("base")
|
|
127
|
+
subtype = complex_type.get("name")
|
|
128
|
+
if parent_type and subtype:
|
|
129
|
+
direct_subtypes[parent_type].add(subtype)
|
|
130
|
+
|
|
131
|
+
subtypes = set()
|
|
132
|
+
types_to_visit = list(direct_subtypes[base_type])
|
|
133
|
+
while types_to_visit:
|
|
134
|
+
subtype = types_to_visit.pop()
|
|
135
|
+
if subtype not in subtypes:
|
|
136
|
+
subtypes.add(subtype)
|
|
137
|
+
types_to_visit.extend(direct_subtypes[subtype])
|
|
138
|
+
return subtypes
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class SchemaRule(BaseRule):
|
|
142
|
+
"""Rule that needs the schema tree to be present."""
|
|
143
|
+
|
|
144
|
+
def __init__(self, *args, **kwargs):
|
|
145
|
+
super(SchemaRule, self).__init__(*args, **kwargs)
|
|
146
|
+
if self.schema_tree is None:
|
|
147
|
+
raise ValueError(f"{type(self).__name__} requires a schema_tree.")
|
|
148
|
+
|
|
114
149
|
|
|
115
150
|
class TreeRule(BaseRule):
|
|
116
151
|
"""Rule that checks entire tree."""
|
|
@@ -20,6 +20,7 @@ import enum
|
|
|
20
20
|
from civics_cdf_validator.rulesets import committee_rules
|
|
21
21
|
from civics_cdf_validator.rulesets import common_rules
|
|
22
22
|
from civics_cdf_validator.rulesets import election_dates_rules
|
|
23
|
+
from civics_cdf_validator.rulesets import election_results_rules
|
|
23
24
|
from civics_cdf_validator.rulesets import election_rules
|
|
24
25
|
from civics_cdf_validator.rulesets import metadata_rules
|
|
25
26
|
from civics_cdf_validator.rulesets import officeholder_rules
|
|
@@ -45,6 +46,7 @@ ELECTION_RULES = election_rules.ELECTION_RULES
|
|
|
45
46
|
OFFICEHOLDER_RULES = officeholder_rules.OFFICEHOLDER_RULES
|
|
46
47
|
COMMITTEE_RULES = committee_rules.COMMITTEE_RULES
|
|
47
48
|
ELECTION_DATES_RULES = election_dates_rules.ELECTION_DATES_RULES
|
|
49
|
+
ELECTION_RESULTS_RULES = election_results_rules.ELECTION_RESULTS_RULES
|
|
48
50
|
METADATA_RULES = metadata_rules.METADATA_RULES
|
|
49
51
|
VOTER_INFORMATION_RULES = voter_information_rules.VOTER_INFORMATION_RULES
|
|
50
52
|
|
|
@@ -54,6 +56,7 @@ ALL_RULES = frozenset(
|
|
|
54
56
|
+ OFFICEHOLDER_RULES
|
|
55
57
|
+ COMMITTEE_RULES
|
|
56
58
|
+ ELECTION_DATES_RULES
|
|
59
|
+
+ ELECTION_RESULTS_RULES
|
|
57
60
|
+ VOTER_INFORMATION_RULES
|
|
58
61
|
+ METADATA_RULES
|
|
59
62
|
)
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
|
|
20
|
+
_REQUIRED_CONTEST_RESULTS_FIELDS = (
|
|
21
|
+
"CurrentResultsReportingStage",
|
|
22
|
+
"ResultsReportingStageCollection",
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class RequiredContestResultsFieldsSet(base.SchemaRule):
|
|
27
|
+
"""Checks that every Contest sets its results reporting stage fields.
|
|
28
|
+
|
|
29
|
+
Election results feeds must set CurrentResultsReportingStage and
|
|
30
|
+
ResultsReportingStageCollection on every Contest.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def elements(self) -> list[str]:
|
|
34
|
+
return ["Contest"] + list(self.get_all_subtypes("Contest"))
|
|
35
|
+
|
|
36
|
+
def check(self, element) -> None:
|
|
37
|
+
missing_fields = [
|
|
38
|
+
field
|
|
39
|
+
for field in _REQUIRED_CONTEST_RESULTS_FIELDS
|
|
40
|
+
if element.find(field) is None
|
|
41
|
+
]
|
|
42
|
+
if missing_fields:
|
|
43
|
+
raise loggers.ElectionError.from_message(
|
|
44
|
+
f"Contest {element.get('objectId')} is missing required field(s)"
|
|
45
|
+
f" {', '.join(missing_fields)}. Election results feeds must set"
|
|
46
|
+
f" {', '.join(_REQUIRED_CONTEST_RESULTS_FIELDS)} on every Contest.",
|
|
47
|
+
[element],
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
ELECTION_RESULTS_RULES = election_rules.ELECTION_RULES + (
|
|
52
|
+
RequiredContestResultsFieldsSet,
|
|
53
|
+
)
|
|
@@ -258,7 +258,7 @@ def filter_all_rules_using_user_arg(rules_allowlist, rule_set, rules_blocklist):
|
|
|
258
258
|
if rule_set == rules.RuleSet.ELECTION:
|
|
259
259
|
rule_names = [rule.__name__ for rule in rules.ELECTION_RULES]
|
|
260
260
|
elif rule_set == rules.RuleSet.ELECTION_RESULTS:
|
|
261
|
-
rule_names = [rule.__name__ for rule in rules.
|
|
261
|
+
rule_names = [rule.__name__ for rule in rules.ELECTION_RESULTS_RULES]
|
|
262
262
|
elif rule_set == rules.RuleSet.OFFICEHOLDER:
|
|
263
263
|
rule_names = [rule.__name__ for rule in rules.OFFICEHOLDER_RULES]
|
|
264
264
|
elif rule_set == rules.RuleSet.COMMITTEE:
|
|
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.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/committee_rules.py
RENAMED
|
File without changes
|
{civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/common_rules.py
RENAMED
|
File without changes
|
{civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/election_dates_rules.py
RENAMED
|
File without changes
|
{civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/election_rules.py
RENAMED
|
File without changes
|
{civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/metadata_rules.py
RENAMED
|
File without changes
|
{civics_cdf_validator-1.68.dev10 → civics_cdf_validator-1.68.dev12}/rulesets/officeholder_rules.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|