def test_expect(): assert generate_diff("tests/fixtures/before_fail.json", "tests/fixtures/after.json", "text") == 'File not found' assert generate_diff("tests/fixtures/before.fail", "tests/fixtures/after_fail.fail", "text") == 'Unsupported type of file. '\ 'Supported .json and .yml'
def main(): parser = argparse.ArgumentParser(description='Generate diff') parser.add_argument('first_file') parser.add_argument('second_file') parser.add_argument('-f', '--format', help='set format of output', default='plain', choices=['plain', 'text', 'json']) args = parser.parse_args() generate_diff(args.first_file, args.second_file, args.format)
def test_input_formats(): with open("tests/fixtures/plain.golden", "r") as result_json: assert generate_diff("tests/fixtures/before.yml", "tests/fixtures/after.yml", "plain") == result_json.read() with open("tests/fixtures/plain.golden", "r") as result_plain: assert generate_diff("tests/fixtures/before.json", "tests/fixtures/after.json", "plain") == result_plain.read()
def test_output_formats(): with open("tests/fixtures/plain.golden", "r") as result_plain: assert generate_diff("tests/fixtures/before.json", "tests/fixtures/after.json", "plain") == result_plain.read() with open("tests/fixtures/json.golden", "r") as result_json: assert generate_diff("tests/fixtures/before.json", "tests/fixtures/after.json", "json") == result_json.read() with open("tests/fixtures/text.golden", "r") as result_text: assert generate_diff("tests/fixtures/before.json", "tests/fixtures/after.json", "text") == result_text.read() with open("tests/fixtures/plain_text.golden", "r") as result_plain_text: assert generate_diff("tests/fixtures/before_plain.json", "tests/fixtures/after_plain.json", "text") == result_plain_text.read()
def main(): parser = argparse.ArgumentParser(description='Generate diff') parser.add_argument('first_file', help='first file to compare') parser.add_argument('second_file', help='second file to compare') 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 test_instantiation(self): first_file = '/home/belrom/python-project-lvl2/before.json' second_file = '/home/belrom/python-project-lvl2/after.json' assert_diff = ''' {\n host: hexlet.io\n + verbose: True\n - timeout: 50\n + timeout: 20\n - proxy: 123.234.53.22\n }''' diff = generate_diff(first_file, second_file) self.assertEqual(diff, assert_diff)
def test_json(): before = "tests/fixtures/json_before.json" after = "tests/fixtures/json_after.json" result = open("tests/fixtures/diff.txt") assert generate_diff(before, after) == result.read()
def test_json_json(): before = 'tests/fixtures/json_recursive_before.json' after = 'tests/fixtures/json_recursive_after.json' result = open("tests/fixtures/diff_json.txt") assert generate_diff(before, after, "json") == result.read()
def test_expection_file(file1, file2, output_format, output_file): file_path = FIXDIR / output_file with open(os.path.abspath(file_path)) as file: data_file = file.read() with pytest.raises(SystemExit): generate_diff(FIXDIR / file1, FIXDIR / file2, output_format)
def test_correct_comparison(file1, file2, output_format, output_file): file_path = FIXDIR / output_file with open(os.path.abspath(file_path)) as file: data_file = file.read() assert generate_diff(FIXDIR / file1, FIXDIR / file2, output_format) == data_file
def test_format_json(data_sets, expected_results): testcase = 'format_json' format = 'json' first, second = data_sets(testcase) assert expected_results(testcase) == generate_diff(first, second, format)
def test_complex_json(data_sets, expected_results): testcase = 'complex_json' format = 'pretty' first, second = data_sets(testcase) assert expected_results(testcase) == generate_diff(first, second, format)
def test_plain_yaml(data_sets, expected_results): testcase = 'plain_yaml' format = 'pretty' first, second = data_sets(testcase) assert expected_results(testcase) == generate_diff(first, second, format)