Skip to content

Commit 480c3b8

Browse files
committed
add: test of parser function
1 parent a0c8d97 commit 480c3b8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

gendiff/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import argparse
22

33

4-
def parse_args():
4+
def parse_args(args=None):
55
parser = argparse.ArgumentParser(
66
prog='gendiff',
77
description='Compares two configuration files and shows a difference.',
@@ -12,4 +12,4 @@ def parse_args():
1212
parser.add_argument('first_file')
1313
parser.add_argument('second_file')
1414

15-
return parser.parse_args()
15+
return parser.parse_args(args)

tests/test_gendiff.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55

66
from gendiff.gendiff import generate_diff, read_file_json, sort_list
7+
from gendiff.cli import parse_args
78

89

910
@pytest.fixture
@@ -75,4 +76,14 @@ def test_generate_diff(temp_dir_with_files):
7576
"}")
7677
file1_path = os.path.join(temp_dir_with_files, 'file1.json')
7778
file2_path = os.path.join(temp_dir_with_files, 'file2.json')
78-
assert generate_diff(file1_path, file2_path) == right_str
79+
assert generate_diff(file1_path, file2_path) == right_str
80+
81+
82+
def test_parse_args_with_args():
83+
test_args = ['--format', 'test_format', 'file1.json', 'file2.json']
84+
85+
args = parse_args(test_args)
86+
87+
assert args.format == 'test_format'
88+
assert args.first_file == 'file1.json'
89+
assert args.second_file == 'file2.json'

0 commit comments

Comments
 (0)