Skip to content

Commit f39071a

Browse files
committed
test: draft for testign document formatting with Python code blocks
1 parent a7cee84 commit f39071a

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Formatting Python Code Cells
3+
format: html
4+
---
5+
6+
```{python}
7+
#| label: my-code
8+
1 + 1
9+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Formatting Python Code Cells
3+
format: html
4+
---
5+
6+
```{python}
7+
#| label: my-code
8+
1+1
9+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import * as vscode from "vscode";
2+
import * as assert from "assert";
3+
import * as path from "path";
4+
import { openAndShowTextDocument, wait, WORKSPACE_PATH } from "./test-utils";
5+
6+
suite("Code Block Formatting", function () {
7+
test("Format Python code block", async function () {
8+
// Ensure Black formatter extension is installed
9+
await vscode.commands.executeCommand("workbench.extensions.installExtension", "ms-python.black-formatter");
10+
await wait(1000);
11+
12+
const { doc, editor } = await openAndShowTextDocument("format-python.qmd");
13+
14+
// const position = new vscode.Position(7, 2); // Line with "1+1"
15+
// editor.selection = new vscode.Selection(position, position);
16+
// await vscode.commands.executeCommand("quarto.formatCell");
17+
await vscode.commands.executeCommand("vscode.executeFormatDocumentProvider", doc.uri);
18+
19+
await wait(500);
20+
21+
const formattedText = doc.getText();
22+
23+
const expectedDoc = await vscode.workspace.openTextDocument(
24+
vscode.Uri.file(path.join(WORKSPACE_PATH, "format-python-expected.qmd"))
25+
);
26+
const expected = expectedDoc.getText();
27+
28+
assert.strictEqual(formattedText, expected, "Python code cell options should not be altered after formatting");
29+
});
30+
});

0 commit comments

Comments
 (0)