11import os
2- import tempfile
3-
4- import pytest
52
63from gendiff .gendiff import generate_diff , read_file_json , sort_list
74
8-
9- @pytest .fixture
10- def temp_dir_with_files ():
11- with tempfile .TemporaryDirectory () as temp_dir :
12- file1_path = os .path .join (temp_dir , 'file1.json' )
13- file2_path = os .path .join (temp_dir , 'file2.json' )
14-
15- with open (file1_path , 'w' ) as f :
16- f .write ('{\n '
17- '"host": "hexlet.io",\n '
18- '"timeout": 50,\n '
19- '"proxy": "123.234.53.22",\n '
20- '"follow": false\n '
21- '}' )
22- with open (file2_path , 'w' ) as f :
23- f .write ('{\n '
24- '"timeout": 20,\n '
25- '"verbose": true,\n '
26- '"host": "hexlet.io"\n '
27- '}' )
28-
29- yield temp_dir
30-
5+ current_dir = os .path .dirname (os .path .abspath (__file__ ))
6+ dir_with_data = os .path .join (current_dir , 'test_data' )
317
328data1 = {
339 "host" : "hexlet.io" ,
@@ -43,9 +19,9 @@ def temp_dir_with_files():
4319}
4420
4521
46- def test_read_file_json (temp_dir_with_files ):
47- file1_path = os .path .join (temp_dir_with_files , 'file1.json' )
48- file2_path = os .path .join (temp_dir_with_files , 'file2.json' )
22+ def test_read_file_json ():
23+ file1_path = os .path .join (dir_with_data , 'file1.json' )
24+ file2_path = os .path .join (dir_with_data , 'file2.json' )
4925 assert read_file_json (file1_path ) == data1
5026 assert read_file_json (file1_path ) != data2
5127 assert read_file_json (file2_path ) == data2
@@ -70,7 +46,7 @@ def test_sort_list():
7046 ]
7147
7248
73- def test_generate_diff (temp_dir_with_files ):
49+ def test_generate_diff ():
7450 right_str = ("{\n "
7551 " - follow: false\n "
7652 " host: hexlet.io\n "
@@ -80,7 +56,7 @@ def test_generate_diff(temp_dir_with_files):
8056 " + verbose: true\n "
8157 "}" )
8258 wrong_str = ''
83- file1_path = os .path .join (temp_dir_with_files , 'file1.json' )
84- file2_path = os .path .join (temp_dir_with_files , 'file2.json' )
59+ file1_path = os .path .join (dir_with_data , 'file1.json' )
60+ file2_path = os .path .join (dir_with_data , 'file2.json' )
8561 assert generate_diff (file1_path , file2_path ) == right_str
8662 assert generate_diff (file1_path , file2_path ) != wrong_str
0 commit comments