mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-28 23:43:53 +00:00
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:
parent
927069c12f
commit
3ab7a8da73
13 changed files with 921 additions and 20 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue