Skip to content

Commit 71b3a18

Browse files
committed
6th step
1 parent 5cf439d commit 71b3a18

File tree

11 files changed

+67
-6
lines changed

11 files changed

+67
-6
lines changed

.coverage

0 Bytes
Binary file not shown.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.venv/
22
dist/
33
__pycache__/
4-
gendiff1.cast
4+
gendiff1.cast
5+
gendiff2.cast

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
[![Maintainability](https://api.codeclimate.com/v1/badges/88675eaf4e4ca1e04a88/maintainability)](https://codeclimate.com/github/ttehasi/python-project-50/maintainability)
66
[![Test Coverage](https://api.codeclimate.com/v1/badges/88675eaf4e4ca1e04a88/test_coverage)](https://codeclimate.com/github/ttehasi/python-project-50/test_coverage)
77

8-
## Asciinema:
8+
## Asciinema JSON file:
99

1010
[![asciicast](https://asciinema.org/a/djCfDR2K0qTnGeiqy4hVWhLO9.svg)](https://asciinema.org/a/djCfDR2K0qTnGeiqy4hVWhLO9)
1111

12+
## Asciinema YAML file:
13+
14+
[![asciicast](https://asciinema.org/a/H918cvPLQohe9DMY2NDxLKcaU.svg)](https://asciinema.org/a/H918cvPLQohe9DMY2NDxLKcaU)
15+
1216
### Links
1317

1418
This project was built using these tools:

gendiff/gen_diff.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import json
22

3+
from gendiff.pars_yaml import open_ymlf
4+
35

46
def open_f(path_to_file) -> dict:
57
with open(path_to_file) as file:
68
return json.load(file)
79

810

911
def generate_diff(file1, file2):
10-
file1 = open_f(file1)
11-
file2 = open_f(file2)
12+
if str(file1)[-5:] == '.json' and str(file2)[-5:] == '.json':
13+
file1 = open_f(file1)
14+
file2 = open_f(file2)
15+
else:
16+
file1 = open_ymlf(file1)
17+
file2 = open_ymlf(file2)
1218
res = '''{
1319
'''
1420
for i in sorted(list(file1)):

gendiff/pars_yaml.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import yaml
2+
3+
4+
def open_ymlf(path) -> dict:
5+
with open(path) as file:
6+
return yaml.load(file, yaml.Loader)
7+
8+
print(open_ymlf('/home/ttehasi/python-project-50/tests/test_data/file2.yml'))
3 Bytes
Binary file not shown.

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ version = "0.1.0"
44
description = "Add your description here"
55
readme = "README.md"
66
requires-python = ">=3.12"
7-
dependencies = []
7+
dependencies = [
8+
"pyyaml>=6.0.2",
9+
]
810

911
[build-system]
1012
requires = ["hatchling"]

tests/test_data/file1.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
host: hexlet.io
2+
timeout: 50
3+
proxy: 123.234.53.22
4+
follow: false

tests/test_data/file2.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
timeout: 20
2+
verbose: true
3+
host: hexlet.io

tests/test_generate_diff.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ def test_generate_diff():
1515
result = read_file('result_file1_file2.txt')
1616
actual = generate_diff(get_test_data_path('file1.json'),
1717
get_test_data_path('file2.json'))
18-
assert actual == result
18+
yam_act = generate_diff(get_test_data_path('file1.yml'),
19+
get_test_data_path('file2.yml'))
20+
assert actual == result
21+
assert yam_act == result

0 commit comments

Comments
 (0)