-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore jupyter-widget tests (#7545)
- Loading branch information
1 parent
59c2651
commit 468d981
Showing
15 changed files
with
163 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 59 additions & 50 deletions
109
modules/jupyter-widget/src/lib/jupyter-transport-model.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,65 @@ | ||
import {DOMWidgetModel} from '@jupyter-widgets/base'; | ||
import * as widgets from '@jupyter-widgets/base'; | ||
import {MODULE_NAME, MODULE_VERSION} from '../version'; | ||
import {deserializeMatrix} from './utils/deserialize-matrix'; | ||
/** | ||
* | ||
* Note: Variables shared explictly between Python and JavaScript use snake_case | ||
*/ | ||
export default class JupyterTransportModel extends DOMWidgetModel { | ||
defaults() { | ||
return { | ||
...super.defaults(), | ||
_model_name: JupyterTransportModel.model_name, | ||
_model_module: JupyterTransportModel.model_module, | ||
_model_module_version: JupyterTransportModel.model_module_version, | ||
_view_name: JupyterTransportModel.view_name, | ||
_view_module: JupyterTransportModel.view_module, | ||
_view_module_version: JupyterTransportModel.view_module_version, | ||
custom_libraries: [], | ||
json_input: null, | ||
mapbox_key: null, | ||
selected_data: [], | ||
data_buffer: null, | ||
tooltip: null, | ||
width: '100%', | ||
height: 500, | ||
js_warning: false | ||
}; | ||
} | ||
|
||
static get serializers() { | ||
return { | ||
...DOMWidgetModel.serializers, | ||
// Add any extra serializers here | ||
data_buffer: {deserialize: deserializeMatrix} | ||
}; | ||
} | ||
let JupyterTransportModel = null; | ||
const DOMWidgetModel = widgets && widgets.DOMWidgetModel; | ||
|
||
static get model_name() { | ||
return 'JupyterTransportModel'; | ||
} | ||
static get model_module() { | ||
return MODULE_NAME; | ||
} | ||
static get model_module_version() { | ||
return MODULE_VERSION; | ||
} | ||
static get view_name() { | ||
return 'JupyterTransportView'; | ||
} | ||
static get view_module() { | ||
return MODULE_NAME; | ||
} | ||
static get view_module_version() { | ||
return MODULE_VERSION; | ||
if (DOMWidgetModel) { | ||
/** | ||
* | ||
* Note: Variables shared explictly between Python and JavaScript use snake_case | ||
*/ | ||
class Model extends DOMWidgetModel { | ||
defaults() { | ||
return { | ||
...super.defaults(), | ||
_model_name: JupyterTransportModel.model_name, | ||
_model_module: JupyterTransportModel.model_module, | ||
_model_module_version: JupyterTransportModel.model_module_version, | ||
_view_name: JupyterTransportModel.view_name, | ||
_view_module: JupyterTransportModel.view_module, | ||
_view_module_version: JupyterTransportModel.view_module_version, | ||
custom_libraries: [], | ||
json_input: null, | ||
mapbox_key: null, | ||
selected_data: [], | ||
data_buffer: null, | ||
tooltip: null, | ||
width: '100%', | ||
height: 500, | ||
js_warning: false | ||
}; | ||
} | ||
|
||
static get serializers() { | ||
return { | ||
...DOMWidgetModel.serializers, | ||
// Add any extra serializers here | ||
data_buffer: {deserialize: deserializeMatrix} | ||
}; | ||
} | ||
|
||
static get model_name() { | ||
return 'JupyterTransportModel'; | ||
} | ||
static get model_module() { | ||
return MODULE_NAME; | ||
} | ||
static get model_module_version() { | ||
return MODULE_VERSION; | ||
} | ||
static get view_name() { | ||
return 'JupyterTransportView'; | ||
} | ||
static get view_module() { | ||
return MODULE_NAME; | ||
} | ||
static get view_module_version() { | ||
return MODULE_VERSION; | ||
} | ||
} | ||
JupyterTransportModel = Model; | ||
} | ||
|
||
export default JupyterTransportModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,64 @@ | ||
import {DOMWidgetView} from '@jupyter-widgets/base'; | ||
import * as widgets from '@jupyter-widgets/base'; | ||
import JupyterTransport from './jupyter-transport'; | ||
|
||
export default class JupyterTransportView extends DOMWidgetView { | ||
initialize() { | ||
this.listenTo(this.model, 'destroy', this.remove); | ||
let JupyterTransportView = null; | ||
const DOMWidgetView = widgets && widgets.DOMWidgetView; | ||
|
||
// TODO - is there any variable information on the model we can use to | ||
// give an interesting name or id to this instance? | ||
this.transport = new JupyterTransport(); | ||
if (DOMWidgetView) { | ||
class View extends DOMWidgetView { | ||
initialize() { | ||
this.listenTo(this.model, 'destroy', this.remove); | ||
|
||
// Expose Jupyter internals to enable work-arounds | ||
this.transport.jupyterModel = this.model; | ||
this.transport.jupyterView = this; | ||
this.transport._initialize(); | ||
super.initialize.apply(this, arguments); | ||
} | ||
// TODO - is there any variable information on the model we can use to | ||
// give an interesting name or id to this instance? | ||
this.transport = new JupyterTransport(); | ||
|
||
remove() { | ||
if (this.transport) { | ||
this.transport._finalize(); | ||
this.transport.jupyterModel = null; | ||
this.transport.jupyterView = null; | ||
this.transport = null; | ||
// Expose Jupyter internals to enable work-arounds | ||
this.transport.jupyterModel = this.model; | ||
this.transport.jupyterView = this; | ||
this.transport._initialize(); | ||
super.initialize.apply(this, arguments); | ||
} | ||
} | ||
|
||
render() { | ||
super.render(); | ||
remove() { | ||
if (this.transport) { | ||
this.transport._finalize(); | ||
this.transport.jupyterModel = null; | ||
this.transport.jupyterView = null; | ||
this.transport = null; | ||
} | ||
} | ||
|
||
this.model.on('change:json_input', this.onJsonChanged.bind(this)); | ||
this.model.on('change:data_buffer', this.onDataBufferChanged.bind(this)); | ||
render() { | ||
super.render(); | ||
|
||
this.onDataBufferChanged(); | ||
} | ||
this.model.on('change:json_input', this.onJsonChanged.bind(this)); | ||
this.model.on('change:data_buffer', this.onDataBufferChanged.bind(this)); | ||
|
||
onJsonChanged() { | ||
const json = JSON.parse(this.model.get('json_input')); | ||
this.transport._messageReceived({type: 'json', json}); | ||
} | ||
this.onDataBufferChanged(); | ||
} | ||
|
||
onDataBufferChanged() { | ||
const json = this.model.get('json_input'); | ||
const dataBuffer = this.model.get('data_buffer'); | ||
|
||
if (json && dataBuffer) { | ||
this.transport._messageReceived({ | ||
type: 'json-with-binary', | ||
json, | ||
binary: dataBuffer | ||
}); | ||
} else { | ||
onJsonChanged() { | ||
const json = JSON.parse(this.model.get('json_input')); | ||
this.transport._messageReceived({type: 'json', json}); | ||
} | ||
|
||
onDataBufferChanged() { | ||
const json = this.model.get('json_input'); | ||
const dataBuffer = this.model.get('data_buffer'); | ||
|
||
if (json && dataBuffer) { | ||
this.transport._messageReceived({ | ||
type: 'json-with-binary', | ||
json, | ||
binary: dataBuffer | ||
}); | ||
} else { | ||
this.transport._messageReceived({type: 'json', json}); | ||
} | ||
} | ||
} | ||
JupyterTransportView = View; | ||
} | ||
|
||
export default JupyterTransportView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
modules/jupyter-widget/src/playground/utils/google-maps-utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 3 additions & 10 deletions
13
modules/jupyter-widget/src/playground/utils/mapbox-utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Dummy exports for node tests | ||
import * as Backbone from 'backbone'; | ||
|
||
export class ManagerBase {} | ||
export class DOMWidgetModel extends Backbone.Model { | ||
defaults() { | ||
return {}; | ||
} | ||
} | ||
export class DOMWidgetView {} | ||
export function uuid() { | ||
return 'uuid'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Dummy exports for node tests | ||
export default {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
try { | ||
require('./binary-transport.spec'); | ||
require('./create-deck.spec'); | ||
require('./index.spec'); | ||
require('./widget-tooltip.spec'); | ||
require('./utils/google-maps-utils.spec'); | ||
} catch (err) { | ||
// eslint-disable-next-line no-console,no-undef | ||
console.log('Skipping browser tests'); | ||
} | ||
import './binary-transport.spec'; | ||
import './create-deck.spec'; | ||
import './widget-tooltip.spec'; | ||
import './utils/google-maps-utils.spec'; | ||
|
||
import './index.spec'; |
Oops, something went wrong.