Skip to content

Commit

Permalink
Add a new test on R Markdown tags and options (#869)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts authored Oct 14, 2021
1 parent 186d822 commit a9991d8
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/test_read_simple_rmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from time import sleep

import nbformat
import pytest
Expand Down Expand Up @@ -198,3 +199,36 @@ def test_root_level_metadata_as_raw_cell(
# Writing back to Rmd should preserve the original document
jupytext_cli([str(nb_file), "--to", "Rmd"])
compare(rmd_file.read(), rmd)


def test_pair_rmd_file_with_cell_tags_and_options(
tmpdir, cwd_tmpdir, no_jupytext_version_number
):
rmd = """```{r plot_1, dpi=72}
plot(3:30)
```
"""
rmd_file = tmpdir.join("test.Rmd")
rmd_file.write(rmd)

# Pair Rmd with ipynb
jupytext_cli(["--set-formats", "ipynb,Rmd", "test.Rmd"])

# Wait so that ipynb will be more recent
sleep(0.2)

# Modify the ipynb file
nb_file = tmpdir.join("test.ipynb")
nb = nbformat.read(nb_file, as_version=4)
nb.cells[0].source = "plot(4:40)"
nb_file.write(nbformat.writes(nb))

# Sync the two files
jupytext_cli(["--sync", "test.Rmd"])

# Remove the header
rmd2 = rmd_file.read()
rmd2 = rmd2.rsplit("---\n\n")[1]

# The new code chunk has the new code, and options are still there
compare(rmd2, rmd.replace("3", "4"))

0 comments on commit a9991d8

Please sign in to comment.