Skip to content

Commit

Permalink
new error messages for missing file and incorrect JSON formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
chusloj committed Jan 5, 2021
1 parent bf71baa commit 119a946
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions taxcalc/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,16 +693,18 @@ def convert_year_to_int(syr_dict):
txt = req.text
else:
if isinstance(topkey, str) and (topkey == ''):
raise ValueError("String is empty.")
raise ValueError("topkey string is empty.")
if isinstance(obj, str):
if obj == '':
raise ValueError("String is empty.")
raise ValueError("obj string is empty.")
elif obj.endswith('.json') and not os.path.isfile(obj):
raise FileNotFoundError("The .json file does not exist.")
elif ("{" and "}") in obj:
txt = obj
else:
raise OSError("The .json file or variable does not exist or is misspecified.")
raise ValueError("The JSON variable is misspecified.")
else:
raise OSError("The .json file or variable does not exist or is misspecified.")
raise ValueError("The JSON variable is misspecified.")
# strip out //-comments without changing line numbers
json_txt = re.sub('//.*', ' ', txt)
# convert JSON text into a Python dictionary
Expand Down
6 changes: 3 additions & 3 deletions taxcalc/tests/test_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def test_read_bad_json_assump_file():
"""
with pytest.raises(ValueError):
Calculator.read_json_param_objects(None, badassump1)
with pytest.raises(OSError):
with pytest.raises(ValueError):
Calculator.read_json_param_objects(None, 'unknown_file_name')
with pytest.raises(ValueError):
Calculator.read_json_param_objects(None, list())
Expand All @@ -514,9 +514,9 @@ def test_json_doesnt_exist():
"""
Test JSON file which doesn't exist
"""
with pytest.raises(OSError):
with pytest.raises(FileNotFoundError):
Calculator.read_json_param_objects(None, './reforms/doesnt_exist.json')
with pytest.raises(OSError):
with pytest.raises(FileNotFoundError):
Calculator.read_json_param_objects('./reforms/doesnt_exist.json', None)


Expand Down

0 comments on commit 119a946

Please sign in to comment.