Skip to content

Commit

Permalink
Use non-random cell ids in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Mar 5, 2021
1 parent 508be51 commit 550b490
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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 550b490

Please sign in to comment.