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