forked from meltano/meltano
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Improve config JSON array/object error message and parser (melta…
- Loading branch information
1 parent
2ba4720
commit 39a10d5
Showing
2 changed files
with
119 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from meltano.core.setting_definition import SettingDefinition, SettingKind | ||
|
||
|
||
class TestSettingDefinition: | ||
@pytest.mark.parametrize( | ||
("setting_definition", "uncast_expected_pairs"), | ||
( | ||
( | ||
SettingDefinition("test_setting", kind=SettingKind.ARRAY), | ||
( | ||
('["abc", "xyz"]', ["abc", "xyz"]), | ||
('["abc", "xyz",]', ["abc", "xyz"]), | ||
("['abc', 'xyz']", ["abc", "xyz"]), | ||
("[abc, xyz]", ValueError), | ||
("'abc', 'xyz'", ["abc", "xyz"]), | ||
("'abc', 'xyz',", ["abc", "xyz"]), | ||
('[null, "xyz"]', [None, "xyz"]), | ||
("{'abc', 'xyz'}", ValueError), | ||
("1234", ValueError), | ||
("[1234, 5678]", [1234, 5678]), | ||
), | ||
), | ||
( | ||
SettingDefinition("test_setting", kind=SettingKind.OBJECT), | ||
( | ||
( | ||
'{"key_1": "value_1", "key_2": "value_2"}', | ||
{"key_1": "value_1", "key_2": "value_2"}, | ||
), | ||
('{"key": "value",}', {"key": "value"}), | ||
('{"key": null}', {"key": None}), | ||
("{'key': null}", ValueError), | ||
("key: value", ValueError), | ||
("{'key': 'value'}", {"key": "value"}), | ||
("{key: value}", ValueError), | ||
("{'abc', 'xyz'}", ValueError), | ||
("1234", ValueError), | ||
), | ||
), | ||
), | ||
ids=("array", "object"), | ||
) | ||
def test_cast_value_array( | ||
self, | ||
setting_definition: SettingDefinition, | ||
uncast_expected_pairs, | ||
): | ||
for uncast, expected in uncast_expected_pairs: | ||
if isinstance(expected, type) and issubclass(expected, Exception): | ||
with pytest.raises(expected): | ||
setting_definition.cast_value(uncast) | ||
else: | ||
assert setting_definition.cast_value(uncast) == expected |