def test_matches_mystnb(): assert matches_mystnb("") is False assert matches_mystnb("```{code-cell}\n```") is False assert matches_mystnb("---\njupytext: true\n---") is False for ext in myst_extensions(no_md=True): assert matches_mystnb("", ext=ext) is True text = dedent("""\ --- {{a --- ```{code-cell} :b: {{c ``` """) assert matches_mystnb(text) is True text = dedent("""\ --- jupytext: text_representation: format_name: myst extension: .md --- """) assert matches_mystnb(text) is True text = dedent("""\ --- a: 1 --- > ```{code-cell} ``` """) assert matches_mystnb(text) is True assert guess_format(text, ".md") == ("myst", {})
def test_script_with_percent_cell_and_kernelspec(script="""# --- # jupyter: # kernelspec: # display_name: Python3 # language: python # name: python3 # --- # %% a = 1 """, ): assert guess_format(script, ".py")[0] == "percent"
def test_script_with_spyder_cell_with_name_is_percent(script="""#%% cell name 1 + 2"""): assert guess_format(script, '.py') == 'percent'
def test_script_with_percent_cell_and_magic_is_hydrogen( script="""#%% %matplotlib inline """): assert guess_format(script, '.py') == 'hydrogen'
def test_script_with_magics_not_percent(script="""# %%time 1 + 2"""): assert guess_format(script, '.py') == 'light'
def test_guess_format_sphinx(nb_file): with open(nb_file) as stream: assert guess_format(stream.read(), ext='.py') == 'sphinx'
def test_guess_format_percent(nb_file): with open(nb_file) as stream: assert guess_format(stream.read(), ext='.py') == 'percent'
def test_guess_format_light(nb_file): with open(nb_file) as stream: assert guess_format(stream.read(), ext='.py') == 'light'
def test_script_with_spyder_cell_is_percent(script="""#%% 1 + 2"""): assert guess_format(script, '.py')[0] == 'percent'
def test_script_with_percent_cell_and_magic_is_hydrogen( script="""#%% %matplotlib inline """, ): assert guess_format(script, ".py")[0] == "hydrogen"
def test_script_with_spyder_cell_is_percent(script="""#%% 1 + 2""", ): assert guess_format(script, ".py")[0] == "percent"
def test_script_with_magics_not_percent(script="""# %%time 1 + 2""", ): assert guess_format(script, ".py")[0] == "light"
def test_guess_format_hydrogen(): text = """# %% cat hello.txt """ assert guess_format(text, ext=".py")[0] == "hydrogen"
def test_guess_format_sphinx(nb_file): with open(nb_file) as stream: assert guess_format(stream.read(), ext=".py")[0] == "sphinx"
def test_guess_format_percent(nb_file): with open(nb_file) as stream: assert guess_format(stream.read(), ext=".py")[0] == "percent"
def test_guess_format_hydrogen(): text = """# %% cat hello.txt """ assert guess_format(text, ext='.py')[0] == 'hydrogen'