Skip to content

Commit

Permalink
#6774 - make e2e tests for jvm repr (#6849)
Browse files Browse the repository at this point in the history
* add kernel api tests

* #6774 clear notebook outputs

* rename test file
  • Loading branch information
wojciechowskim authored and scottdraves committed Feb 14, 2018
1 parent f0d1b76 commit a02538f
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 0 deletions.
135 changes: 135 additions & 0 deletions test/notebooks/groovy/KernelAPITest.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Load Magic Command"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%classpath add jar ../../../doc/resources/jar/loadMagicJarDemo.jar"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_magic com.twosigma.beakerx.custom.magic.command.ShowEnvsCustomMagicCommand"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%showEnvs"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Show Null Execution Result"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"com.twosigma.beakerx.kernel.Kernel.showNullExecutionResult"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"com.twosigma.beakerx.kernel.Kernel.showNullExecutionResult = true;\n",
"String seeNullString = null;\n",
"seeNullString"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"com.twosigma.beakerx.kernel.Kernel.showNullExecutionResult = false;\n",
"String noNullString = null;\n",
"noNullString"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# JVM Repr"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import jupyter.Displayer;\n",
"import jupyter.Displayers;\n",
"Displayers.register(Integer.class, new Displayer<Integer>() {\n",
" @Override\n",
" public Map<String, String> display(Integer value) {\n",
" return new HashMap<String, String>() {{\n",
" put(MIMEContainer.MIME.TEXT_HTML, \"<div><h1>\" + value + \"</h1></div>\");\n",
"\n",
" }};\n",
" }\n",
"});"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"1+1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Groovy",
"language": "groovy",
"name": "groovy"
},
"language_info": {
"codemirror_mode": "groovy",
"file_extension": ".groovy",
"mimetype": "",
"name": "Groovy",
"nbconverter_exporter": "",
"version": "2.4.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
108 changes: 108 additions & 0 deletions test/tests/groovy/kernelAPITest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright 2017 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var BeakerXPageObject = require('../beakerx.po.js');
var beakerxPO;

describe('(Groovy) Testing of Kernel API', function () {

beforeAll(function () {
beakerxPO = new BeakerXPageObject();
beakerxPO.runNotebookByUrl('/notebooks/test/notebooks/groovy/KernelAPITest.ipynb');
}, 2);

afterAll(function () {
beakerxPO.closeAndHaltNotebook();
});

var cellIndex;

describe('(Groovy) Adding jar file', function () {

var testValues = {
loadJarSuccess: 'Added jar: [loadMagicJarDemo.jar]',
magicCommandSuccess: 'Magic command %showEnvs was successfully added.',
envs: '{PATH='
};

it('Jar file is loaded correctly', function () {
cellIndex = 0;
var output = beakerxPO.runCellToGetOutputTextElement(cellIndex);
expect(output.isEnabled()).toBeTruthy();
expect(output.getText()).toBe(testValues.loadJarSuccess);
});

it('Magic command is added successfully', function () {
cellIndex += 1;
var output = beakerxPO.runCellToGetOutputTextElement(cellIndex);
expect(output.isEnabled()).toBeTruthy();
expect(output.getText()).toBe(testValues.magicCommandSuccess);
});

it('Envs are displayed correctly', function () {
cellIndex += 1;
var output = beakerxPO.runCellToGetOutputTextElement(cellIndex);
expect(output.isEnabled()).toBeTruthy();
expect(output.getText()).toContain(testValues.envs);
});
});

describe('(Groovy) Show null execution result as true', function() {
it('Cell displays true output', function () {
cellIndex += 1;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);

expect(codeCell.$('div.output_result').isEnabled()).toBeTruthy();
expect(codeCell.$('div.output_result').getText()).toBe('true');
});
});

describe('(Groovy) Show null execution result as null', function() {
it('Cell displays null output', function () {
cellIndex += 1;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);

expect(codeCell.$('div.output_result').isEnabled()).toBeTruthy();
expect(codeCell.$('div.output_result').getText()).toBe('null');
});
});

describe('(Groovy) Do not show null execution result', function() {
it('Cell displays no output', function () {
cellIndex += 1;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);

expect(codeCell.$('div.output').getText()).toBe('');
});
});

describe('(Groovy) Jvm Repr', function() {
it('Displayer is properly loaded', function() {
cellIndex += 1;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);

expect(codeCell.$('div.output').getText()).toBe('');
});

it('Cell displays proper output', function() {
cellIndex += 1;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);

expect(codeCell.$('div.output_result').getText()).toBe('2');

});
});
});

0 comments on commit a02538f

Please sign in to comment.