civics-cdf-validator 1.68.dev11__tar.gz → 1.68.dev13__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.dev11/civics_cdf_validator.egg-info → civics_cdf_validator-1.68.dev13}/PKG-INFO +1 -1
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/base.py +35 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13/civics_cdf_validator.egg-info}/PKG-INFO +1 -1
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/civics_cdf_validator.egg-info/SOURCES.txt +1 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rules.py +3 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/common_rules.py +4 -4
- civics_cdf_validator-1.68.dev13/rulesets/election_results_rules.py +53 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/election_rules.py +1 -1
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/validator.py +1 -1
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/version.py +1 -1
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/CONTRIBUTING.md +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/LICENSE-2.0.txt +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/MANIFEST.in +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/README.md +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/__init__.py +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/civics_cdf_validator.egg-info/dependency_links.txt +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/civics_cdf_validator.egg-info/entry_points.txt +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/civics_cdf_validator.egg-info/requires.txt +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/civics_cdf_validator.egg-info/top_level.txt +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/gpunit_rules.py +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/loggers.py +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/office_utils.py +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/__init__.py +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/committee_rules.py +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/election_dates_rules.py +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/metadata_rules.py +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/officeholder_rules.py +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/rule_util.py +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/voter_information_rules.py +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/setup.cfg +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/setup.py +0 -0
- {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/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
|
|
@@ -96,6 +97,15 @@ class BaseRule(SchemaHandler):
|
|
|
96
97
|
def setup(self):
|
|
97
98
|
"""Perform any rule specific setup before checking."""
|
|
98
99
|
|
|
100
|
+
|
|
101
|
+
class SchemaRule(BaseRule):
|
|
102
|
+
"""Rule that needs the schema tree to be present."""
|
|
103
|
+
|
|
104
|
+
def __init__(self, *args, **kwargs):
|
|
105
|
+
super(SchemaRule, self).__init__(*args, **kwargs)
|
|
106
|
+
if self.schema_tree is None:
|
|
107
|
+
raise ValueError(f"{type(self).__name__} requires a schema_tree.")
|
|
108
|
+
|
|
99
109
|
def get_element_names_for_types(self, element_types: Set[str]) -> set[str]:
|
|
100
110
|
element_names = set()
|
|
101
111
|
for _, element in etree.iterwalk(self.schema_tree):
|
|
@@ -111,6 +121,31 @@ class BaseRule(SchemaHandler):
|
|
|
111
121
|
def get_element_names_for_type(self, element_type: str) -> set[str]:
|
|
112
122
|
return self.get_element_names_for_types({element_type})
|
|
113
123
|
|
|
124
|
+
def get_all_subtypes(self, base_type: str) -> set[str]:
|
|
125
|
+
"""Returns every schema type that extends base_type, at any depth."""
|
|
126
|
+
direct_subtypes = collections.defaultdict(set)
|
|
127
|
+
for complex_type in self.schema_tree.iterfind(
|
|
128
|
+
f"{{{self._XSCHEMA_NAMESPACE}}}complexType"
|
|
129
|
+
):
|
|
130
|
+
extension = complex_type.find(
|
|
131
|
+
f"*/{{{self._XSCHEMA_NAMESPACE}}}extension"
|
|
132
|
+
)
|
|
133
|
+
if extension is None:
|
|
134
|
+
continue
|
|
135
|
+
parent_type = extension.get("base")
|
|
136
|
+
subtype = complex_type.get("name")
|
|
137
|
+
if parent_type and subtype:
|
|
138
|
+
direct_subtypes[parent_type].add(subtype)
|
|
139
|
+
|
|
140
|
+
subtypes = set()
|
|
141
|
+
types_to_visit = list(direct_subtypes[base_type])
|
|
142
|
+
while types_to_visit:
|
|
143
|
+
subtype = types_to_visit.pop()
|
|
144
|
+
if subtype not in subtypes:
|
|
145
|
+
subtypes.add(subtype)
|
|
146
|
+
types_to_visit.extend(direct_subtypes[subtype])
|
|
147
|
+
return subtypes
|
|
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
|
)
|
{civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/common_rules.py
RENAMED
|
@@ -243,7 +243,7 @@ class EmptyText(base.BaseRule):
|
|
|
243
243
|
raise loggers.ElectionError.from_message("Text is empty", element)
|
|
244
244
|
|
|
245
245
|
|
|
246
|
-
class EmptyString(base.
|
|
246
|
+
class EmptyString(base.SchemaRule):
|
|
247
247
|
"""Check that string fields are not empty or strictly whitespace."""
|
|
248
248
|
|
|
249
249
|
def elements(self):
|
|
@@ -599,7 +599,7 @@ class OtherType(base.BaseRule):
|
|
|
599
599
|
raise loggers.ElectionError.from_message(msg, [element])
|
|
600
600
|
|
|
601
601
|
|
|
602
|
-
class UniqueLabel(base.
|
|
602
|
+
class UniqueLabel(base.SchemaRule):
|
|
603
603
|
"""Labels should be unique within a file."""
|
|
604
604
|
|
|
605
605
|
def __init__(self, *args, **kwargs):
|
|
@@ -1742,7 +1742,7 @@ class MissingOfficeSelectionMethod(base.BaseRule):
|
|
|
1742
1742
|
)
|
|
1743
1743
|
|
|
1744
1744
|
|
|
1745
|
-
class AllInternationalizedTextHaveEnVersion(base.
|
|
1745
|
+
class AllInternationalizedTextHaveEnVersion(base.SchemaRule):
|
|
1746
1746
|
"""Checks for InternationalizedText elements missing an English version."""
|
|
1747
1747
|
|
|
1748
1748
|
def elements(self):
|
|
@@ -1811,7 +1811,7 @@ class ProhibitElectionData(base.TreeRule):
|
|
|
1811
1811
|
)
|
|
1812
1812
|
|
|
1813
1813
|
|
|
1814
|
-
class UnreferencedEntitiesBase(base.TreeRule):
|
|
1814
|
+
class UnreferencedEntitiesBase(base.TreeRule, base.SchemaRule):
|
|
1815
1815
|
"""All non-top-level entities in a feed should be referenced by at least one other entity.
|
|
1816
1816
|
|
|
1817
1817
|
In the context of this rule, top-level means that an entity is not expected to
|
|
@@ -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
|
+
)
|
{civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/election_rules.py
RENAMED
|
@@ -716,7 +716,7 @@ class VoteCountTypesCoherency(base.BaseRule):
|
|
|
716
716
|
raise loggers.ElectionError.from_message(msg, [element])
|
|
717
717
|
|
|
718
718
|
|
|
719
|
-
class VoteCountValidSeatsDeltaTypes(base.
|
|
719
|
+
class VoteCountValidSeatsDeltaTypes(base.SchemaRule):
|
|
720
720
|
"""Ensure VoteCount seats delta types are valid."""
|
|
721
721
|
|
|
722
722
|
def elements(self):
|
|
@@ -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.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/committee_rules.py
RENAMED
|
File without changes
|
{civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/election_dates_rules.py
RENAMED
|
File without changes
|
{civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/metadata_rules.py
RENAMED
|
File without changes
|
{civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev13}/rulesets/officeholder_rules.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|