Skip to content

Invalid notebook in test expectation #157

Open
@krassowski

Description

@krassowski

Note: the underlying issue might be the cause of jupyter/notebook#6828.

The nb0.ipynb notebook used as an expectation in tests is invalid and does not even render on GitHub:

Screenshot from 2023-04-08 16-08-49

It is used in this test:

@pytest.mark.asyncio
@pytest.mark.parametrize("yjs_client", "0", indirect=True)
async def test_ypy_yjs_0(yws_server, yjs_client):
ydoc = Y.YDoc()
ynotebook = YNotebook(ydoc)
websocket = await connect("ws://localhost:1234/my-roomname")
WebsocketProvider(ydoc, websocket)
nb = stringify_source(json.loads((files_dir / "nb0.ipynb").read_text()))
ynotebook.source = nb
ytest = YTest(ydoc, 3.0)
await ytest.change()
assert ytest.source == nb

And contains two code cells with id set to null:

{
    "cells": [
        {
            "cell_type": "code",
            "source": [
                "print('Hello, World!')"
            ],
            "metadata": {},
            "outputs": [],
            "execution_count": null,
            "id": null
        },
        {
            "cell_type": "code",
            "source": "print('Hello, World!')",
            "metadata": {},
            "outputs": [],
            "execution_count": null,
            "id": null
        }
    ],
    "metadata": {
        "kernelspec": {
            "display_name": "Python 3 (ipykernel)",
            "language": "python",
            "name": "python3"
        },
        "language_info": {
            "codemirror_mode": {
                "name": "ipython",
                "version": 3
            },
            "file_extension": ".py",
            "mimetype": "text/x-python",
            "name": "python",
            "nbconvert_exporter": "python",
            "pygments_lexer": "ipython3",
            "version": "3.10.2"
        }
    },
    "nbformat": 4,
    "nbformat_minor": 5
}

While execution_count can be null, id cannot, compare specification:

Code cells are the primary content of Jupyter notebooks. They contain source code in the language of the document’s associated kernel, and a list of outputs associated with executing that code. They also have an execution_count, which must be an integer or null.

Since the 4.5 schema release, all cells have an id field which must be a string of length 1-64 with alphanumeric, -, and _ as legal characters to use. These ids must be unique to any given Notebook following the nbformat spec.

And schema:

"execution_count": {
  "description": "The code cell's prompt number. Will be null if the cell has not been run.",
  "type": ["integer", "null"],
  "minimum": 0
}
"definitions": {
    "cell_id": {
      "description": "A string field representing the identifier of this particular cell.",
      "type": "string",
      "pattern": "^[a-zA-Z0-9-_]+$",
      "minLength": 1,
      "maxLength": 64
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions