Skip to content

Commit 3c8fa11

Browse files
committed
Test the template in CI
1 parent c79ac4c commit 3c8fa11

File tree

9 files changed

+167
-24
lines changed

9 files changed

+167
-24
lines changed

.travis.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
language: python
2+
python:
3+
- 3.6
4+
sudo: false
5+
cache:
6+
pip: true
7+
directories:
8+
- $HOME/.npm
9+
before_install:
10+
- pip install -U pip setuptools
11+
- nvm install 6
12+
- pip install cookiecutter
13+
install:
14+
- |
15+
pushd $(mktemp -d)
16+
cookiecutter $TRAVIS_BUILD_DIR --config-file $TRAVIS_BUILD_DIR/tests/testconfig.yaml --no-input
17+
pushd jupyter-widget-testwidgets
18+
pip install --upgrade -v ".[test]"
19+
script:
20+
- |
21+
py.test
22+
npm test
23+
popd
24+
popd
25+
before_cache:
26+
# Do not cache our own package
27+
- |
28+
rm -rf packages/{{ cookiecutter.jlab_extension_name }}/node_modules/{{ cookiecutter.npm_package_name }}
29+
after_success:
30+
- codecov

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ you should run the tests:
4848
# First install the python package. This will also build the JS packages.
4949
pip install -e .
5050

51-
# Run the python tests. This should only give you TODO errors:
51+
# Run the python tests. This should not give you a few sucessful example tests
5252
py.test
5353

5454
# Run the JS tests. This should again, only give TODO errors (Expected 'Value' to equal 'Expected value'):

tests/testconfig.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
default_context:
2+
author_name: "Test Widget"
3+
author_email: "[email protected]"
4+
github_project_name: "jupyter-widget-testwidgets"
5+
github_organization_name: "jupyter"
6+
python_package_name: "ipywidgettestwidgets"
7+
npm_package_name: "jupyter-widget-testwidgets"
8+
npm_package_version: "1.1.0"
9+
jlab_extension_name: "jupyterlab-widget-testwidgets"
10+
jlab_extension_id: "jupyter.extensions.testwidgets"
11+
project_short_description: "A Test Jupyter Widget Library"

