civics-cdf-validator 1.69.dev17__tar.gz → 1.69.dev18__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.69.dev17/civics_cdf_validator.egg-info → civics_cdf_validator-1.69.dev18}/PKG-INFO +1 -1
  2. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18/civics_cdf_validator.egg-info}/PKG-INFO +1 -1
  3. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/rulesets/election_rules.py +39 -4
  4. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/rulesets/rule_util.py +10 -0
  5. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/version.py +1 -1
  6. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/CONTRIBUTING.md +0 -0
  7. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/LICENSE-2.0.txt +0 -0
  8. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/MANIFEST.in +0 -0
  9. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/README.md +0 -0
  10. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/__init__.py +0 -0
  11. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/base.py +0 -0
  12. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/civics_cdf_validator.egg-info/SOURCES.txt +0 -0
  13. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/civics_cdf_validator.egg-info/dependency_links.txt +0 -0
  14. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/civics_cdf_validator.egg-info/entry_points.txt +0 -0
  15. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/civics_cdf_validator.egg-info/requires.txt +0 -0
  16. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/civics_cdf_validator.egg-info/top_level.txt +0 -0
  17. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/gpunit_rules.py +0 -0
  18. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/loggers.py +0 -0
  19. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/office_utils.py +0 -0
  20. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/rules.py +0 -0
  21. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/rulesets/__init__.py +0 -0
  22. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/rulesets/committee_rules.py +0 -0
  23. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/rulesets/common_rules.py +0 -0
  24. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/rulesets/election_dates_rules.py +0 -0
  25. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/rulesets/election_results_rules.py +0 -0
  26. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/rulesets/metadata_rules.py +0 -0
  27. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/rulesets/officeholder_rules.py +0 -0
  28. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/rulesets/voter_information_rules.py +0 -0
  29. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/setup.cfg +0 -0
  30. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/setup.py +0 -0
  31. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/stats.py +0 -0
  32. {civics_cdf_validator-1.69.dev17 → civics_cdf_validator-1.69.dev18}/validator.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: civics_cdf_validator
3
- Version: 1.69.dev17
3
+ Version: 1.69.dev18
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: civics_cdf_validator
3
- Version: 1.69.dev17
3
+ Version: 1.69.dev18
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
@@ -42,6 +42,13 @@ _WINNER_POST_ELECTION_STATUSES = frozenset([
42
42
  ])
43
43
 
44
44
 
45
+ _SEATS_DELTA_VOTE_COUNT_TYPES = frozenset([
46
+ "seats-delta",
47
+ "seats-delta-institutional",
48
+ "seats-delta-mandate",
49
+ ])
50
+
51
+
45
52
  def _get_type_or_other_type(element: etree._Element) -> str:
46
53
  """Returns the OtherType text if Type is "other", else the Type text."""
47
54
  type_element = element.find("Type")
@@ -90,7 +97,9 @@ class PercentSum(base.SchemaRule):
90
97
  ):
91
98
  other_type = vote_counts.find("OtherType")
92
99
  if other_type is not None and other_type.text == "total-percent":
93
- sum_percents += float(vote_counts.find("Count").text)
100
+ count = rule_util.get_float(vote_counts.find("Count"))
101
+ if count is not None:
102
+ sum_percents += count
94
103
  if not PercentSum.fuzzy_equals(
95
104
  sum_percents, 0
96
105
  ) and not PercentSum.fuzzy_equals(sum_percents, 100):
@@ -777,6 +786,32 @@ class VoteCountValidSeatsDeltaTypes(base.SchemaRule):
777
786
  )
778
787
 
779
788
 
789
+ class VoteCountsNotNegative(base.BaseRule):
790
+ """Checks that every VoteCounts has a Count of zero or more.
791
+
792
+ Only seats-delta, seats-delta-mandate, and seats-delta-institutional
793
+ VoteCounts can be negative, since they report a change in the number of seats.
794
+ """
795
+
796
+ def elements(self) -> list[str]:
797
+ return ["VoteCounts"]
798
+
799
+ def check(self, element: etree._Element) -> None:
800
+ count_element = element.find("Count")
801
+ count = rule_util.get_float(count_element)
802
+ if count is None:
803
+ return
804
+ vote_count_type = _get_type_or_other_type(element)
805
+ if count < 0 and vote_count_type not in _SEATS_DELTA_VOTE_COUNT_TYPES:
806
+ raise loggers.ElectionError.from_message(
807
+ f"VoteCounts of type '{vote_count_type}' has a negative Count of"
808
+ f" {count_element.text.strip()}. Only"
809
+ f" {', '.join(sorted(_SEATS_DELTA_VOTE_COUNT_TYPES))} VoteCounts"
810
+ " can be negative.",
811
+ [element],
812
+ )
813
+
814
+
780
815
  class OfficeHasjurisdictionSameAsElectoralDistrict(base.BaseRule):
781
816
  """In election feeds, office has the electoral district same as jurisdiction."""
782
817
 
@@ -2335,10 +2370,9 @@ class ValidateIncludeInAggregationBallotSelections(base.BaseRule):
2335
2370
  return count_by_type_and_gp_unit
2336
2371
 
2337
2372
  for vote_counts in vote_counts_collection.findall("VoteCounts"):
2338
- count_element = vote_counts.find("Count")
2339
- if not rule_util.element_has_text(count_element):
2373
+ count = rule_util.get_float(vote_counts.find("Count"))
2374
+ if count is None:
2340
2375
  continue
2341
- count = float(count_element.text)
2342
2376
 
2343
2377
  vote_count_type = _get_type_or_other_type(vote_counts)
2344
2378
  gp_unit_id_element = vote_counts.find("GpUnitId")
@@ -2463,6 +2497,7 @@ ELECTION_RULES = common_rules.COMMON_RULES + (
2463
2497
  ValidateSpecialBallotSelectionCountedInTotal,
2464
2498
  VoteCountTypesCoherency,
2465
2499
  VoteCountValidSeatsDeltaTypes,
2500
+ VoteCountsNotNegative,
2466
2501
  WinnerCountLimit,
2467
2502
  # go/keep-sorted end
2468
2503
  )
@@ -148,6 +148,16 @@ def element_has_text(element: etree._Element | None) -> bool:
148
148
  )
149
149
 
150
150
 
151
+ def get_float(element: etree._Element | None) -> float | None:
152
+ """Returns the element's text as a float, or None if it isn't one."""
153
+ if not element_has_text(element):
154
+ return None
155
+ try:
156
+ return float(element.text.strip())
157
+ except ValueError:
158
+ return None
159
+
160
+
151
161
  def country_code_is_valid(country_code: str) -> bool:
152
162
  # EU is part of ISO 3166/MA
153
163
  return (
@@ -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.dev17'
8
+ __version__ = '1.69.dev18'