Skip to content

Commit 6f075eb

Browse files
committed
Fix tests
1 parent 7e9b450 commit 6f075eb

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

myst_nb/core/read.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,11 @@ def _flush_markdown(start_line, token, md_metadata):
233233
meta = nbf.from_dict(md_metadata)
234234
if md_source:
235235
source_map.append(start_line)
236-
notebook.cells.append(
237-
nbf_version.new_markdown_cell(source=md_source, metadata=meta)
238-
)
236+
cell = nbf_version.new_markdown_cell(source=md_source, metadata=meta)
237+
# remove randomly generated cell IDs
238+
if "id" in cell:
239+
del cell["id"]
240+
notebook.cells.append(cell)
239241

240242
# iterate through the tokens to identify notebook cells
241243
nesting_level = 0
@@ -260,9 +262,13 @@ def _flush_markdown(start_line, token, md_metadata):
260262
)
261263
meta = nbf.from_dict(options)
262264
source_map.append(token_map[0] + 1)
263-
notebook.cells.append(
264-
nbf_version.new_code_cell(source="\n".join(body_lines), metadata=meta)
265+
cell = nbf_version.new_code_cell(
266+
source="\n".join(body_lines), metadata=meta
265267
)
268+
# remove randomly generated cell IDs
269+
if "id" in cell:
270+
del cell["id"]
271+
notebook.cells.append(cell)
266272
md_metadata = {}
267273
md_start_line = token_map[1]
268274

@@ -271,9 +277,11 @@ def _flush_markdown(start_line, token, md_metadata):
271277
options, body_lines = _read_fenced_cell(token, len(notebook.cells), "Raw")
272278
meta = nbf.from_dict(options)
273279
source_map.append(token_map[0] + 1)
274-
notebook.cells.append(
275-
nbf_version.new_raw_cell(source="\n".join(body_lines), metadata=meta)
276-
)
280+
cell = nbf_version.new_raw_cell(source="\n".join(body_lines), metadata=meta)
281+
# remove randomly generated cell IDs
282+
if "id" in cell:
283+
del cell["id"]
284+
notebook.cells.append(cell)
277285
md_metadata = {}
278286
md_start_line = token_map[1]
279287

tests/test_execute/test_custom_convert_auto.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<literal_block language="ipython3" xml:space="preserve">
88
import pandas as pd
99
x = pd.Series({'A':1, 'B':3, 'C':2})
10-
<container cell_index="3" cell_metadata="{'name': 'bar_plot', 'tags': ['remove_input'], 'fig.height': 5, 'fig.width': 8}" classes="cell tag_remove_input" exec_count="2" nb_element="cell_code">
10+
<container cell_index="3" cell_metadata="{'name': 'bar_plot', 'tags': ['remove_input'], 'fig.height': 5, 'fig.width': 8}" classes="cell tag_remove_input" exec_count="2" ids="id2" nb_element="cell_code" slug="cell-id=2ed7deb2">
1111
<container classes="cell_output" nb_element="cell_code_output">
1212
<container nb_element="mime_bundle">
1313
<container mime_type="text/plain">

tests/test_execute/test_custom_convert_cache.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<section ids="custom-formats" names="custom\ formats">
33
<title>
44
Custom Formats
5-
<container cell_index="2" cell_metadata="{'echo': True}" classes="cell" exec_count="1" nb_element="cell_code">
5+
<container cell_index="2" cell_metadata="{'echo': True}" classes="cell" exec_count="1" ids="id1" nb_element="cell_code" slug="cell-id=73ee1a6a">
66
<container classes="cell_input" nb_element="cell_code_source">
77
<literal_block language="ipython3" xml:space="preserve">
88
import pandas as pd
99
x = pd.Series({'A':1, 'B':3, 'C':2})
10-
<container cell_index="3" cell_metadata="{'name': 'bar_plot', 'tags': ['remove_input'], 'fig.height': 5, 'fig.width': 8}" classes="cell tag_remove_input" exec_count="2" nb_element="cell_code">
10+
<container cell_index="3" cell_metadata="{'name': 'bar_plot', 'tags': ['remove_input'], 'fig.height': 5, 'fig.width': 8}" classes="cell tag_remove_input" exec_count="2" ids="id2" nb_element="cell_code" slug="cell-id=3aee4e49">
1111
<container classes="cell_output" nb_element="cell_code_output">
1212
<container nb_element="mime_bundle">
1313
<container mime_type="text/plain">

0 commit comments

Comments
 (0)