def print_defaults(form_name, form_version): form_module_name = 'luca.forms.' + form_name try: form_module = importlib.import_module(form_module_name) except ImportError: raise ValueError( 'cannot find a Luca form named {!r}'.format(form_module_name)) message = None if form_version is None: message = [ 'Please specify a particular version of this form' ' with a command like:' ] elif form_version not in form_module.versions: message = [ 'Sorry, but luca does not support that form for the year' ' {!r}.\nHere are the years luca supports that form:'.format( form_version) ] if message: for version in form_module.versions: message.append('\n luca form {} {}'.format(form_name, version)) sys.exit(''.join(message)) form = formlib.Form() form.form_name = form_name form.form_version = form_version if hasattr(form_module, 'defaults'): form_module.defaults(form) print formlib.dump_json(form).encode('utf-8').strip()
def test_sample_filing(sample_filing_path): print "arg is", sample_filing_path with open(sample_filing_path) as f: json_data = f.read() form, form_module = actions.process(json_data) json_output = formlib.dump_json(form).encode('utf-8') assert json_data == json_output
def test_dumping_form_preserves_inputs_and_includes_new_outputs(self): for json in json_in, json_empty_output, json_filled_output: f = load_json(json) f._enter_output_mode() process_form(f) j = dump_json(f) assert j == json_filled_output
def test_dumping_list_of_subforms(self): f = load_json('{"inputs": {"items": [{"n": 10}, {"m": 11}]}}') f._enter_output_mode() f.items[0].x = 100 f.items[0].y = 101 j = dump_json(f) assert j == dedent(u'''\ { "inputs": { "items": [ { "n": 10 }, { "m": 11 } ] }, "outputs": { "items": [ { "x": 100, "y": 101 }, {} ] } } ''')
def complete_form(json_path): with open(json_path) as f: json_data = f.read() form, form_module = process(json_data) json_string = formlib.dump_json(form).encode('utf-8') with open(json_path, 'w') as f: f.write(json_string) if not os.path.isdir('out'): os.mkdir('out') return form_module, form
def print_defaults(form_name, form_version): form_module_name = 'luca.forms.' + form_name try: form_module = importlib.import_module(form_module_name) except ImportError: raise ValueError('cannot find a Luca form named {!r}'.format( form_module_name)) if form_version is None or form_version not in form_module.versions: print ('Please specify a particular version of this form' ' with a command like:') for version in form_module.versions: print ' luca form {} {}'.format(form_name, version) return form = formlib.Form() form.form_name = form_name form.form_version = form_version if hasattr(form_module, 'defaults'): form_module.defaults(form) print formlib.dump_json(form).encode('utf-8').strip()
def test_dumping_form_includes_output_subforms(self): f = load_json('{"inputs": {"A": {"a": 1}}}') f._enter_output_mode() f.B = Form() f.B._enter_output_mode() f.B.b = 2 j = dump_json(f) assert j == dedent(u'''\ { "inputs": { "A": { "a": 1 } }, "outputs": { "B": { "b": 2 } } } ''')
def test_json_output_handles_decimals_in_lists(self): f = Form() f.line1 = [["First Bank", Decimal('1.23')], ["Second Bank", Decimal('4.56')]] assert dump_json(f) == dedent(u'''\ { "inputs": { "line1": [ [ "First Bank", "1.23" ], [ "Second Bank", "4.56" ] ] }, "outputs": {} } ''')
def test_dumping_form_preserves_inputs(self): for json in json_in, json_empty_output, json_filled_output: f = load_json(json) j = dump_json(f) assert j == json_empty_output