civics-cdf-validator 1.68.dev11__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.
Files changed (32) hide show
  1. {civics_cdf_validator-1.68.dev11/civics_cdf_validator.egg-info → civics_cdf_validator-1.68.dev12}/PKG-INFO +1 -1
  2. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/base.py +35 -0
  3. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12/civics_cdf_validator.egg-info}/PKG-INFO +1 -1
  4. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/civics_cdf_validator.egg-info/SOURCES.txt +1 -0
  5. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/rules.py +3 -0
  6. civics_cdf_validator-1.68.dev12/rulesets/election_results_rules.py +53 -0
  7. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/validator.py +1 -1
  8. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/version.py +1 -1
  9. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/CONTRIBUTING.md +0 -0
  10. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/LICENSE-2.0.txt +0 -0
  11. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/MANIFEST.in +0 -0
  12. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/README.md +0 -0
  13. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/__init__.py +0 -0
  14. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/civics_cdf_validator.egg-info/dependency_links.txt +0 -0
  15. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/civics_cdf_validator.egg-info/entry_points.txt +0 -0
  16. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/civics_cdf_validator.egg-info/requires.txt +0 -0
  17. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/civics_cdf_validator.egg-info/top_level.txt +0 -0
  18. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/gpunit_rules.py +0 -0
  19. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/loggers.py +0 -0
  20. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/office_utils.py +0 -0
  21. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/rulesets/__init__.py +0 -0
  22. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/rulesets/committee_rules.py +0 -0
  23. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/rulesets/common_rules.py +0 -0
  24. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/rulesets/election_dates_rules.py +0 -0
  25. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/rulesets/election_rules.py +0 -0
  26. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/rulesets/metadata_rules.py +0 -0
  27. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/rulesets/officeholder_rules.py +0 -0
  28. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/rulesets/rule_util.py +0 -0
  29. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/rulesets/voter_information_rules.py +0 -0
  30. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/setup.cfg +0 -0
  31. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/setup.py +0 -0
  32. {civics_cdf_validator-1.68.dev11 → civics_cdf_validator-1.68.dev12}/stats.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: civics_cdf_validator
3
- Version: 1.68.dev11
3
+ Version: 1.68.dev12
4
4
  Summary: Checks if an election feed follows best practices
5
5
  Home-page: https://github.com/google/civics_cdf_validator
6
6
  Author: Google Civics
@@ -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."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: civics_cdf_validator
3
- Version: 1.68.dev11
3
+ Version: 1.68.dev12
4
4
  Summary: Checks if an election feed follows best practices
5
5
  Home-page: https://github.com/google/civics_cdf_validator
6
6
  Author: Google Civics
@@ -19,6 +19,7 @@ setup.py
19
19
  ./rulesets/committee_rules.py
20
20
  ./rulesets/common_rules.py
21
21
  ./rulesets/election_dates_rules.py
22
+ ./rulesets/election_results_rules.py
22
23
  ./rulesets/election_rules.py
23
24
  ./rulesets/metadata_rules.py
24
25
  ./rulesets/officeholder_rules.py
@@ -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.ELECTION_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:
@@ -5,4 +5,4 @@ No dependencies should be added to this module.
5
5
  See https://packaging.python.org/guides/single-sourcing-package-version/
6
6
  """
7
7
 
8
- __version__ = '1.68.dev11'
8
+ __version__ = '1.68.dev12'