Debian Codegraph @

test/unit/_cli/test_obj_loads.py

raw
1 ######################################################################
2 #
3 # File: test/unit/_cli/test_obj_loads.py
4 #
5 # Copyright 2024 Backblaze Inc. All Rights Reserved.
6 #
7 # License https://www.backblaze.com/using_b2_code.html
8 #
9 ######################################################################
10 import argparse
11
12 import pytest
13
14 from b2._internal._cli.obj_loads import validated_loads
15
16
17 @pytest.mark.parametrize(
18 "input_, expected_val",
19 [
20 # json
21 ('{"a": 1}', {
22 "a": 1
23 }),
24 ('{"a": 1, "b": 2}', {
25 "a": 1,
26 "b": 2
27 }),
28 ('{"a": 1, "b": 2, "c": 3}', {
29 "a": 1,
30 "b": 2,
31 "c": 3
32 }),
33 ],
34 )
35 def test_validated_loads(input_, expected_val):
36 assert validated_loads(input_) == expected_val
37
38
39 @pytest.mark.parametrize(
40 "input_, error_msg",
41 [
42 # not valid json nor yaml
43 ("{", "'{' is not a valid JSON value"),
44 ],
45 )
46 def test_validated_loads__invalid_syntax(input_, error_msg):
47 with pytest.raises(argparse.ArgumentTypeError, match=error_msg):
48 validated_loads(input_)