Skip to content

Commit 435b127

Browse files
wrote tests on no additional arguments, 1 and 2 arguments. need to test for invalid arguments.
1 parent bdd5139 commit 435b127

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/diffpy/labpdfproc/labpdfprocapp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def get_args():
6262
"--additional-info",
6363
metavar=("KEY=VALUE"),
6464
action="append",
65-
help="specify key-value pairs to be loaded into metadata. You can specify multiple "
66-
"paris by calling -add multiple times",
65+
help="specify key-value pairs to be loaded into metadata by using key=value. "
66+
"You can specify multiple paris by calling -add multiple times.",
6767
)
6868
args = p.parse_args()
6969
return args
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from argparse import ArgumentParser
2+
3+
import pytest
4+
5+
from diffpy.labpdfproc.tools import load_additional_info
6+
7+
params5 = [
8+
([], []),
9+
([["weather=rainy"]], [["weather", "rainy"]]),
10+
([["weather=rainy", "day=tuesday"]], [["weather", "rainy"], ["day", "tuesday"]]),
11+
]
12+
13+
14+
@pytest.mark.parametrize("inputs, expected", params5)
15+
def test_load_additional_info(inputs, expected):
16+
actual_parser = ArgumentParser()
17+
actual_parser.add_argument("-add", "--additional-info", action="append", metavar=("KEY=VALUE"))
18+
actual_args = actual_parser.parse_args([])
19+
expected_parser = ArgumentParser()
20+
expected_args = expected_parser.parse_args([])
21+
22+
if not inputs:
23+
actual_args = load_additional_info(actual_args)
24+
assert actual_args == expected_args
25+
else:
26+
setattr(actual_args, "additional_info", inputs[0])
27+
actual_args = load_additional_info(actual_args)
28+
for expected_pair in expected:
29+
setattr(expected_args, expected_pair[0], expected_pair[1])
30+
assert actual_args == expected_args

0 commit comments

Comments
 (0)