Add Jupyter Notebook document change snapshot test (#11944)

## Summary

Closes #11914.

This PR introduces a snapshot test that replays the LSP requests made
during a document formatting request, and confirms that the notebook
document is updated in the expected way.
This commit is contained in:
Jane Lewis 2024-06-20 22:29:27 -07:00 committed by GitHub
parent 927069c12f
commit 3ab7a8da73
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 921 additions and 20 deletions

View file

@ -31,6 +31,18 @@ impl Cell {
}
}
pub fn is_code_cell(&self) -> bool {
matches!(self, Cell::Code(_))
}
pub fn metadata(&self) -> &serde_json::Value {
match self {
Cell::Code(cell) => &cell.metadata,
Cell::Markdown(cell) => &cell.metadata,
Cell::Raw(cell) => &cell.metadata,
}
}
/// Update the [`SourceValue`] of the cell.
pub(crate) fn set_source(&mut self, source: SourceValue) {
match self {

View file

@ -19,6 +19,7 @@ use ruff_text_size::TextSize;
use crate::cell::CellOffsets;
use crate::index::NotebookIndex;
use crate::schema::{Cell, RawNotebook, SortAlphabetically, SourceValue};
use crate::RawNotebookMetadata;
/// Run round-trip source code generation on a given Jupyter notebook file path.
pub fn round_trip(path: &Path) -> anyhow::Result<String> {
@ -383,6 +384,10 @@ impl Notebook {
&self.raw.cells
}
pub fn metadata(&self) -> &RawNotebookMetadata {
&self.raw.metadata
}
/// Return `true` if the notebook is a Python notebook, `false` otherwise.
pub fn is_python_notebook(&self) -> bool {
self.raw