Skip to content

Commit

Permalink
add option to suppress warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarobruce committed Oct 26, 2017
1 parent 27afa56 commit 2a9d339
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ The following script is run to create alternately formatted data files for the `
Two scripts help maintain and validate district office data:

* `geocode_offices.py` : Derives latitude, longitude pairs for office addresses. It should be run whenever new offices are added. By default this script geocodes all offices with addresses that have not already been geocoded. It optionally takes bioguide IDs as arguments, and in this case will geocode just offices for the specified ids. This script uses the Google Maps API, and requires that a key be set in scripts/cache/google_maps_api_key.txt .
* `office_validator.py` : Validates rules for district office data and reports errors and warnings. This script should be run whenever offices are added or modified. It is used by continuous integration testing, so errors here will cause the build to fail.
* `office_validator.py` : Validates rules for district office data and reports errors and warnings. An optional `--skip-warnings` argument will suppress display of warnings. This script should be run whenever offices are added or modified. It is used by continuous integration testing, so errors here will cause the build to fail.

Every script in `scripts/` should be safely import-able without executing code, beyond imports themselves. We typically do this with a `def run():` declaration after the imports, and putting this at the bottom of the script:

Expand Down
12 changes: 10 additions & 2 deletions scripts/office_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def print_issues(legislator, errors, warnings):
print("")


def run():
def run(skip_warnings=False):
legislators = load_to_dict("../legislators-current.yaml")
legislators_offices = load_to_dict("../legislators-district-offices.yaml")

Expand All @@ -188,6 +188,9 @@ def run():

errors, warnings = check_legislator_offices(legislator_offices, legislator)

if skip_warnings:
warnings = []

if errors:
has_errors = True

Expand All @@ -201,5 +204,10 @@ def run():
return has_errors

if __name__ == '__main__':
has_errors = run()
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--skip-warnings", action="store_true")
args = parser.parse_args()

has_errors = run(skip_warnings=args.skip_warnings)
sys.exit(1 if has_errors else 0)
2 changes: 1 addition & 1 deletion test/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def check_id_uniqueness(seen_ids):
" ".join(legislator['id']['bioguide'] for legislator in occurrences)))

def check_district_offices():
has_errors = validate_offices()
has_errors = validate_offices(skip_warnings=True)
if has_errors:
error("District offices have errors")

Expand Down

0 comments on commit 2a9d339

Please sign in to comment.