civics-cdf-validator 1.69.dev4__py3-none-any.whl → 1.69.dev5__py3-none-any.whl

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.
@@ -23,6 +23,8 @@ _REQUIRED_CONTEST_RESULTS_FIELDS = (
23
23
  "ResultsReportingStageCollection",
24
24
  )
25
25
 
26
+ _SUB_UNITS_FIELD_NAMES = ("SubUnitsReported", "TotalSubUnits")
27
+
26
28
 
27
29
  class RequiredContestResultsFieldsSet(base.SchemaRule):
28
30
  """Checks that every Contest sets its results reporting stage fields.
@@ -69,9 +71,38 @@ class DataSourcesRequired(base.BaseRule):
69
71
  )
70
72
 
71
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
+
72
102
  ELECTION_RESULTS_RULES = election_rules.ELECTION_RULES + (
73
103
  # go/keep-sorted start
74
104
  DataSourcesRequired,
75
105
  RequiredContestResultsFieldsSet,
106
+ ValidatePercentReporting,
76
107
  # go/keep-sorted end
77
108
  )
@@ -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.69.dev4'
8
+ __version__ = '1.69.dev5'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: civics_cdf_validator
3
- Version: 1.69.dev4
3
+ Version: 1.69.dev5
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
@@ -6,20 +6,20 @@ civics_cdf_validator/office_utils.py,sha256=4r0zc6-UB2YdqmUnGznEn5K5WLFRsQNQr-QM
6
6
  civics_cdf_validator/rules.py,sha256=J9a77RTXVaXEHBfH0Nrv9rAckOrGOkQMbSTMmUME6G8,2208
7
7
  civics_cdf_validator/stats.py,sha256=nVo2rGccls2ot8uKVNqHA5r1clUyjB1ht_HUhQQ05_c,3924
8
8
  civics_cdf_validator/validator.py,sha256=YqmbXlBjV3O4m8C_9jlAahrqIt86p9ACL_zWp00tkkg,14211
9
- civics_cdf_validator/version.py,sha256=byIIxzQYt5aFnRN41Q7I_4xUKJwL7IIz1THChndcSLo,188
9
+ civics_cdf_validator/version.py,sha256=0IUSK1Xe5BRouz8ZRnADDB6Ree9LN8aLQE5l-28D2dY,188
10
10
  civics_cdf_validator/rulesets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  civics_cdf_validator/rulesets/committee_rules.py,sha256=kKOkO7Yb1vLJvlQRCLl6HwMvMHPbePN1w0kpMDXcYCU,3601
12
12
  civics_cdf_validator/rulesets/common_rules.py,sha256=0CFMwrrlWs5O95hh4wh_MHxvkzWa1PqIPSzRzDyCcuI,74514
13
13
  civics_cdf_validator/rulesets/election_dates_rules.py,sha256=UIB5yLZ3KZleRyR8avsREF78dhcAVaod381sKq0bKoY,1463
14
- civics_cdf_validator/rulesets/election_results_rules.py,sha256=ppw9CMMoGrCpkTW-gB51LlBfIc598fdSv0SouRT5eBI,2665
14
+ civics_cdf_validator/rulesets/election_results_rules.py,sha256=Ago_Hnm7_TpixWufg5rls-BoCqCQRqgDHpLzrBcnCAw,3834
15
15
  civics_cdf_validator/rulesets/election_rules.py,sha256=klliyhnCsBrg9e6Oo2fUcr1NUh14LtO2b0Jd5dkcPrw,88422
16
16
  civics_cdf_validator/rulesets/metadata_rules.py,sha256=iU7x34hvI_jxzPZmi1VYS2F2fRqMLcX8QCcAMFm6j6M,16545
17
17
  civics_cdf_validator/rulesets/officeholder_rules.py,sha256=XDnGOZ505pVjEw4FoQ4ec6ro5-RZNhwxC_B6-Skuq8Y,17533
18
18
  civics_cdf_validator/rulesets/rule_util.py,sha256=fRAnJG1ILgBdC_nQglj1XU7pcqyfb4Z4l_sa6gmi238,4824
19
19
  civics_cdf_validator/rulesets/voter_information_rules.py,sha256=9Y3X9AWIVuKyoVWCohLdGNzqIV3nbwDWUKjxcWwjuEI,4991
20
- civics_cdf_validator-1.69.dev4.dist-info/licenses/LICENSE-2.0.txt,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
21
- civics_cdf_validator-1.69.dev4.dist-info/METADATA,sha256=cSkD8CnxbT1Ix9H4euLJ1i-jex7VnVZA529EX48LYM8,1280
22
- civics_cdf_validator-1.69.dev4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
23
- civics_cdf_validator-1.69.dev4.dist-info/entry_points.txt,sha256=QibgvtMOocwDi7fQ1emgMJ2lIlI41sW0__KIQdnVn90,77
24
- civics_cdf_validator-1.69.dev4.dist-info/top_level.txt,sha256=PYT5Eclxbop5o6DJIcgs4IeU6Ds5jqyftjoFbgkkJYo,21
25
- civics_cdf_validator-1.69.dev4.dist-info/RECORD,,
20
+ civics_cdf_validator-1.69.dev5.dist-info/licenses/LICENSE-2.0.txt,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
21
+ civics_cdf_validator-1.69.dev5.dist-info/METADATA,sha256=RUWDzFmQ9ZHE4sr4KdQ-2TtsTgy5nRenmNYyOJsgc2o,1280
22
+ civics_cdf_validator-1.69.dev5.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
23
+ civics_cdf_validator-1.69.dev5.dist-info/entry_points.txt,sha256=QibgvtMOocwDi7fQ1emgMJ2lIlI41sW0__KIQdnVn90,77
24
+ civics_cdf_validator-1.69.dev5.dist-info/top_level.txt,sha256=PYT5Eclxbop5o6DJIcgs4IeU6Ds5jqyftjoFbgkkJYo,21
25
+ civics_cdf_validator-1.69.dev5.dist-info/RECORD,,