From cb695ab541ee5e0c3cabeacb6841339659e8be2a Mon Sep 17 00:00:00 2001 From: Marco Heinemann Date: Thu, 12 Feb 2026 10:04:38 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20schema=20tests=20for=20doc?= =?UTF-8?q?name=20in=20select=20and=20validate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/schema/__snapshots__/test_schema.ambr | 90 +++++++++++++++++++++ tests/schema/fixtures/fields.yml | 90 +++++++++++++++++++++ 2 files changed, 180 insertions(+) diff --git a/tests/schema/__snapshots__/test_schema.ambr b/tests/schema/__snapshots__/test_schema.ambr index cdcb4d0ed..893358a87 100644 --- a/tests/schema/__snapshots__/test_schema.ambr +++ b/tests/schema/__snapshots__/test_schema.ambr @@ -3449,6 +3449,96 @@ }), }) # --- +# name: test_schemas[schema/fixtures/fields-docname_select_error] + ''' + ERROR: Need 'IMPL_1' has schema violations: + Severity: violation + Need path: IMPL_1 + Schema path: [0] > local > required + User message: asil required for needs in index file + Schema message: "asil" is a required property [sn_schema_violation.local_fail] + + ''' +# --- +# name: test_schemas[schema/fixtures/fields-docname_select_error].1 + dict({ + 'validated_needs_count': 1, + 'validation_warnings': dict({ + 'IMPL_1': list([ + dict({ + 'children': list([ + ]), + 'details': dict({ + 'need_path': 'IMPL_1', + 'schema_path': '[0] > local > required', + 'severity': 'violation', + 'user_msg': 'asil required for needs in index file', + 'validation_msg': '"asil" is a required property', + }), + 'log_lvl': 'error', + 'subtype': 'local_fail', + 'type': 'sn_schema_violation', + }), + ]), + }), + }) +# --- +# name: test_schemas[schema/fixtures/fields-docname_select_success] + '' +# --- +# name: test_schemas[schema/fixtures/fields-docname_select_success].1 + dict({ + 'validated_needs_count': 1, + 'validation_warnings': dict({ + }), + }) +# --- +# name: test_schemas[schema/fixtures/fields-docname_validate_error] + ''' + ERROR: Need 'IMPL_1' has schema violations: + Severity: violation + Field: docname + Need path: IMPL_1 + Schema path: [0] > local > properties > docname > pattern + User message: all needs must be in other file + Schema message: "index" does not match "other" [sn_schema_violation.local_fail] + + ''' +# --- +# name: test_schemas[schema/fixtures/fields-docname_validate_error].1 + dict({ + 'validated_needs_count': 1, + 'validation_warnings': dict({ + 'IMPL_1': list([ + dict({ + 'children': list([ + ]), + 'details': dict({ + 'field': 'docname', + 'need_path': 'IMPL_1', + 'schema_path': '[0] > local > properties > docname > pattern', + 'severity': 'violation', + 'user_msg': 'all needs must be in other file', + 'validation_msg': '"index" does not match "other"', + }), + 'log_lvl': 'error', + 'subtype': 'local_fail', + 'type': 'sn_schema_violation', + }), + ]), + }), + }) +# --- +# name: test_schemas[schema/fixtures/fields-docname_validate_success] + '' +# --- +# name: test_schemas[schema/fixtures/fields-docname_validate_success].1 + dict({ + 'validated_needs_count': 1, + 'validation_warnings': dict({ + }), + }) +# --- # name: test_schemas[schema/fixtures/fields-enum] '' # --- diff --git a/tests/schema/fixtures/fields.yml b/tests/schema/fixtures/fields.yml index f7234a243..e497909fd 100644 --- a/tests/schema/fixtures/fields.yml +++ b/tests/schema/fixtures/fields.yml @@ -794,3 +794,93 @@ multiple_errors_per_need: :id: IMPL_1 :priority: 8 :severity: critical + +docname_select_error: + conf: | + extensions = ["sphinx_needs"] + needs_from_toml = "ubproject.toml" + needs_schema_definitions_from_json = "schemas.json" + ubproject: | + [needs.fields.asil] + nullable = true + rst: | + .. impl:: title + :id: IMPL_1 + schemas: + $defs: [] + schemas: + - message: asil required for needs in index file + select: + properties: + docname: + pattern: "index" + required: ["docname"] + validate: + local: + required: ["asil"] + +docname_select_success: + conf: | + extensions = ["sphinx_needs"] + needs_from_toml = "ubproject.toml" + needs_schema_definitions_from_json = "schemas.json" + ubproject: | + [needs.fields.asil] + nullable = true + rst: | + .. impl:: title + :id: IMPL_1 + schemas: + $defs: [] + schemas: + - message: asil required for needs in other file + select: + properties: + docname: + pattern: "other" + required: ["docname"] + validate: + local: + required: ["asil"] + +docname_validate_error: + conf: | + extensions = ["sphinx_needs"] + needs_from_toml = "ubproject.toml" + needs_schema_definitions_from_json = "schemas.json" + ubproject: | + [needs.fields.asil] + nullable = true + rst: | + .. impl:: title + :id: IMPL_1 + schemas: + $defs: [] + schemas: + - message: all needs must be in other file + validate: + local: + properties: + docname: + pattern: "other" + +docname_validate_success: + conf: | + extensions = ["sphinx_needs"] + needs_from_toml = "ubproject.toml" + needs_schema_definitions_from_json = "schemas.json" + ubproject: | + [needs.fields.asil] + nullable = true + rst: | + .. impl:: title + :id: IMPL_1 + schemas: + $defs: [] + schemas: + - message: all needs must be in index file + validate: + local: + properties: + docname: + pattern: "index"