def test_generate_diff(source, changed_source, correct_diff_path, style): if style: diff = generate_diff(source, changed_source, style) else: diff = generate_diff(source, changed_source) with open(correct_diff_path, 'r') as correct_diff: assert diff == correct_diff.read()
def test_diff_stylish_json(file1, file2, right_answer, format_name): path_dict1 = get_fixture_path(file1) path_dict2 = get_fixture_path(file2) path_right_answer = get_fixture_path(right_answer) with open('{}'.format(path_right_answer)) as f: right_answer = f.read()[:-1] assert generate_diff(path_dict1, path_dict2, format_name) == right_answer if format_name == 'stylish': assert generate_diff(path_dict1, path_dict2) == right_answer
def test(): for test_data in TEST_DATA.values(): with open(test_data[ANSWER], 'r') as file: correct_result = file.read() assert correct_result == format( generate_diff(test_data[BEFORE], test_data[AFTER]), test_data[FORMAT])
def main(): parser = argparse.ArgumentParser(description='Generate diff') parser.add_argument('first_file', type=str) parser.add_argument('second_file', type=str) parser.add_argument('-f', '--format', help='set format of output') args = parser.parse_args() diff = generate_diff(args.first_file, args.second_file) print(diff)
def main(): """Entry point for gendiff.""" arguments = parser.parse_args() diff = generate_diff( arguments.first_file, arguments.second_file, arguments.output_format, ) print(diff)
def main(): args = take_apart_params() print( generate_diff( args.first_file, args.second_file, args.format, ) )
def main(): """Run main func.""" args = args_parse() try: # noqa: WPS229 # allow long ``try`` body length diff = generate_diff(args.first_file, args.second_file, args.formater) print(diff) # noqa: WPS421 # allow print call except (FormaterError, FileTypeError) as e: # noqa: WPS111 # ignore wrn about to short name print('Exception: {0}'.format(str(e))) # noqa: WPS421 # ignore warning about print call
def main(first_file, second_file, format): # noqa: WPS125 """Generate diff. Args: first_file (str): Plain json file for comparison. second_file (str): Plain json file for comparison. format (str): Output format. """ diff = generate_diff.generate_diff(first_file, second_file) print(diff)
def main(): parser = argparse.ArgumentParser(description='Generate diff') parser.add_argument('first_file', type=str) parser.add_argument('second_file', type=str) parser.add_argument('-f', '--format', help='set format of output') args = parser.parse_args() format_type = formatters.DEFAULT if args.format is None else args.format print( formatters.format(generate_diff(args.first_file, args.second_file), format_type))
def test_json_format(expected, file_name1, file_name2, output_format): path_file1 = file_name1 path_file2 = file_name2 diff = json.loads(generate_diff(path_file1, path_file2, output_format)) path_expected = FIXTURES_DIR / expected with open(path_expected) as f: expected = json.load(f) assert diff == expected, 'diff must be exact as the reference value'
def test_text_formats(expected, file_name1, file_name2, output_format): path_file1 = file_name1 path_file2 = file_name2 diff = generate_diff(path_file1, path_file2, output_format).split('\n') path_expected = FIXTURES_DIR / expected with open(path_expected) as f: expected = f.read().split('\n') assert diff == expected, 'diff must be exact as the reference value'
def run(first_file, second_file): """Take 2 files from cli and print a diff between them. Args: first_file: some file second_file: some file """ first_file_extension = get_extension(first_file) second_file_extension = get_extension(second_file) if first_file_extension != second_file_extension: print('Sorry, we can compare only files with the same extension') return # we need to check only one extension, because they are the same if first_file_extension not in EXTENSIONS: print('Sorry, we can work only with JSON extension') return print(jsonlike.generate_output( generate_diff( read_file(first_file), read_file(second_file), ), ))
def test_five_json(): x = generate_diff('tests/fixtures/test for json/test5_file1.json', 'tests/fixtures/test for json/test5_file2.json') y = open("tests/fixtures/test for json/test5.txt", "r") assert x == y.read()
def test_four_yaml(): x = generate_diff('tests/fixtures/test for yaml/test4_file1.yml', 'tests/fixtures/test for yaml/test4_file2.yml') y = open("tests/fixtures/test for json/test4.txt", "r") assert x == y.read()
def test_yaml(): result = generate_diff('tests/fixtures/file1.yml', 'tests/fixtures/file2.yml') f = open(PATH_TO_ANSWER) answer = f.read()[:-1] assert result == answer
def test_three(): x = generate_diff('tests/fixtures/test for json/test3_file1.json', 'tests/fixtures/test for json/test3_file2.json') y = open("tests/fixtures/test for json/test3.txt", "r") assert x == y.read()
def main(): path_file1, path_file2, format_name = parser_arg() result = generate_diff(path_file1, path_file2, format_name) print(result)