{{cookiecutter.github_project_name}}/examples/introduction.ipynb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@
2626
"source": [
2727
"assert w.value == 'Hello World'"
2828
]
29-
},
30-
{
31-
"cell_type": "code",
32-
"execution_count": null,
33-
"metadata": {},
34-
"outputs": [],
35-
"source": [
36-
"raise ValueError('TODO: Add example usage of your widget.')"
37-
]
3829
}
3930
],
4031
"metadata": {

{{cookiecutter.github_project_name}}/packages/{{ cookiecutter.jlab_extension_name }}/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"@jupyterlab/application": "~0.9.0",
99
"@phosphor/coreutils": "~1.3.0",
1010
"@jupyter-widgets/jupyterlab-manager": "~0.25.11",
11-
"{{ cookiecutter.npm_package_name }}": "{{ cookiecutter.npm_package_name }}"
11+
"{{ cookiecutter.npm_package_name }}": "^{{ cookiecutter.npm_package_version }}"
1212
},
1313
"devDependencies": {
1414
"rimraf": "^2.6.1",

{{cookiecutter.github_project_name}}/packages/{{ cookiecutter.npm_package_name }}/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
"jupyter",
2323
"widgets"
2424
],
25+
"dependencies": {
26+
"@jupyter-widgets/base": "~0.6.11"
27+
},
2528
"devDependencies": {
2629
"@types/expect.js": "^0.3.29",
2730
"@types/mocha": "^2.2.41",
@@ -41,9 +44,6 @@
4144
"typescript": "^2.4.2",
4245
"webpack": "^3.4.1"
4346
},
44-
"dependencies": {
45-
"@jupyter-widgets/base": "~0.6.11"
46-
},
4747
"repository": {
4848
"type": "git",
4949
"url": "https://github.com/{{ cookiecutter.github_organization_name }}/{{ cookiecutter.python_package_name }}"

{{cookiecutter.github_project_name}}/packages/{{ cookiecutter.npm_package_name }}/tests/src/index.spec.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,30 @@ import {
77
// Add any needed widget imports here (or from controls)
88
} from '@jupyter-widgets/base';
99

10+
import {
11+
createTestModel
12+
} from './utils.spec';
13+
1014
import {
1115
ExampleModel, ExampleView
1216
} from '../../src/'
1317

1418

15-
describe('Test category', () => {
19+
describe('Example', () => {
1620

17-
describe('Sub category', () => {
21+
describe('ExampleModel', () => {
22+
23+
it('should be createable', () => {
24+
let model = createTestModel(ExampleModel);
25+
expect(model).to.be.an(ExampleModel);
26+
expect(model.get('value')).to.be('Hello World');
27+
});
1828

19-
it('should be testable', () => {
20-
// TODO: Replace me!
21-
expect('Value').to.be('Expected value');
29+
it('should be createable with a value', () => {
30+
let state = { value: 'Foo Bar!' }
31+
let model = createTestModel(ExampleModel, state);
32+
expect(model).to.be.an(ExampleModel);
33+
expect(model.get('value')).to.be('Foo Bar!');
2234
});
2335

2436
});
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright (c) Jupyter Development Team.
2+
// Distributed under the terms of the Modified BSD License.
3+
4+
import * as widgets from '@jupyter-widgets/base';
5+
import * as services from '@jupyterlab/services';
6+
import * as Backbone from 'backbone';
7+
8+
let numComms = 0;
9+
10+
export
11+
class MockComm {
12+
constructor() {
13+
this.comm_id = `mock-comm-id-${numComms}`;
14+
numComms += 1;
15+
}
16+
on_close(fn: Function | null) {
17+
this._on_close = fn;
18+
}
19+
on_msg(fn: Function | null) {
20+
this._on_msg = fn;
21+
}
22+
_process_msg(msg: services.KernelMessage.ICommMsg) {
23+
if (this._on_msg) {
24+
return this._on_msg(msg);
25+
} else {
26+
return Promise.resolve();
27+
}
28+
}
29+
close() {
30+
if (this._on_close) {
31+
this._on_close();
32+
}
33+
}
34+
send() {}
35+
comm_id: string;
36+
_on_msg: Function | null = null;
37+
_on_close: Function | null = null;
38+
}
39+
40+
export
41+
class DummyManager extends widgets.ManagerBase<HTMLElement> {
42+
constructor() {
43+
super();
44+
this.el = window.document.createElement('div');
45+
}
46+
47+
display_view(msg: services.KernelMessage.IMessage, view: Backbone.View<Backbone.Model>, options: any) {
48+
// TODO: make this a spy
49+
// TODO: return an html element
50+
return Promise.resolve(view).then(view => {
51+
this.el.appendChild(view.el);
52+
view.on('remove', () => console.log('view removed', view));
53+
return view.el;
54+
});
55+
}
56+
57+
protected loadClass(className: string, moduleName: string, moduleVersion: string): Promise<any> {
58+
if (moduleName === '@jupyter-widgets/base') {
59+
if ((widgets as any)[className]) {
60+
return Promise.resolve((widgets as any)[className]);
61+
} else {
62+
return Promise.reject(`Cannot find class ${className}`)
63+
}
64+
} else if (moduleName === 'jupyter-datawidgets') {
65+
if (this.testClasses[className]) {
66+
return Promise.resolve(this.testClasses[className]);
67+
} else {
68+
return Promise.reject(`Cannot find class ${className}`)
69+
}
70+
} else {
71+
return Promise.reject(`Cannot find module ${moduleName}`);
72+
}
73+
}
74+
75+
_get_comm_info() {
76+
return Promise.resolve({});
77+
}
78+
79+
_create_comm() {
80+
return Promise.resolve(new MockComm());
81+
}
82+
83+
el: HTMLElement;
84+
85+
testClasses: { [key: string]: any } = {};
86+
}
87+
88+
89+
export
90+
interface Constructor<T> {
91+
new (attributes?: any, options?: any): T;
92+
}
93+
94+
export
95+
function createTestModel<T extends widgets.WidgetModel>(constructor: Constructor<T>, attributes?: any): T {
96+
let id = widgets.uuid();
97+
let widget_manager = new DummyManager();
98+
let modelOptions = {
99+
widget_manager: widget_manager,
100+
model_id: id,
101+
}
102+
103+
return new constructor(attributes, modelOptions);
104+
}

{{cookiecutter.github_project_name}}/{{cookiecutter.python_package_name}}/tests/test_example.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,3 @@
1212
def test_example_creation_blank():
1313
w = ExampleWidget()
1414
assert w.value == 'Hello World'
15-
16-
17-
def test_todo():
18-
# TODO: Replace me with proper tests
19-
assert 'Value' == 'Expected value'

0 commit comments

Comments
 (0)