Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions extensions/vscode/src/api/types/configurations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import {
RConfig,
PythonConfig,
Configuration,
ContentType,
UpdateConfigWithDefaults,
UpdateAllConfigsWithDefaults,
isPythonContent,
isAPIContent,
isAppContent,
} from "./configurations";
import { InterpreterDefaults } from "./interpreters";
import {
Expand Down Expand Up @@ -98,6 +102,82 @@ describe("Configurations Types", () => {
);
});

describe("isPythonContent", () => {
test.each([
ContentType.JUPYTER_NOTEBOOK,
ContentType.JUPYTER_VOILA,
ContentType.PYTHON_BOKEH,
ContentType.PYTHON_DASH,
ContentType.PYTHON_FASTAPI,
ContentType.PYTHON_FLASK,
ContentType.PYTHON_GRADIO,
ContentType.PYTHON_PANEL,
ContentType.PYTHON_SHINY,
ContentType.PYTHON_STREAMLIT,
])("returns true for %s", (type) => {
expect(isPythonContent(type)).toBe(true);
});

test.each([
ContentType.HTML,
ContentType.QUARTO,
ContentType.QUARTO_STATIC,
ContentType.QUARTO_SHINY,
ContentType.R_PLUMBER,
ContentType.R_SHINY,
ContentType.RMD,
ContentType.RMD_SHINY,
ContentType.UNKNOWN,
])("returns false for %s", (type) => {
expect(isPythonContent(type)).toBe(false);
});
});

describe("isAPIContent", () => {
test.each([
ContentType.PYTHON_FLASK,
ContentType.PYTHON_FASTAPI,
ContentType.R_PLUMBER,
])("returns true for %s", (type) => {
expect(isAPIContent(type)).toBe(true);
});

test.each([
ContentType.HTML,
ContentType.PYTHON_SHINY,
ContentType.R_SHINY,
ContentType.QUARTO,
ContentType.UNKNOWN,
])("returns false for %s", (type) => {
expect(isAPIContent(type)).toBe(false);
});
});

describe("isAppContent", () => {
test.each([
ContentType.PYTHON_SHINY,
ContentType.R_SHINY,
ContentType.PYTHON_BOKEH,
ContentType.PYTHON_DASH,
ContentType.PYTHON_GRADIO,
ContentType.PYTHON_PANEL,
ContentType.PYTHON_STREAMLIT,
])("returns true for %s", (type) => {
expect(isAppContent(type)).toBe(true);
});

test.each([
ContentType.HTML,
ContentType.PYTHON_FLASK,
ContentType.PYTHON_FASTAPI,
ContentType.R_PLUMBER,
ContentType.QUARTO,
ContentType.UNKNOWN,
])("returns false for %s", (type) => {
expect(isAppContent(type)).toBe(false);
});
});

describe("UpdateAllConfigsWithDefaults", () => {
test("updates all configs passed to it", () => {
const multiConfigs: Configuration[] = [];
Expand Down
44 changes: 44 additions & 0 deletions extensions/vscode/src/api/types/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,50 @@ export const allValidContentTypes: ContentType[] = [
ContentType.RMD,
];

export function isPythonContent(type: ContentType): boolean {
switch (type) {
case ContentType.JUPYTER_NOTEBOOK:
case ContentType.JUPYTER_VOILA:
case ContentType.PYTHON_BOKEH:
case ContentType.PYTHON_DASH:
case ContentType.PYTHON_FASTAPI:
case ContentType.PYTHON_FLASK:
case ContentType.PYTHON_GRADIO:
case ContentType.PYTHON_PANEL:
case ContentType.PYTHON_SHINY:
case ContentType.PYTHON_STREAMLIT:
return true;
default:
return false;
}
}

export function isAPIContent(type: ContentType): boolean {
switch (type) {
case ContentType.PYTHON_FLASK:
case ContentType.PYTHON_FASTAPI:
case ContentType.R_PLUMBER:
return true;
default:
return false;
}
}

export function isAppContent(type: ContentType): boolean {
switch (type) {
case ContentType.PYTHON_SHINY:
case ContentType.R_SHINY:
case ContentType.PYTHON_BOKEH:
case ContentType.PYTHON_DASH:
case ContentType.PYTHON_GRADIO:
case ContentType.PYTHON_PANEL:
case ContentType.PYTHON_STREAMLIT:
return true;
default:
return false;
}
}

export const contentTypeStrings = {
[ContentType.HTML]: "serve pre-rendered HTML",
[ContentType.JUPYTER_NOTEBOOK]: "render with Jupyter nbconvert",
Expand Down
Loading