Skip to content

Commit

Permalink
Use preferred is_file and import sytax
Browse files Browse the repository at this point in the history
  • Loading branch information
stratofax committed Aug 12, 2022
1 parent e697989 commit 3cde731
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/electos/ballotmaker/make_ballots.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def make_ballots(
Output directory for generated PDF files
Styles file for ballot formatting
"""
# is the EDF a JSON file?
# is the EDF a file?
if _edf is None:
log.debug("No EDF file provided.")
log.debug("No EDF file provided to make ballots.")
return NO_FILE
if Path.is_file(_edf) is False:
log.debug(f"{_edf} is not a file")
if not _edf.is_file():
log.debug(f"Can't make ballots, EDF {_edf} is not a file")
return NO_FILE
# was a valid output directory provided?
# was a styles file provided?
Expand Down
4 changes: 2 additions & 2 deletions src/electos/ballotmaker/validate_edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def validate_edf(
"""
# is the EDF a file?
if _edf is None:
log.debug("No EDF file provided.")
log.debug("No EDF file provided for validation.")
return NO_FILE
if not _edf.is_file():
log.debug(f"{_edf} is not a file")
log.debug(f"Can't validate, EDF {_edf} is not a file")
return NO_FILE

ballot_style_count = read_edf(_edf)
Expand Down
16 changes: 8 additions & 8 deletions tests/test_make_ballots.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from pathlib import Path

from electos.ballotmaker import make_ballots
from electos.ballotmaker.constants import NO_ERRORS, NO_FILE
from electos.ballotmaker.make_ballots import make_ballots

not_a_file = Path("not_a_file.json")
imaginary_file = Path("imaginary_file.json")
test_dir = Path(__file__).parent.resolve()
test_file = Path("june_test_case.json")
full_test_path = Path(test_dir, test_file)


def test_make_ballots():
# force a no file error with Path = None
assert make_ballots.make_ballots(_edf=None) == NO_FILE
# ensure not_a_file is actually not a file
assert Path.is_file(not_a_file) == False
assert make_ballots.make_ballots(not_a_file) == NO_FILE
assert Path.is_file(full_test_path)
assert make_ballots.make_ballots(full_test_path) == NO_ERRORS
assert make_ballots(_edf=None) == NO_FILE
# ensure imaginary_file is actually not a file
assert not imaginary_file.is_file()
assert make_ballots(imaginary_file) == NO_FILE
assert full_test_path.is_file()
assert make_ballots(full_test_path) == NO_ERRORS

0 comments on commit 3cde731

Please sign in to comment.