@@ -56,6 +56,120 @@ def doctree(
56
56
shutil .rmtree (tree )
57
57
58
58
59
+ def test_basic (doctree ):
60
+ source = """
61
+ .. jupyter-execute::
62
+
63
+ 2 + 2
64
+ """
65
+ tree = doctree (source )
66
+ (cell ,) = tree .traverse (JupyterCellNode )
67
+ assert cell .attributes ["code_below" ] is False
68
+ assert cell .attributes ["hide_code" ] is False
69
+ assert cell .attributes ["hide_output" ] is False
70
+ assert cell .attributes ["linenos" ] is False
71
+ assert cell .children [0 ].rawsource .strip () == "2 + 2"
72
+ assert cell .children [1 ].rawsource .strip () == "4"
73
+
74
+
75
+ def test_basic_old_entrypoint (doctree ):
76
+ source = """
77
+ .. jupyter-execute::
78
+
79
+ 2 + 2
80
+ """
81
+ tree = doctree (source , entrypoint = "jupyter_sphinx.execute" )
82
+ (cell ,) = tree .traverse (JupyterCellNode )
83
+ assert cell .attributes ["code_below" ] is False
84
+ assert cell .attributes ["hide_code" ] is False
85
+ assert cell .attributes ["hide_output" ] is False
86
+ assert cell .attributes ["linenos" ] is False
87
+ assert cell .children [0 ].rawsource .strip () == "2 + 2"
88
+ assert cell .children [1 ].rawsource .strip () == "4"
89
+
90
+
91
+ def test_hide_output (doctree ):
92
+ source = """
93
+ .. jupyter-execute::
94
+ :hide-output:
95
+
96
+ 2 + 2
97
+ """
98
+ tree = doctree (source )
99
+ (cell ,) = tree .traverse (JupyterCellNode )
100
+ assert cell .attributes ["hide_output" ] is True
101
+ assert len (cell .children ) == 1
102
+ assert cell .children [0 ].rawsource .strip () == "2 + 2"
103
+
104
+
105
+ def test_hide_code (doctree ):
106
+ source = """
107
+ .. jupyter-execute::
108
+ :hide-code:
109
+
110
+ 2 + 2
111
+ """
112
+ tree = doctree (source )
113
+ (cell ,) = tree .traverse (JupyterCellNode )
114
+ assert cell .attributes ["hide_code" ] is True
115
+ assert len (cell .children ) == 1
116
+ assert cell .children [0 ].rawsource .strip () == "4"
117
+
118
+
119
+ def test_code_below (doctree ):
120
+ source = """
121
+ .. jupyter-execute::
122
+ :code-below:
123
+
124
+ 2 + 2
125
+ """
126
+ tree = doctree (source )
127
+ (cell ,) = tree .traverse (JupyterCellNode )
128
+ assert cell .attributes ["code_below" ] is True
129
+ assert cell .children [0 ].rawsource .strip () == "4"
130
+ assert cell .children [1 ].rawsource .strip () == "2 + 2"
131
+
132
+
133
+ def test_linenos (doctree ):
134
+ source = """
135
+ .. jupyter-execute::
136
+ :linenos:
137
+
138
+ 2 + 2
139
+ """
140
+ tree = doctree (source )
141
+ (cell ,) = tree .traverse (JupyterCellNode )
142
+ assert cell .attributes ["linenos" ] is True
143
+ assert len (cell .children ) == 2
144
+ assert cell .children [0 ].rawsource .strip () == "2 + 2"
145
+ assert cell .children [1 ].rawsource .strip () == "4"
146
+ source = """
147
+ .. jupyter-execute::
148
+ :linenos:
149
+ :code-below:
150
+
151
+ 2 + 2
152
+ """
153
+ tree = doctree (source )
154
+ (cell ,) = tree .traverse (JupyterCellNode )
155
+ assert len (cell .children ) == 2
156
+ assert cell .attributes ["linenos" ] is True
157
+
158
+
159
+ def test_linenos_conf_option (doctree ):
160
+ source = """
161
+ .. jupyter-execute::
162
+
163
+ 2 + 2
164
+ """
165
+ tree = doctree (source , config = "jupyter_sphinx_linenos = True" )
166
+ (cell ,) = tree .traverse (JupyterCellNode )
167
+ assert cell .children [0 ].attributes ["linenos" ]
168
+ assert "highlight_args" not in cell .children [0 ].attributes
169
+ assert cell .children [0 ].rawsource .strip () == "2 + 2"
170
+ assert cell .children [1 ].rawsource .strip () == "4"
171
+
172
+
59
173
def test_continue_linenos_conf_option (doctree ):
60
174
# Test no linenumbering without linenos config or lineno-start directive
61
175
source = """
@@ -71,7 +185,7 @@ def test_continue_linenos_conf_option(doctree):
71
185
assert cell .children [0 ].rawsource .strip () == "2 + 2"
72
186
assert cell .children [1 ].rawsource .strip () == "4"
73
187
74
- # Test continuous line numbeirng
188
+ # Test continuous line numbering
75
189
source = """
76
190
.. jupyter-execute::
77
191
@@ -100,6 +214,7 @@ def test_continue_linenos_conf_option(doctree):
100
214
assert cell1 .children [1 ].rawsource .strip () == "6"
101
215
102
216
# Line number should continue after lineno-start option
217
+
103
218
source = """
104
219
.. jupyter-execute::
105
220
:lineno-start: 7
0 commit comments