Skip to content

Commit e829805

Browse files
committed
add: temp dir to files for tests
1 parent aa3737e commit e829805

File tree

3 files changed

+75
-8
lines changed

3 files changed

+75
-8
lines changed

gendiff/gendiff.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,5 @@ def make_str_from_list(items: list) -> str:
7373
def generate_diff(path1, path2) -> str:
7474
data1 = read_file_json(path1)
7575
data2 = read_file_json(path2)
76-
return make_str_from_list(sort_list(get_list_of_dict_with_sign(data1, data2)))
76+
sorted_list_of_dict = sort_list(get_list_of_dict_with_sign(data1, data2))
77+
return make_str_from_list(sorted_list_of_dict)

pyci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Python CI
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Set up Python
13+
uses: actions/setup-python@v5
14+
with:
15+
python-version: '3.13'
16+
# make depends on uv
17+
- name: Install dependencies
18+
run: |
19+
pip install uv
20+
make install
21+
- name: Run linter and pytest
22+
run: |
23+
make check
24+
- name: Run test coverage
25+
run: |
26+
make test-coverage
27+
- name: SonarQubeScan
28+
uses: SonarSource/sonarqube-scan-action@v5
29+
env:
30+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
31+
with:
32+
args: >
33+
-Dsonar.projectKey=hexlet-boilerplates_gendiff
34+
-Dsonar.organization=hexlet-boilerplates
35+
-Dsonar.python.coverage.reportPaths=coverage.xml

tests/test_gendiff.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,54 @@
1+
import os
2+
import tempfile
3+
4+
import pytest
5+
16
from gendiff.gendiff import generate_diff, read_file_json, sort_list
27

3-
path1 = '/home/zk/python-project-50/file1.json'
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+
31+
432
data1 = {
533
"host": "hexlet.io",
634
"timeout": 50,
735
"proxy": "123.234.53.22",
836
"follow": False
937
}
1038

11-
path2 = '/home/zk/python-project-50/file2.json'
1239
data2 = {
1340
"timeout": 20,
1441
"verbose": True,
1542
"host": "hexlet.io"
1643
}
1744

1845

19-
def test_read_file_json():
20-
assert read_file_json(path1) == data1
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')
49+
assert read_file_json(file1_path) == data1
2150

22-
assert read_file_json(path2) == data2
51+
assert read_file_json(file2_path) == data2
2352

2453

2554
def test_sort_list():
@@ -35,7 +64,7 @@ def test_sort_list():
3564
]
3665

3766

38-
def test_generate_diff():
67+
def test_generate_diff(temp_dir_with_files):
3968
right_str = ("{\n"
4069
" - follow: false\n"
4170
" host: hexlet.io\n"
@@ -44,4 +73,6 @@ def test_generate_diff():
4473
" + timeout: 20\n"
4574
" + verbose: true\n"
4675
"}")
47-
assert generate_diff(path1, path2) == right_str
76+
file1_path = os.path.join(temp_dir_with_files, 'file1.json')
77+
file2_path = os.path.join(temp_dir_with_files, 'file2.json')
78+
assert generate_diff(file1_path, file2_path) == right_str

0 commit comments

Comments
 (0)