civics-cdf-validator 1.67.dev18__tar.gz → 1.67.dev20__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.dev18/civics_cdf_validator.egg-info → civics_cdf_validator-1.67.dev20}/PKG-INFO +1 -1
  2. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20/civics_cdf_validator.egg-info}/PKG-INFO +1 -1
  3. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/rulesets/common_rules.py +108 -1
  4. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/rulesets/election_rules.py +2 -101
  5. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/version.py +1 -1
  6. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/CONTRIBUTING.md +0 -0
  7. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/LICENSE-2.0.txt +0 -0
  8. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/MANIFEST.in +0 -0
  9. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/README.md +0 -0
  10. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/__init__.py +0 -0
  11. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/base.py +0 -0
  12. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/civics_cdf_validator.egg-info/SOURCES.txt +0 -0
  13. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/civics_cdf_validator.egg-info/dependency_links.txt +0 -0
  14. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/civics_cdf_validator.egg-info/entry_points.txt +0 -0
  15. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/civics_cdf_validator.egg-info/requires.txt +0 -0
  16. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/civics_cdf_validator.egg-info/top_level.txt +0 -0
  17. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/gpunit_rules.py +0 -0
  18. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/loggers.py +0 -0
  19. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/office_utils.py +0 -0
  20. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/rules.py +0 -0
  21. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/rulesets/__init__.py +0 -0
  22. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/rulesets/committee_rules.py +0 -0
  23. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/rulesets/election_dates_rules.py +0 -0
  24. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/rulesets/metadata_rules.py +0 -0
  25. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/rulesets/officeholder_rules.py +0 -0
  26. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/rulesets/rule_util.py +0 -0
  27. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/rulesets/voter_information_rules.py +0 -0
  28. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/setup.cfg +0 -0
  29. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/setup.py +0 -0
  30. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/stats.py +0 -0
  31. {civics_cdf_validator-1.67.dev18 → civics_cdf_validator-1.67.dev20}/validator.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: civics_cdf_validator
3
- Version: 1.67.dev18
3
+ Version: 1.67.dev20
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.dev18
3
+ Version: 1.67.dev20
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([
@@ -1872,6 +1871,112 @@ class CoalitionParties(base.BaseRule):
1872
1871
  )
1873
1872
 
1874
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
+
1941
+ class DuplicatedPartyName(ValidatePartyCollection):
1942
+ """Party name should be used once in a given language.
1943
+
1944
+ If a party name is duplicated, the corresponding party should be picked up
1945
+ within this class and returned to the user as an Info message.
1946
+ """
1947
+
1948
+ def check_specific(self, parties):
1949
+ info_log = []
1950
+ party_names_by_language = {}
1951
+ for party in parties:
1952
+ name_element = party.find("Name")
1953
+ if name_element is None:
1954
+ info_log.append(
1955
+ loggers.LogEntry("<Party> does not have <Name> objects", [party])
1956
+ )
1957
+ continue
1958
+ party_names = name_element.findall("Text")
1959
+ for party_name in party_names:
1960
+ language = party_name.get("language")
1961
+ name = party_name.text
1962
+ if language not in party_names_by_language:
1963
+ party_names_by_language[language] = {}
1964
+ if name in party_names_by_language[language]:
1965
+ party_names_by_language[language][name].append(party)
1966
+ else:
1967
+ party_names_by_language[language][name] = [party]
1968
+
1969
+ for language, names in party_names_by_language.items():
1970
+ for name, parties in names.items():
1971
+ if len(parties) > 1:
1972
+ info_log.append(
1973
+ loggers.LogEntry(
1974
+ f"Parties have the same name in {language}.", parties
1975
+ )
1976
+ )
1977
+ return info_log
1978
+
1979
+
1875
1980
  COMMON_RULES = (
1876
1981
  # go/keep-sorted start
1877
1982
  AllCaps,
@@ -1885,6 +1990,8 @@ COMMON_RULES = (
1885
1990
  DuplicateGpUnits,
1886
1991
  DuplicateID,
1887
1992
  DuplicatedGpUnitOcdId,
1993
+ DuplicatedPartyAbbreviation,
1994
+ DuplicatedPartyName,
1888
1995
  EmptyString,
1889
1996
  EmptyText,
1890
1997
  Encoding,
@@ -464,31 +464,6 @@ class SingularPartySelection(base.BaseRule):
464
464
  )
465
465
 
466
466
 
467
- class ValidatePartyCollection(base.BaseRule):
468
- """Generic party collection validation rule.
469
-
470
- All partyCollection validation rules can inherit from this class since it
471
- contains basic checks.
472
- """
473
-
474
- def elements(self):
475
- return ["PartyCollection"]
476
-
477
- def check_specific(self, parties):
478
- """Return a list of info log to be raised."""
479
- raise NotImplementedError
480
-
481
- def check(self, element):
482
- info_log = []
483
- parties = element.findall("Party")
484
- if len(parties) < 1:
485
- info_message = "<PartyCollection> does not have <Party> objects"
486
- info_log.append(loggers.LogEntry(info_message, element))
487
- info_log.extend(self.check_specific(parties))
488
- if info_log:
489
- raise loggers.ElectionInfo(info_log)
490
-
491
-
492
467
  class ValidateDuplicateColors(base.TreeRule):
493
468
  """Parties under the same contest should have unique color.
494
469
 
@@ -566,79 +541,7 @@ class ValidateDuplicateColors(base.TreeRule):
566
541
  raise loggers.ElectionWarning(warning_log)
567
542
 
568
543
 
569
- class DuplicatedPartyAbbreviation(ValidatePartyCollection):
570
- """Party abbreviation should be used once in a given language.
571
-
572
- If an abbreviation is duplicated, the corresponding party should be picked up
573
- within this class and returned to the user as an Info message.
574
- """
575
-
576
- def check_specific(self, parties):
577
- info_log = []
578
- party_abbrs_by_language = {}
579
- for party in parties:
580
- abbr_element = party.find("InternationalizedAbbreviation")
581
- if abbr_element is None:
582
- info_message = (
583
- "<Party> does not have <InternationalizedAbbreviation> objects"
584
- )
585
- info_log.append(loggers.LogEntry(info_message, [party]))
586
- continue
587
- party_abbrs = abbr_element.findall("Text")
588
- for party_abbr in party_abbrs:
589
- language = party_abbr.get("language")
590
- abbr = party_abbr.text
591
- if language not in party_abbrs_by_language:
592
- party_abbrs_by_language[language] = {}
593
- if abbr in party_abbrs_by_language[language]:
594
- party_abbrs_by_language[language][abbr].append(party)
595
- else:
596
- party_abbrs_by_language[language][abbr] = [party]
597
-
598
- for language, abbrs in party_abbrs_by_language.items():
599
- for abbr, parties in abbrs.items():
600
- if len(parties) > 1:
601
- info_message = "Parties have the same abbreviation in %s." % language
602
- info_log.append(loggers.LogEntry(info_message, parties))
603
- return info_log
604
-
605
-
606
- class DuplicatedPartyName(ValidatePartyCollection):
607
- """Party name should be used once in a given language.
608
-
609
- If a party name is duplicated, the corresponding party should be picked up
610
- within this class and returned to the user as an Info message.
611
- """
612
-
613
- def check_specific(self, parties):
614
- info_log = []
615
- party_names_by_language = {}
616
- for party in parties:
617
- name_element = party.find("Name")
618
- if name_element is None:
619
- info_message = "<Party> does not have <Name> objects"
620
- info_log.append(loggers.LogEntry(info_message, [party]))
621
- continue
622
- party_names = name_element.findall("Text")
623
- for party_name in party_names:
624
- language = party_name.get("language")
625
- name = party_name.text
626
- if language not in party_names_by_language:
627
- party_names_by_language[language] = {}
628
- if name in party_names_by_language[language]:
629
- party_names_by_language[language][name].append(party)
630
- else:
631
- party_names_by_language[language][name] = [party]
632
-
633
- for language, names in party_names_by_language.items():
634
- for name, parties in names.items():
635
- if len(parties) > 1:
636
- info_message = "Parties have the same name in %s." % language
637
- info_log.append(loggers.LogEntry(info_message, parties))
638
- return info_log
639
-
640
-
641
- class MissingPartyNameTranslation(ValidatePartyCollection):
544
+ class MissingPartyNameTranslation(common_rules.ValidatePartyCollection):
642
545
  """All Parties should have their name translated to the same languages.
643
546
 
644
547
  If there is a party name that is not translated to all the feed languages,
@@ -680,7 +583,7 @@ class MissingPartyNameTranslation(ValidatePartyCollection):
680
583
  return info_log
681
584
 
682
585
 
683
- class MissingPartyAbbreviationTranslation(ValidatePartyCollection):
586
+ class MissingPartyAbbreviationTranslation(common_rules.ValidatePartyCollection):
684
587
  """Every party's abbreviation should be translated to the same languages.
685
588
 
686
589
  If a party is missing a name translation, it should be picked up within this
@@ -2637,8 +2540,6 @@ ELECTION_RULES = common_rules.COMMON_RULES + (
2637
2540
  DateStatusMatches,
2638
2541
  DuplicateBallotTitleSeatPair,
2639
2542
  DuplicateContestNames,
2640
- DuplicatedPartyAbbreviation,
2641
- DuplicatedPartyName,
2642
2543
  ElectionContainsStartAndEndDates,
2643
2544
  ElectionDatesSpanContestDates,
2644
2545
  ElectionEndDatesInThePast,
@@ -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.dev18'
8
+ __version__ = '1.67.dev20'