Skip to content

Commit

Permalink
Use non-random cell ids in tests (#751)
Browse files Browse the repository at this point in the history
* Use non-random cell ids in tests

* Update CHANGELOG.md
  • Loading branch information
mwouts authored Mar 7, 2021
1 parent 58e8b27 commit 593bcef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
10 changes: 10 additions & 0 deletions tests/test_cell_id.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 593bcef

Please sign in to comment.