|
18 | 18 | from taxcalc.growdiff import GrowDiff |
19 | 19 | from taxcalc.growfactors import GrowFactors |
20 | 20 | from taxcalc.calculator import Calculator |
21 | | -from taxcalc.utils import (delete_file, write_graph_file, |
| 21 | +from taxcalc.utils import (json_to_dict, delete_file, write_graph_file, |
22 | 22 | add_quantile_table_row_variable, |
23 | 23 | unweighted_sum, weighted_sum) |
24 | 24 |
|
@@ -133,7 +133,17 @@ def __init__(self, input_data, tax_year, baseline, reform, assump, |
133 | 133 | msg = f'{fname} does not end in .json' |
134 | 134 | self.errmsg += f'ERROR: BASELINE file name {msg}\n' |
135 | 135 | # check existence of BASELINE file |
136 | | - if not os.path.isfile(bas): |
| 136 | + if os.path.isfile(bas): |
| 137 | + # check validity of JSON text |
| 138 | + with open(bas, 'r', encoding='utf-8') as jfile: |
| 139 | + json_text = jfile.read() |
| 140 | + try: |
| 141 | + _ = json_to_dict(json_text) |
| 142 | + except ValueError as valerr: # pragma: no cover |
| 143 | + msg = f'{bas} contains invalid JSON' |
| 144 | + self.errmsg += f'ERROR: BASELINE file {msg}\n' |
| 145 | + self.errmsg += f'{valerr}' |
| 146 | + else: |
137 | 147 | msg = f'{bas} could not be found' |
138 | 148 | self.errmsg += f'ERROR: BASELINE file {msg}\n' |
139 | 149 | # add fname to list of basnames used in output file names |
@@ -167,7 +177,17 @@ def __init__(self, input_data, tax_year, baseline, reform, assump, |
167 | 177 | msg = f'{fname} does not end in .json' |
168 | 178 | self.errmsg += f'ERROR: REFORM file name {msg}\n' |
169 | 179 | # check existence of REFORM file |
170 | | - if not os.path.isfile(rfm): |
| 180 | + if os.path.isfile(rfm): |
| 181 | + # check validity of JSON text |
| 182 | + with open(rfm, 'r', encoding='utf-8') as jfile: |
| 183 | + json_text = jfile.read() |
| 184 | + try: |
| 185 | + _ = json_to_dict(json_text) |
| 186 | + except ValueError as valerr: # pragma: no cover |
| 187 | + msg = f'{rfm} contains invalid JSON' |
| 188 | + self.errmsg += f'ERROR: REFORM file {msg}\n' |
| 189 | + self.errmsg += f'{valerr}' |
| 190 | + else: |
171 | 191 | msg = f'{rfm} could not be found' |
172 | 192 | self.errmsg += f'ERROR: REFORM file {msg}\n' |
173 | 193 | # add fname to list of refnames used in output file names |
|
0 commit comments