Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix running tests and lints in notebook for new pytest-html #275

Merged
merged 3 commits into from
Jun 1, 2024
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,6 @@ junit.xml
examples/_*
*_test.py
*_test.html

nbcelltests/labextension/*.tgz
nbcelltests/labextension
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Cell-by-cell testing for production Jupyter notebooks in JupyterLab

[![Build Status](https://github.com/jpmorganchase/nbcelltests/workflows/Build%20Status/badge.svg?branch=main)](https://github.com/jpmorganchase/nbcelltests/actions?query=workflow%3A%22Build+Status%22)
[![Build Status](https://github.com/jpmorganchase/nbcelltests/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/jpmorganchase/nbcelltests/actions?query=workflow%3A%22Build+Status%22)
[![codecov](https://codecov.io/gh/jpmorganchase/nbcelltests/branch/main/graph/badge.svg)](https://codecov.io/gh/jpmorganchase/nbcelltests)
[![PyPI](https://img.shields.io/pypi/l/nbcelltests.svg)](https://pypi.python.org/pypi/nbcelltests)
[![PyPI](https://img.shields.io/pypi/v/nbcelltests.svg)](https://pypi.python.org/pypi/nbcelltests)
Expand Down
71 changes: 21 additions & 50 deletions examples/Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"metadata": {},
"source": [
"# Test1"
]
Expand All @@ -17,32 +11,29 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {
"celltests": [
"# Use %cell to mark where the cell should be inserted, or add a line comment \"# no %cell\" to deliberately skip the cell\n",
"%cell\n",
"tests": [
"from mock import patch\n",
"import pandas as pd\n",
"with patch('superstore.getTimeSeries') as mock:\n",
" mock.return_value = pd.DataFrame([{'1': 1, '2': 2}])\n",
" %cell\n",
"\n"
],
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
]
},
"outputs": [],
"source": [
"import cufflinks as cf\n",
"df = cf.datagen.lines()"
"from superstore import getTimeSeries\n",
"df = getTimeSeries()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
"tests": [
"%cell\n",
"assert df.equals(pd.DataFrame([{'1': 1, '2': 2}]))\n"
]
},
"outputs": [
{
Expand Down Expand Up @@ -139,13 +130,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"df['date'] = df.index"
Expand All @@ -155,11 +140,10 @@
"cell_type": "code",
"execution_count": 4,
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
"tests": [
"with patch('pandas.DataFrame.head') as mock:\n",
" %cell\n"
]
},
"outputs": [
{
Expand Down Expand Up @@ -269,29 +253,16 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"\n",
"test3"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"metadata": {},
"outputs": [
{
"ename": "KeyboardInterrupt",
Expand Down
29 changes: 18 additions & 11 deletions js/src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,27 @@ export async function runCellTests(app, docManager) {
}

const settings = ServerConnection.makeSettings();
const res = await ServerConnection.makeRequest(`${settings.baseUrl}celltests/test/run`, {method: "post", body: {path, model}}, settings);
const res = await ServerConnection.makeRequest(`${settings.baseUrl}celltests/test/run`, {method: "post", body: JSON.stringify({path, model})}, settings);

if (res.ok) {
const div = document.createElement("div");
div.innerHTML = (await res.json()).test;
const body = new Widget({node: div});
const iframe = document.createElement("iframe");
const html_data = (await res.json()).test;
iframe.onload = () => {
// write iframe content
iframe.contentWindow.document.write(html_data);
};
const body = new Widget({node: iframe});

const dialog = new Dialog({
body,
buttons: [Dialog.okButton({label: "Ok"})],
title: "Tests run!",
});
dialog.node.lastChild.style.maxHeight = "750px";
dialog.node.lastChild.style.maxWidth = "800px";
dialog.node.lastChild.style.width = "800px";

dialog.node.lastChild.style.maxHeight = "1600px";
dialog.node.lastChild.style.maxWidth = "2000px";
dialog.node.lastChild.style.width = "900px";
dialog.node.lastChild.style.height = "900px";

await dialog.launch();
} else {
Expand Down Expand Up @@ -72,7 +78,7 @@ export async function runCellLints(app, docManager) {
}

const settings = ServerConnection.makeSettings();
const res = await ServerConnection.makeRequest(`${settings.baseUrl}celltests/lint/run`, {method: "post", body: {path, model}}, settings);
const res = await ServerConnection.makeRequest(`${settings.baseUrl}celltests/lint/run`, {method: "post", body: JSON.stringify({path, model})}, settings);

if (res.ok) {
const div = document.createElement("div");
Expand All @@ -85,9 +91,10 @@ export async function runCellLints(app, docManager) {
title: "Lints run!",
});

dialog.node.lastChild.style.maxHeight = "750px";
dialog.node.lastChild.style.maxWidth = "500px";
dialog.node.lastChild.style.width = "500px";
dialog.node.lastChild.style.maxHeight = "1600px";
dialog.node.lastChild.style.maxWidth = "2000px";
dialog.node.lastChild.style.width = "600px";
dialog.node.lastChild.style.height = "800px";

await dialog.launch();
} else {
Expand Down
1 change: 0 additions & 1 deletion js/src/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class ControlsWidget extends BoxPanel {

this.svg = document.createElement("svg");
this.svg.innerHTML = circleSvg;
console.log("check this");
this.svg = this.svg.firstChild;

const div1 = document.createElement("div");
Expand Down
3 changes: 2 additions & 1 deletion js/style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ div.CelltestsControls > div > div {
div.CelltestsControls > div > button {
width: 50%;
}

div.CelltestsControls > div > button:hover {
background: var(--jp-layout-color2);
background: var(--jp-layout-color3);
}

div.CelltestsRules > div {
Expand Down
93 changes: 0 additions & 93 deletions nbcelltests/labextension/package.json

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions nbcelltests/labextension/static/style.js

This file was deleted.

16 changes: 0 additions & 16 deletions nbcelltests/labextension/static/third-party-licenses.json

This file was deleted.

Loading