File tree Expand file tree Collapse file tree 5 files changed +36
-11
lines changed Expand file tree Collapse file tree 5 files changed +36
-11
lines changed Original file line number Diff line number Diff line change 1
1
""" The BallotMaker Command Line Interface (CLI)"""
2
+ import logging
3
+ import sys
2
4
from os import strerror
3
5
from pathlib import Path
4
6
from typing import Optional
12
14
STYLE_HELP = "Stylesheet file for ballot generation"
13
15
VERSION_HELP = "Print the version number."
14
16
17
+ # configure logging
18
+ logging .basicConfig (stream = sys .stdout , level = logging .DEBUG )
19
+ log = logging .getLogger (__name__ )
20
+
15
21
16
22
def version_callback (value : bool ):
17
23
if value :
@@ -45,8 +51,8 @@ def make(
45
51
"""Make ballots from EDF file"""
46
52
make_ballots_result = make_ballots .make_ballots (edf , output_dir , style )
47
53
if make_ballots_result != NO_ERRORS :
48
- typer . echo (
49
- f"Error { make_ballots_result } making ballots: { strerror (make_ballots_result )} "
54
+ log . error (
55
+ f"Code { make_ballots_result } in make - { strerror (make_ballots_result )} "
50
56
)
51
57
return make_ballots_result
52
58
@@ -61,8 +67,8 @@ def validate(
61
67
"""Validate data in EDF file"""
62
68
validate_edf_result = validate_edf .validate_edf (edf )
63
69
if validate_edf_result != NO_ERRORS :
64
- typer . echo (
65
- f"Error { validate_edf_result } validating EDF: { strerror (validate_edf_result )} "
70
+ log . error (
71
+ f"Code { validate_edf_result } in validate - { strerror (validate_edf_result )} "
66
72
)
67
73
return validate_edf_result
68
74
Original file line number Diff line number Diff line change
1
+ import logging
1
2
from pathlib import Path
2
3
3
4
from electos .ballotmaker .constants import NO_ERRORS , NO_FILE
4
5
6
+ log = logging .getLogger (__name__ )
7
+
5
8
6
9
def make_ballots (
7
10
_edf : Path , _output_dir : Path = None , _styles : Path = None
@@ -13,8 +16,12 @@ def make_ballots(
13
16
Output directory for generated PDF files
14
17
Styles file for ballot formatting
15
18
"""
16
- # is the EDF a JSON file?
19
+ # is the EDF a file?
17
20
if _edf is None :
21
+ log .debug ("No EDF file provided to make ballots." )
22
+ return NO_FILE
23
+ if not _edf .is_file ():
24
+ log .debug (f"Can't make ballots, EDF { _edf } is not a file" )
18
25
return NO_FILE
19
26
# was a valid output directory provided?
20
27
# was a styles file provided?
Original file line number Diff line number Diff line change
1
+ import logging
1
2
from pathlib import Path
2
3
3
4
from electos .ballotmaker .constants import NO_DATA , NO_ERRORS , NO_FILE
4
5
from electos .ballotmaker .read_edf import read_edf
5
6
7
+ log = logging .getLogger (__name__ )
8
+
6
9
7
10
def validate_edf (
8
11
_edf : Path ,
@@ -13,10 +16,12 @@ def validate_edf(
13
16
"""
14
17
# is the EDF a file?
15
18
if _edf is None :
19
+ log .debug ("No EDF file provided for validation." )
16
20
return NO_FILE
17
21
if not _edf .is_file ():
22
+ log .debug (f"Can't validate, EDF { _edf } is not a file" )
18
23
return NO_FILE
19
24
20
25
ballot_style_count = read_edf (_edf )
21
- print (f"Found { ballot_style_count } ballots in { _edf } " )
26
+ log . info (f"Found { ballot_style_count } ballots in { _edf } " )
22
27
return NO_ERRORS
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ def test_make():
34
34
# bypass mandatory CLI option to force error
35
35
assert cli .make (edf = None ) == NO_FILE
36
36
# any old path will satisfy current tests
37
- assert cli .make (imaginary_file ) == NO_ERRORS
37
+ assert cli .make (imaginary_file ) == NO_FILE
38
38
# check CLI errors: no options for make
39
39
result = runner .invoke (cli .app , ["make" ])
40
40
assert result .exit_code == NO_FILE
Original file line number Diff line number Diff line change 1
1
from pathlib import Path
2
2
3
- from electos .ballotmaker import make_ballots
4
3
from electos .ballotmaker .constants import NO_ERRORS , NO_FILE
4
+ from electos .ballotmaker .make_ballots import make_ballots
5
5
6
- test_file = Path ("empty.json" )
6
+ imaginary_file = Path ("imaginary_file.json" )
7
+ test_dir = Path (__file__ ).parent .resolve ()
8
+ test_file = Path ("june_test_case.json" )
9
+ full_test_path = Path (test_dir , test_file )
7
10
8
11
9
12
def test_make_ballots ():
10
13
# force a no file error with Path = None
11
- assert make_ballots .make_ballots (_edf = None ) == NO_FILE
12
- assert make_ballots .make_ballots (test_file ) == NO_ERRORS
14
+ assert make_ballots (_edf = None ) == NO_FILE
15
+ # ensure imaginary_file is actually not a file
16
+ assert not imaginary_file .is_file ()
17
+ assert make_ballots (imaginary_file ) == NO_FILE
18
+ assert full_test_path .is_file ()
19
+ assert make_ballots (full_test_path ) == NO_ERRORS
You can’t perform that action at this time.
0 commit comments