civics-cdf-validator 1.67.dev17__tar.gz → 1.67.dev19__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 (31) hide show
  1. {civics_cdf_validator-1.67.dev17/civics_cdf_validator.egg-info → civics_cdf_validator-1.67.dev19}/PKG-INFO +1 -1
  2. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19/civics_cdf_validator.egg-info}/PKG-INFO +1 -1
  3. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/rulesets/common_rules.py +83 -1
  4. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/rulesets/election_rules.py +3 -81
  5. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/version.py +1 -1
  6. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/CONTRIBUTING.md +0 -0
  7. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/LICENSE-2.0.txt +0 -0
  8. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/MANIFEST.in +0 -0
  9. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/README.md +0 -0
  10. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/__init__.py +0 -0
  11. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/base.py +0 -0
  12. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/civics_cdf_validator.egg-info/SOURCES.txt +0 -0
  13. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/civics_cdf_validator.egg-info/dependency_links.txt +0 -0
  14. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/civics_cdf_validator.egg-info/entry_points.txt +0 -0
  15. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/civics_cdf_validator.egg-info/requires.txt +0 -0
  16. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/civics_cdf_validator.egg-info/top_level.txt +0 -0
  17. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/gpunit_rules.py +0 -0
  18. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/loggers.py +0 -0
  19. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/office_utils.py +0 -0
  20. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/rules.py +0 -0
  21. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/rulesets/__init__.py +0 -0
  22. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/rulesets/committee_rules.py +0 -0
  23. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/rulesets/election_dates_rules.py +0 -0
  24. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/rulesets/metadata_rules.py +0 -0
  25. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/rulesets/officeholder_rules.py +0 -0
  26. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/rulesets/rule_util.py +0 -0
  27. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/rulesets/voter_information_rules.py +0 -0
  28. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/setup.cfg +0 -0
  29. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/setup.py +0 -0
  30. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/stats.py +0 -0
  31. {civics_cdf_validator-1.67.dev17 → civics_cdf_validator-1.67.dev19}/validator.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: civics_cdf_validator
3
- Version: 1.67.dev17
3
+ Version: 1.67.dev19
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.67.dev17
3
+ Version: 1.67.dev19
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
@@ -26,7 +26,6 @@ import language_tags
26
26
  from lxml import etree
27
27
  from six.moves.urllib.parse import urlparse
28
28
 
29
-
30
29
  _INDEPENDENT_PARTY_NAMES = frozenset(["independent", "nonpartisan"])
31
30
 
