From 593bcef515bf9e40a9a6c21d9327f497697d6969 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sun, 7 Mar 2021 20:27:24 +0100 Subject: [PATCH] Use non-random cell ids in tests (#751) * Use non-random cell ids in tests * Update CHANGELOG.md --- docs/CHANGELOG.md | 3 ++- tests/conftest.py | 15 +++++++++++++++ tests/test_cell_id.py | 10 ++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/test_cell_id.py diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6b5745896..91efed852 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,7 +5,8 @@ Jupytext ChangeLog ------------------- **Fixed** -- We have updated `marked`, an indirect dependency of the `jupyterlab-jupytext` extension, to fix a moderate vulnerability (#750). +- We have updated `marked`, an indirect dependency of the `jupyterlab-jupytext` extension, to fix a moderate vulnerability ([#750](https://github.com/mwouts/jupytext/issues/750)). +- We use non-random cell ids in the tests to avoid test failures due to duplicate cell ids ([#747](https://github.com/mwouts/jupytext/issues/747)) 1.10.2 (2021-02-17) diff --git a/tests/conftest.py b/tests/conftest.py index f9a36d895..d35315e15 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,6 +3,7 @@ import pytest from git import Repo +from nbformat.v4 import nbbase from nbformat.v4.nbbase import ( new_code_cell, new_markdown_cell, @@ -90,3 +91,17 @@ def notebook_with_outputs(): } }, ) + + +"""To make sure that cell ids are distinct we use a global counter. + This solves https://github.com/mwouts/jupytext/issues/747""" +global_cell_count = 0 + + +def generate_corpus_id(): + global global_cell_count + global_cell_count += 1 + return f"cell-{global_cell_count}" + + +nbbase.random_cell_id = generate_corpus_id diff --git a/tests/test_cell_id.py b/tests/test_cell_id.py new file mode 100644 index 000000000..4d65e3a83 --- /dev/null +++ b/tests/test_cell_id.py @@ -0,0 +1,10 @@ +from nbformat.v4.nbbase import new_code_cell + + +def test_cell_id_is_not_random(): + id1 = new_code_cell().id + id2 = new_code_cell().id + + n1 = int(id1.split("-")[1]) + n2 = int(id2.split("-")[1]) + assert n2 == n1 + 1