Skip to content

Commit

Permalink
test new_juris_files
Browse files Browse the repository at this point in the history
  • Loading branch information
sfsinger19103 committed Jun 16, 2021
1 parent 7d8dc6d commit 8a1ddab
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/election_data_analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,11 @@ def __new__(cls,
return None
return super().__new__(cls)

def new_juris_files(self, target_dir: Optional[str] = None):
def new_juris_files(
self,
target_dir: Optional[str] = None,
templates: Optional[str] = None,
):
"""Create starter files in <target_dir>. If no <target_dir> is given, put the standard
jurisdiction files into a subdirectory of the jurisdictions directory in the repo, and put
the starter dictionary in the current directory.
Expand All @@ -907,9 +911,11 @@ def new_juris_files(self, target_dir: Optional[str] = None):
error = jm.ensure_jurisdiction_dir(self.d["jurisdiction_path"])
# add default entries
project_root = Path(__file__).absolute().parents[1]
templates = os.path.join(
project_root, "election_data_analysis", "juris_and_munger", "jurisdiction_templates"
)
# default templates are from repo
if not templates:
templates = os.path.join(
project_root, "election_data_analysis", "juris_and_munger", "jurisdiction_templates"
)
for element in ["Party", "Election"]:
new_err = prep.add_defaults(self.d["jurisdiction_path"], templates, element)
if new_err:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Name ElectionDistrict Election
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BallotName
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Name NumberElected Office PrimaryParty
6 changes: 6 additions & 0 deletions tests/000_data_for_pytest/jurisdiction_templates/Election.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Name ElectionType
2020 General Runoff runoff
2020 General general
2020 Primary primary
2018 General general
2016 General general
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Name ElectionDistrict
5 changes: 5 additions & 0 deletions tests/000_data_for_pytest/jurisdiction_templates/Party.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Name
Democratic Party
Republican Party
Green Party
Libertarian Party
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Name ReportingUnitType
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cdf_element cdf_internal_name raw_identifier_value
3 changes: 2 additions & 1 deletion tests/jurisdiction_prepper_tests/test_jp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def test_new_files():
run_time_file = os.path.join(tests_dir,"run_time.ini")
temp_dir = os.path.join(tests_dir,"000_data_for_pytest","Temp")
ref_dir = os.path.join(tests_dir,"000_data_for_pytest","JurisdictionPrepper_reference_files")
templates = os.path.join(tests_dir,"000_data_for_pytest", "jurisdiction_templates")

file_list = [f for f in os.listdir(ref_dir) if f[-4:] == ".txt"]

Expand All @@ -20,7 +21,7 @@ def test_new_files():
os.remove(f_path)

jp = eda.JurisdictionPrepper(prep_param_file=prep_file,run_time_param_file=run_time_file,target_dir=temp_dir)
jp.new_juris_files(target_dir=temp_dir)
jp.new_juris_files(target_dir=temp_dir, templates=templates)

bad = [f for f in file_list if
open(os.path.join(temp_dir,f),"r").read() != open(os.path.join(ref_dir,f),"r").read()]
Expand Down

0 comments on commit 8a1ddab

Please sign in to comment.