32
31
  _GPUNIT_TYPES_WITHOUT_OCD_IDS = frozenset([
@@ -1858,6 +1857,87 @@ class UnreferencedEntitiesBase(base.TreeRule):
1858
1857
  )
1859
1858
 
1860
1859
 
1860
+ class CoalitionParties(base.BaseRule):
1861
+ """Coalitions should always define the Party IDs."""
1862
+
1863
+ def elements(self):
1864
+ return ["Coalition"]
1865
+
1866
+ def check(self, element):
1867
+ party_id = element.find("PartyIds")
1868
+ if party_id is None or not party_id.text or not party_id.text.strip():
1869
+ raise loggers.ElectionError.from_message(
1870
+ "Coalition must define PartyIDs", [element]
1871
+ )
1872
+
1873
+
1874
+ class ValidatePartyCollection(base.BaseRule):
1875
+ """Generic party collection validation rule.
1876
+
1877
+ All partyCollection validation rules can inherit from this class since it
1878
+ contains basic checks.
1879
+ """
1880
+
1881
+ def elements(self):
1882
+ return ["PartyCollection"]
1883
+
1884
+ def check_specific(self, parties):
1885
+ """Return a list of info log to be raised."""
1886
+ raise NotImplementedError
1887
+
1888
+ def check(self, element):
1889
+ info_log = []
1890
+ parties = element.findall("Party")
1891
+ if len(parties) < 1:
1892
+ info_message = "<PartyCollection> does not have <Party> objects"
1893
+ info_log.append(loggers.LogEntry(info_message, element))
1894
+ info_log.extend(self.check_specific(parties))
1895
+ if info_log:
1896
+ raise loggers.ElectionInfo(info_log)
1897
+
1898
+
1899
+ class DuplicatedPartyAbbreviation(ValidatePartyCollection):
1900
+ """Party abbreviation should be used once in a given language.
1901
+
1902
+ If an abbreviation is duplicated, the corresponding party should be picked up
1903
+ within this class and returned to the user as an Info message.
1904
+ """
1905
+
1906
+ def check_specific(self, parties):
1907
+ info_log = []
1908
+ party_abbreviations_by_language = {}
1909
+ for party in parties:
1910
+ abbreviation_element = party.find("InternationalizedAbbreviation")
1911
+ if abbreviation_element is None:
1912
+ info_log.append(
1913
+ loggers.LogEntry(
1914
+ "<Party> does not have <InternationalizedAbbreviation> objects",
1915
+ [party],
1916
+ )
1917
+ )
1918
+ continue
1919
+ party_abbreviations = abbreviation_element.findall("Text")
1920
+ for party_abbreviation in party_abbreviations:
1921
+ language = party_abbreviation.get("language")
1922
+ abbreviation = party_abbreviation.text
1923
+ if language not in party_abbreviations_by_language:
1924
+ party_abbreviations_by_language[language] = {}
1925
+ if abbreviation in party_abbreviations_by_language[language]:
1926
+ party_abbreviations_by_language[language][abbreviation].append(party)
1927
+ else:
1928
+ party_abbreviations_by_language[language][abbreviation] = [party]
1929
+
1930
+ for language, abbreviations in party_abbreviations_by_language.items():
1931
+ for abbreviation, parties in abbreviations.items():
1932
+ if len(parties) > 1:
1933
+ info_log.append(
1934
+ loggers.LogEntry(
1935
+ f"Parties have the same abbreviation in {language}.", parties
1936
+ )
1937
+ )
1938
+ return info_log
1939
+
1940
+
1861
1941
  COMMON_RULES = (
1862
1942
  # go/keep-sorted start
1863
1943
  AllCaps,
@@ -1865,11 +1945,13 @@ COMMON_RULES = (
1865
1945
  AllLanguages,
1866
1946
  BadCharactersInPersonFullName,
1867
1947
  CandidateImageInContactInformation,
1948
+ CoalitionParties,
1868
1949
  DeprecatedPartyLeadershipSchema,
1869
1950
  DiplomaticOfficesHaveCorrespondingGpUnitsSet,
1870
1951
  DuplicateGpUnits,
1871
1952
  DuplicateID,
1872
1953
  DuplicatedGpUnitOcdId,
1954
+ DuplicatedPartyAbbreviation,
1873
1955
  EmptyString,
1874
1956
  EmptyText,
1875
1957
  Encoding,
@@ -220,20 +220,6 @@ class PartisanPrimaryHeuristic(base.BaseRule):
220
220
  raise loggers.ElectionWarning.from_message(msg, [contest_elem])
221
221
 
222
222
 
223
- class CoalitionParties(base.BaseRule):
224
- """Coalitions should always define the Party IDs."""
225
-
226
- def elements(self):
227
- return ["Coalition"]
228
-
229
- def check(self, element):
230
- party_id = element.find("PartyIds")
231
- if party_id is None or not party_id.text or not party_id.text.strip():
232
- raise loggers.ElectionError.from_message(
233
- "Coalition must define PartyIDs", [element]
234
- )
235
-
236
-
237
223
  class CandidatesReferencedInRelatedContests(base.BaseRule):
238
224
  """Candidate should not be referred to by multiple unrelated contests.
239
225
 
@@ -478,31 +464,6 @@ class SingularPartySelection(base.BaseRule):
478
464
  )
479
465
 
480
466
 
481
- class ValidatePartyCollection(base.BaseRule):
482
- """Generic party collection validation rule.
483
-
484
- All partyCollection validation rules can inherit from this class since it
485
- contains basic checks.
486
- """
487
-
488
- def elements(self):
489
- return ["PartyCollection"]
490
-
491
- def check_specific(self, parties):
492
- """Return a list of info log to be raised."""
493
- raise NotImplementedError
494
-
495
- def check(self, element):
496
- info_log = []
497
- parties = element.findall("Party")
498
- if len(parties) < 1:
499
- info_message = "<PartyCollection> does not have <Party> objects"
500
- info_log.append(loggers.LogEntry(info_message, element))
501
- info_log.extend(self.check_specific(parties))
502
- if info_log:
503
- raise loggers.ElectionInfo(info_log)
504
-
505
-
506
467
  class ValidateDuplicateColors(base.TreeRule):
507
468
  """Parties under the same contest should have unique color.
508
469
 
@@ -580,44 +541,7 @@ class ValidateDuplicateColors(base.TreeRule):
580
541
  raise loggers.ElectionWarning(warning_log)
581
542
 
582
543
 
583
- class DuplicatedPartyAbbreviation(ValidatePartyCollection):
584
- """Party abbreviation should be used once in a given language.
585
-
586
- If an abbreviation is duplicated, the corresponding party should be picked up
587
- within this class and returned to the user as an Info message.
588
- """
589
-
590
- def check_specific(self, parties):
591
- info_log = []
592
- party_abbrs_by_language = {}
593
- for party in parties:
594
- abbr_element = party.find("InternationalizedAbbreviation")
595
- if abbr_element is None:
596
- info_message = (
597
- "<Party> does not have <InternationalizedAbbreviation> objects"
598
- )
599
- info_log.append(loggers.LogEntry(info_message, [party]))
600
- continue
601
- party_abbrs = abbr_element.findall("Text")
602
- for party_abbr in party_abbrs:
603
- language = party_abbr.get("language")
604
- abbr = party_abbr.text
605
- if language not in party_abbrs_by_language:
606
- party_abbrs_by_language[language] = {}
607
- if abbr in party_abbrs_by_language[language]:
608
- party_abbrs_by_language[language][abbr].append(party)
609
- else:
610
- party_abbrs_by_language[language][abbr] = [party]
611
-
612
- for language, abbrs in party_abbrs_by_language.items():
613
- for abbr, parties in abbrs.items():
614
- if len(parties) > 1:
615
- info_message = "Parties have the same abbreviation in %s." % language
616
- info_log.append(loggers.LogEntry(info_message, parties))
617
- return info_log
618
-
619
-
620
- class DuplicatedPartyName(ValidatePartyCollection):
544
+ class DuplicatedPartyName(common_rules.ValidatePartyCollection):
621
545
  """Party name should be used once in a given language.
622
546
 
623
547
  If a party name is duplicated, the corresponding party should be picked up
@@ -652,7 +576,7 @@ class DuplicatedPartyName(ValidatePartyCollection):
652
576
  return info_log
653
577
 
654
578
 
655
- class MissingPartyNameTranslation(ValidatePartyCollection):
579
+ class MissingPartyNameTranslation(common_rules.ValidatePartyCollection):
656
580
  """All Parties should have their name translated to the same languages.
657
581
 
658
582
  If there is a party name that is not translated to all the feed languages,
@@ -694,7 +618,7 @@ class MissingPartyNameTranslation(ValidatePartyCollection):
694
618
  return info_log
695
619
 
696
620
 
697
- class MissingPartyAbbreviationTranslation(ValidatePartyCollection):
621
+ class MissingPartyAbbreviationTranslation(common_rules.ValidatePartyCollection):
698
622
  """Every party's abbreviation should be translated to the same languages.
699
623
 
700
624
  If a party is missing a name translation, it should be picked up within this
@@ -2639,7 +2563,6 @@ ELECTION_RULES = common_rules.COMMON_RULES + (
2639
2563
  BallotTitle,
2640
2564
  CandidateContestTypesAreCompatible,
2641
2565
  CandidatesReferencedInRelatedContests,
2642
- CoalitionParties,
2643
2566
  ComposingContestIdsAreValidRelatedContests,
2644
2567
  ContestContainsValidEndDate,
2645
2568
  ContestContainsValidStartDate,
@@ -2652,7 +2575,6 @@ ELECTION_RULES = common_rules.COMMON_RULES + (
2652
2575
  DateStatusMatches,
2653
2576
  DuplicateBallotTitleSeatPair,
2654
2577
  DuplicateContestNames,
2655
- DuplicatedPartyAbbreviation,
2656
2578
  DuplicatedPartyName,
2657
2579
  ElectionContainsStartAndEndDates,
2658
2580
  ElectionDatesSpanContestDates,
@@ -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.67.dev17'
8
+ __version__ = '1.67.dev19'