json-schema-org / json-schema-org/JSON-Schema-Test-Suite

Revamped output testing

Open
#657 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement missing test
Dominant language
Python
Stars
750
Forks
307
Avg merge
3d 17h
Merged PRs (30d)
24

Description

Following up on #247 and in light of @jdesrosiers' #652, I think we can do better for output tests.

The current test structure presents a JSON Schema that constrains several locations to specific values.

Example:
https://github.com/json-schema-org/JSON-Schema-Test-Suite/blob/19947eaa1289168a49edd21bb7a8aa2098069ae0/output-tests/draft2020-12/content/readOnly.json#L13-L33

However, maybe a simpler approach (both to implement and write) would be just to have a series of JSON Pointers and the values that are expected to be in the output at those locations. For example, the above test file could be re-written as:

[
    {
        "description": "readOnly generates its value as an annotation",
        "schema": {
            "$schema": "https://json-schema.org/draft/2020-12/schema",
            "$id": "https://json-schema.org/tests/content/draft2020-12/readOnly/0",
            "readOnly": true
        },
        "tests": [
            {
                "description": "readOnly is true",
                "data": 1,
                "output": {
                    "basic": {
                        "/annotations/0/keywordLocation": "/readOnly",
                        "/annotations/0/absoluteKeywordLocation": "https://json-schema.org/tests/content/draft2020-12/readOnly/0#/readOnly",
                        "/annotations/0/instanceLocation": "",
                        "/annotations/0/annotation": true
                    }
                }
            }
        ]
    }
]

As long as all of those locations in the output contain those values, it is considered valid.

There is one caveat that the current version of the test also enforces that the the errors property is disallowed when annotations is present, which is something that the spec requires, but the proposal can't cover that case. I'm open to options here if that's important to us.

Edit: I've since realized that the pointers need indices because annotations is an array. I'm not sure if we can specify that the first one needs to be a particular value. Items in the array could be in any order. Maybe the tests could be engineered so that it's the only expected item?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with output-tests/draft2020-12/content/readOnly.json and compare it with the proposed JSON Pointer structure, then review the constraints discussed in issues #247 and #652. Define how array ordering and the errors/annotations rule should be represented; the work is done when the output-test format can express the required assertions without losing those constraints.

Written by the indexing model from the issue text.

Assessment

Tech stack
json
Domain
testing
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.