def test_load_all_as_json(): """Tests yamlstratus.load_all_as_json()""" for json_filename, yaml_filename in get_test_pairs(test_dir): with open(json_filename, 'r') as json_f: all_expected_json = json.loads(json_f.read()) with open(yaml_filename, 'r') as yaml_f: json_cnt = 1 for actual_json_str in yamlstratus.load_all_as_json( yaml_f, **all_expected_json[0]): actual_json = json.loads(actual_json_str) expected_json = all_expected_json[json_cnt] compare_json(expected_json, actual_json) json_cnt += 1
args = parser.parse_args() incdirs = (args.include_dirs or ".").split(os.pathsep) outdir = args.output_dir or "target" params = args.param or [] root_tag = args.root_tag or "main" params_dict = dict() for param in params: param_name, param_value = param[0].split('=') params_dict[param_name] = param_value if not os.path.exists(outdir): os.makedirs(outdir) for filename in args.src: output_file_name = os.path.splitext(os.path.basename(filename))[0] + '.json' if outdir is not None: output_file_name = os.path.join(outdir, output_file_name) with open(output_file_name, 'w') as out: with open(filename, 'r') as f: file_incdirs = incdirs + [os.path.dirname(filename)] for json_part in yamlstratus.load_all_as_json( f, include_dirs=file_incdirs, params=params_dict, root_tag=root_tag): out.write(json_part)