예제 #1
0
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", {})
예제 #2
0
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"
예제 #3
0
def test_script_with_spyder_cell_with_name_is_percent(script="""#%% cell name
1 + 2"""):
    assert guess_format(script, '.py') == 'percent'
예제 #4
0
def test_script_with_percent_cell_and_magic_is_hydrogen(
        script="""#%%
%matplotlib inline
"""):
    assert guess_format(script, '.py') == 'hydrogen'
예제 #5
0
def test_script_with_magics_not_percent(script="""# %%time
1 + 2"""):
    assert guess_format(script, '.py') == 'light'
예제 #6
0
def test_guess_format_sphinx(nb_file):
    with open(nb_file) as stream:
        assert guess_format(stream.read(), ext='.py') == 'sphinx'
예제 #7
0
def test_guess_format_percent(nb_file):
    with open(nb_file) as stream:
        assert guess_format(stream.read(), ext='.py') == 'percent'
예제 #8
0
def test_guess_format_light(nb_file):
    with open(nb_file) as stream:
        assert guess_format(stream.read(), ext='.py') == 'light'
예제 #9
0
def test_script_with_spyder_cell_is_percent(script="""#%%
1 + 2"""):
    assert guess_format(script, '.py')[0] == 'percent'
예제 #10
0
def test_script_with_percent_cell_and_magic_is_hydrogen(
    script="""#%%
%matplotlib inline
""", ):
    assert guess_format(script, ".py")[0] == "hydrogen"
예제 #11
0
def test_script_with_spyder_cell_is_percent(script="""#%%
1 + 2""", ):
    assert guess_format(script, ".py")[0] == "percent"
예제 #12
0
def test_script_with_magics_not_percent(script="""# %%time
1 + 2""", ):
    assert guess_format(script, ".py")[0] == "light"
예제 #13
0
def test_guess_format_hydrogen():
    text = """# %%
cat hello.txt
"""
    assert guess_format(text, ext=".py")[0] == "hydrogen"
예제 #14
0
def test_guess_format_sphinx(nb_file):
    with open(nb_file) as stream:
        assert guess_format(stream.read(), ext=".py")[0] == "sphinx"
예제 #15
0
def test_guess_format_percent(nb_file):
    with open(nb_file) as stream:
        assert guess_format(stream.read(), ext=".py")[0] == "percent"
예제 #16
0
def test_guess_format_hydrogen():
    text = """# %%
cat hello.txt
"""
    assert guess_format(text, ext='.py')[0] == 'hydrogen'