Test that multiple MIME types create a single display_data output, not multiple.
()
| 1115 | |
| 1116 | |
| 1117 | def test_notebook_export_single_display(): |
| 1118 | """Test that multiple MIME types create a single display_data output, not multiple.""" |
| 1119 | pytest.importorskip("nbformat") |
| 1120 | |
| 1121 | _ip = get_ipython() |
| 1122 | orig_outputs = _ip.history_manager.outputs.copy() |
| 1123 | orig_execution_count = _ip.execution_count |
| 1124 | _ip.history_manager.reset() |
| 1125 | |
| 1126 | try: |
| 1127 | execution_count = _ip.execution_count = 1 |
| 1128 | _ip.run_cell("'test'", store_history=True, silent=False) |
| 1129 | |
| 1130 | # Mock display output with multiple MIME types |
| 1131 | test_display_history = HistoryOutput( |
| 1132 | output_type="display_data", |
| 1133 | bundle={"text/plain": "test", "text/html": "<div>test</div>"}, |
| 1134 | ) |
| 1135 | _ip.history_manager.outputs[execution_count] = [test_display_history] |
| 1136 | |
| 1137 | with TemporaryDirectory() as td: |
| 1138 | outfile = f"{td}/test.ipynb" |
| 1139 | _ip.run_cell(f"%notebook {outfile}", store_history=True, silent=False) |
| 1140 | |
| 1141 | # Verify single display_data output with both MIME types |
| 1142 | with open(outfile, "r") as f: |
| 1143 | nb = json.load(f) |
| 1144 | |
| 1145 | cell = nb["cells"][0] |
| 1146 | display_outputs = [ |
| 1147 | out for out in cell["outputs"] if out["output_type"] == "display_data" |
| 1148 | ] |
| 1149 | |
| 1150 | assert ( |
| 1151 | len(display_outputs) == 1 |
| 1152 | ), f"Expected 1 display_data output, got {len(display_outputs)}" |
| 1153 | |
| 1154 | output_data = display_outputs[0]["data"] |
| 1155 | assert set(output_data.keys()) == {"text/plain", "text/html"} |
| 1156 | assert output_data["text/plain"] == ["test"] |
| 1157 | assert output_data["text/html"] == ["<div>test</div>"] |
| 1158 | |
| 1159 | finally: |
| 1160 | _ip.history_manager.outputs = orig_outputs |
| 1161 | _ip.execution_count = orig_execution_count |
| 1162 | |
| 1163 | |
| 1164 | class TestEnv(TestCase): |
nothing calls this directly
no test coverage detected
searching dependent graphs…