Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Jul 31, 2023
1 parent 7e9b450 commit 6f075eb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
24 changes: 16 additions & 8 deletions myst_nb/core/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,11 @@ def _flush_markdown(start_line, token, md_metadata):
meta = nbf.from_dict(md_metadata)
if md_source:
source_map.append(start_line)
notebook.cells.append(
nbf_version.new_markdown_cell(source=md_source, metadata=meta)
)
cell = nbf_version.new_markdown_cell(source=md_source, metadata=meta)
# remove randomly generated cell IDs
if "id" in cell:
del cell["id"]
notebook.cells.append(cell)

# iterate through the tokens to identify notebook cells
nesting_level = 0
Expand All @@ -260,9 +262,13 @@ def _flush_markdown(start_line, token, md_metadata):
)
meta = nbf.from_dict(options)
source_map.append(token_map[0] + 1)
notebook.cells.append(
nbf_version.new_code_cell(source="\n".join(body_lines), metadata=meta)
cell = nbf_version.new_code_cell(
source="\n".join(body_lines), metadata=meta
)
# remove randomly generated cell IDs
if "id" in cell:
del cell["id"]
notebook.cells.append(cell)
md_metadata = {}
md_start_line = token_map[1]

Expand All @@ -271,9 +277,11 @@ def _flush_markdown(start_line, token, md_metadata):
options, body_lines = _read_fenced_cell(token, len(notebook.cells), "Raw")
meta = nbf.from_dict(options)
source_map.append(token_map[0] + 1)
notebook.cells.append(
nbf_version.new_raw_cell(source="\n".join(body_lines), metadata=meta)
)
cell = nbf_version.new_raw_cell(source="\n".join(body_lines), metadata=meta)
# remove randomly generated cell IDs
if "id" in cell:
del cell["id"]
notebook.cells.append(cell)
md_metadata = {}
md_start_line = token_map[1]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_execute/test_custom_convert_auto.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<literal_block language="ipython3" xml:space="preserve">
import pandas as pd
x = pd.Series({'A':1, 'B':3, 'C':2})
<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">
<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">
<container classes="cell_output" nb_element="cell_code_output">
<container nb_element="mime_bundle">
<container mime_type="text/plain">
Expand Down
4 changes: 2 additions & 2 deletions tests/test_execute/test_custom_convert_cache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<section ids="custom-formats" names="custom\ formats">
<title>
Custom Formats
<container cell_index="2" cell_metadata="{'echo': True}" classes="cell" exec_count="1" nb_element="cell_code">
<container cell_index="2" cell_metadata="{'echo': True}" classes="cell" exec_count="1" ids="id1" nb_element="cell_code" slug="cell-id=73ee1a6a">
<container classes="cell_input" nb_element="cell_code_source">
<literal_block language="ipython3" xml:space="preserve">
import pandas as pd
x = pd.Series({'A':1, 'B':3, 'C':2})
<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">
<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">
<container classes="cell_output" nb_element="cell_code_output">
<container nb_element="mime_bundle">
<container mime_type="text/plain">
Expand Down

0 comments on commit 6f075eb

Please sign in to comment.