From 570273dbeba1c7fef13f946bfe78e827253cbbc7 Mon Sep 17 00:00:00 2001 From: Pat Nadolny Date: Thu, 15 Feb 2024 15:48:55 -0500 Subject: [PATCH] custom parse faker config to array --- hub_utils/meltano_util.py | 4 ++- tests/data/faker_configs.json | 62 +++++++++++++++++++++++++++++++++++ tests/test_meltano_utils.py | 19 +++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 tests/data/faker_configs.json diff --git a/hub_utils/meltano_util.py b/hub_utils/meltano_util.py index ab8a323..682767e 100644 --- a/hub_utils/meltano_util.py +++ b/hub_utils/meltano_util.py @@ -259,7 +259,9 @@ def _get_kind_from_type(type, name, enforce_desc): kind = type if not kind: - if enforce_desc: + if name == "faker_config.locale": + kind = "array" + elif enforce_desc: kind = typer.prompt(f"[{name}] `kind`", default="string") else: name = name diff --git a/tests/data/faker_configs.json b/tests/data/faker_configs.json new file mode 100644 index 0000000..be97fba --- /dev/null +++ b/tests/data/faker_configs.json @@ -0,0 +1,62 @@ +{ + "name": "tap-faker-example", + "description": "Faker tap class.", + "version": "[could not be detected]", + "sdk_version": "0.35.0", + "supported_python_versions": null, + "capabilities": [], + "settings": { + "type": "object", + "properties": { + "faker_config": { + "type": [ + "object", + "null" + ], + "properties": { + "seed": { + "oneOf": [ + { + "type": [ + "number" + ] + }, + { + "type": [ + "string" + ] + }, + { + "type": [ + "boolean" + ] + } + ], + "description": "Value to seed the Faker generator for deterministic output: https://faker.readthedocs.io/en/master/#seeding-the-generator" + }, + "locale": { + "oneOf": [ + { + "type": [ + "string" + ] + }, + { + "type": "array", + "items": { + "type": [ + "string" + ] + } + } + ], + "description": "One or more LCID locale strings to produce localized output for: https://faker.readthedocs.io/en/master/#localization" + } + }, + "description": "Config for the [`Faker`](https://faker.readthedocs.io/en/master/) instance variable `fake` used within map expressions. Only applicable if the plugin specifies `faker` as an addtional dependency (through the `singer-sdk` `faker` extra or directly)." + } + }, + "required": [] + } + } + \ No newline at end of file diff --git a/tests/test_meltano_utils.py b/tests/test_meltano_utils.py index 6b88e62..03b2fae 100644 --- a/tests/test_meltano_utils.py +++ b/tests/test_meltano_utils.py @@ -537,3 +537,22 @@ def test_get_quality(input, expected): ) def test_clean_description(input, expected): assert MeltanoUtil._clean_description(input) == expected + + +def test_sdk_about_parsing_faker_configs(): + sdk_about_dict = _read_data('faker_configs.json') + settings, _, _ = MeltanoUtil._parse_sdk_about_settings(sdk_about_dict) + assert settings == [ + { + "name": "faker_config.seed", + "label": "Faker Config Seed", + "description": "Value to seed the Faker generator for deterministic output: https://faker.readthedocs.io/en/master/#seeding-the-generator", + "kind": "string" + }, + { + "name": "faker_config.locale", + "label": "Faker Config Locale", + "description": "One or more LCID locale strings to produce localized output for: https://faker.readthedocs.io/en/master/#localization", + "kind": "array" + } + ]