How to use properties method in pandera

Best Python code snippet using pandera_python

tablepropertiesui.js

Source:tablepropertiesui.js Github

copy

Full Screen

1/**2 * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.3 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license4 */5/* globals document, Event */6import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';7import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';8import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';9import { getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';10import Undo from '@ckeditor/ckeditor5-undo/src/undo';11import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';12import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';13import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';14import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';15import Table from '../../src/table';16import TablePropertiesEditing from '../../src/tableproperties/tablepropertiesediting';17import TablePropertiesUI from '../../src/tableproperties/tablepropertiesui';18import TablePropertiesUIView from '../../src/tableproperties/ui/tablepropertiesview';19import { defaultColors } from '../../src/utils/ui/table-properties';20describe( 'table properties', () => {21 describe( 'TablePropertiesUI', () => {22 let editor, editorElement, contextualBalloon,23 tablePropertiesUI, tablePropertiesView, tablePropertiesButton,24 clock;25 testUtils.createSinonSandbox();26 beforeEach( () => {27 clock = sinon.useFakeTimers();28 editorElement = document.createElement( 'div' );29 document.body.appendChild( editorElement );30 return ClassicTestEditor31 .create( editorElement, {32 plugins: [ Table, TablePropertiesEditing, TablePropertiesUI, Paragraph, Undo ],33 initialData: '<table><tr><td>foo</td></tr></table><p>bar</p>'34 } )35 .then( newEditor => {36 editor = newEditor;37 tablePropertiesUI = editor.plugins.get( TablePropertiesUI );38 tablePropertiesButton = editor.ui.componentFactory.create( 'tableProperties' );39 contextualBalloon = editor.plugins.get( ContextualBalloon );40 tablePropertiesView = tablePropertiesUI.view;41 // There is no point to execute BalloonPanelView attachTo and pin methods so lets override it.42 testUtils.sinon.stub( contextualBalloon.view, 'attachTo' ).returns( {} );43 testUtils.sinon.stub( contextualBalloon.view, 'pin' ).returns( {} );44 } );45 } );46 afterEach( () => {47 clock.restore();48 editorElement.remove();49 return editor.destroy();50 } );51 it( 'should be named', () => {52 expect( TablePropertiesUI.pluginName ).to.equal( 'TablePropertiesUI' );53 } );54 it( 'should load ContextualBalloon', () => {55 expect( editor.plugins.get( ContextualBalloon ) ).to.be.instanceOf( ContextualBalloon );56 } );57 describe( 'constructor()', () => {58 it( 'should define table.tableProperties config', () => {59 expect( editor.config.get( 'table.tableProperties' ) ).to.deep.equal( {60 borderColors: defaultColors,61 backgroundColors: defaultColors62 } );63 } );64 } );65 describe( 'init()', () => {66 it( 'should set a batch', () => {67 expect( tablePropertiesUI._undoStepBatch ).to.be.null;68 } );69 describe( '#view', () => {70 it( 'should be created', () => {71 expect( tablePropertiesUI.view ).to.be.instanceOf( TablePropertiesUIView );72 } );73 it( 'should be rendered', () => {74 expect( tablePropertiesUI.view.isRendered ).to.be.true;75 } );76 it( 'should get the border colors configurations', () => {77 expect( tablePropertiesView.options.borderColors ).to.have.length( 15 );78 } );79 it( 'should get the background colors configurations', () => {80 expect( tablePropertiesView.options.backgroundColors ).to.have.length( 15 );81 } );82 } );83 describe( 'toolbar button', () => {84 it( 'should be registered', () => {85 expect( tablePropertiesButton ).to.be.instanceOf( ButtonView );86 } );87 it( 'should have a label', () => {88 expect( tablePropertiesButton.label ).to.equal( 'Table properties' );89 } );90 it( 'should have a tooltip', () => {91 expect( tablePropertiesButton.tooltip ).to.be.true;92 } );93 it( 'should call #_showView upon #execute', () => {94 const spy = testUtils.sinon.stub( tablePropertiesUI, '_showView' ).returns( {} );95 tablePropertiesButton.fire( 'execute' );96 sinon.assert.calledOnce( spy );97 } );98 it( 'should be disabled if all of the table properties commands are disabled', () => {99 [100 'tableBorderStyle',101 'tableBorderColor',102 'tableBorderWidth',103 'tableBackgroundColor',104 'tableWidth',105 'tableHeight',106 'tableAlignment'107 ].forEach( command => {108 editor.commands.get( command ).isEnabled = false;109 } );110 expect( tablePropertiesButton.isEnabled ).to.be.false;111 editor.commands.get( 'tableBackgroundColor' ).isEnabled = true;112 expect( tablePropertiesButton.isEnabled ).to.be.true;113 } );114 } );115 } );116 describe( 'destroy()', () => {117 it( 'should destroy the #view', () => {118 const spy = sinon.spy( tablePropertiesView, 'destroy' );119 tablePropertiesUI.destroy();120 sinon.assert.calledOnce( spy );121 } );122 } );123 describe( 'Properties #view', () => {124 beforeEach( () => {125 editor.model.change( writer => {126 writer.setSelection( editor.model.document.getRoot().getChild( 0 ).getChild( 0 ).getChild( 0 ), 0 );127 } );128 } );129 it( 'should hide on #submit', () => {130 tablePropertiesButton.fire( 'execute' );131 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );132 tablePropertiesView.fire( 'submit' );133 expect( contextualBalloon.visibleView ).to.be.null;134 } );135 describe( '#cancel event', () => {136 // https://github.com/ckeditor/ckeditor5/issues/6180137 it( 'should not undo if it there were no changes made to the property fields', () => {138 const spy = sinon.spy( editor, 'execute' );139 // Show the view. New batch will be created.140 tablePropertiesButton.fire( 'execute' );141 // Cancel the view immediately.142 tablePropertiesView.fire( 'cancel' );143 sinon.assert.notCalled( spy );144 } );145 it( 'should undo the entire batch of changes if there were some', () => {146 const spy = sinon.spy( editor, 'execute' );147 // Show the view. New batch will be created.148 tablePropertiesButton.fire( 'execute' );149 // Do the changes like a user.150 tablePropertiesView.borderStyle = 'dotted';151 tablePropertiesView.backgroundColor = 'red';152 expect( getModelData( editor.model ) ).to.equal(153 '<table backgroundColor="red" borderStyle="dotted">' +154 '<tableRow>' +155 '<tableCell>' +156 '<paragraph>[]foo</paragraph>' +157 '</tableCell>' +158 '</tableRow>' +159 '</table>' +160 '<paragraph>bar</paragraph>'161 );162 tablePropertiesView.fire( 'cancel' );163 expect( getModelData( editor.model ) ).to.equal(164 '<table>' +165 '<tableRow>' +166 '<tableCell>' +167 '<paragraph>[]foo</paragraph>' +168 '</tableCell>' +169 '</tableRow>' +170 '</table>' +171 '<paragraph>bar</paragraph>'172 );173 sinon.assert.calledWith( spy, 'undo', tablePropertiesUI._undoStepBatch );174 } );175 it( 'should hide the view', () => {176 tablePropertiesButton.fire( 'execute' );177 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );178 tablePropertiesView.fire( 'cancel' );179 expect( contextualBalloon.visibleView ).to.be.null;180 } );181 } );182 it( 'should hide on the Esc key press', () => {183 const keyEvtData = {184 keyCode: keyCodes.esc,185 preventDefault: sinon.spy(),186 stopPropagation: sinon.spy()187 };188 tablePropertiesButton.fire( 'execute' );189 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );190 tablePropertiesView.keystrokes.press( keyEvtData );191 expect( contextualBalloon.visibleView ).to.be.null;192 } );193 it( 'should hide if the table is no longer selected on EditorUI#update', () => {194 tablePropertiesButton.fire( 'execute' );195 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );196 editor.model.change( writer => {197 // Set selection in the paragraph.198 writer.setSelection( editor.model.document.getRoot().getChild( 1 ), 0 );199 } );200 expect( contextualBalloon.visibleView ).to.be.null;201 } );202 it( 'should reposition if table is still selected on on EditorUI#update', () => {203 tablePropertiesButton.fire( 'execute' );204 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );205 editor.model.change( writer => {206 writer.insertText( 'qux', editor.model.document.selection.getFirstPosition() );207 } );208 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );209 } );210 it( 'should hide if clicked outside the balloon', () => {211 tablePropertiesButton.fire( 'execute' );212 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );213 document.body.dispatchEvent( new Event( 'mousedown', { bubbles: true } ) );214 expect( contextualBalloon.visibleView ).to.be.null;215 } );216 describe( 'property changes', () => {217 beforeEach( () => {218 tablePropertiesUI._undoStepBatch = 'foo';219 } );220 describe( '#borderStyle', () => {221 it( 'should affect the editor state', () => {222 const spy = testUtils.sinon.stub( editor, 'execute' );223 tablePropertiesView.borderStyle = 'dotted';224 sinon.assert.calledOnce( spy );225 sinon.assert.calledWithExactly( spy, 'tableBorderStyle', { value: 'dotted', batch: 'foo' } );226 } );227 } );228 describe( '#borderColor', () => {229 it( 'should affect the editor state', () => {230 const spy = testUtils.sinon.stub( editor, 'execute' );231 tablePropertiesView.borderColor = '#FFAAFF';232 sinon.assert.calledOnce( spy );233 sinon.assert.calledWithExactly( spy, 'tableBorderColor', { value: '#FFAAFF', batch: 'foo' } );234 } );235 it( 'should display an error message if value is invalid', () => {236 const spy = testUtils.sinon.stub( editor, 'execute' );237 // First, let's pass an invalid value and check what happens.238 tablePropertiesView.borderColor = '42';239 clock.tick( 500 );240 expect( tablePropertiesView.borderColorInput.errorText ).to.match( /^The color is invalid/ );241 sinon.assert.notCalled( spy );242 // And now let's pass a valid value and check if the error text will be gone.243 tablePropertiesView.borderColor = '#AAA';244 clock.tick( 500 );245 expect( tablePropertiesView.borderColorInput.errorText ).to.be.null;246 sinon.assert.calledWithExactly( spy, 'tableBorderColor', { value: '#AAA', batch: 'foo' } );247 } );248 } );249 describe( '#borderWidth', () => {250 it( 'should affect the editor state', () => {251 const spy = testUtils.sinon.stub( editor, 'execute' );252 tablePropertiesView.borderWidth = '12px';253 sinon.assert.calledOnce( spy );254 sinon.assert.calledWithExactly( spy, 'tableBorderWidth', { value: '12px', batch: 'foo' } );255 } );256 it( 'should display an error message if value is invalid', () => {257 const spy = testUtils.sinon.stub( editor, 'execute' );258 // First, let's pass an invalid value and check what happens.259 tablePropertiesView.borderWidth = 'wrong';260 clock.tick( 500 );261 expect( tablePropertiesView.borderWidthInput.errorText ).to.match( /^The value is invalid/ );262 sinon.assert.notCalled( spy );263 // And now let's pass a valid value and check if the error text will be gone.264 tablePropertiesView.borderWidth = '3em';265 clock.tick( 500 );266 expect( tablePropertiesView.backgroundInput.errorText ).to.be.null;267 sinon.assert.calledWithExactly( spy, 'tableBorderWidth', { value: '3em', batch: 'foo' } );268 } );269 } );270 describe( '#backgroundColor', () => {271 it( 'should affect the editor state', () => {272 const spy = testUtils.sinon.stub( editor, 'execute' );273 tablePropertiesView.backgroundColor = '#FFAAFF';274 sinon.assert.calledOnce( spy );275 sinon.assert.calledWithExactly( spy, 'tableBackgroundColor', { value: '#FFAAFF', batch: 'foo' } );276 } );277 it( 'should display an error message if value is invalid', () => {278 const spy = testUtils.sinon.stub( editor, 'execute' );279 // First, let's pass an invalid value and check what happens.280 tablePropertiesView.backgroundColor = '42';281 clock.tick( 500 );282 expect( tablePropertiesView.backgroundInput.errorText ).to.match( /^The color is invalid/ );283 sinon.assert.notCalled( spy );284 // And now let's pass a valid value and check if the error text will be gone.285 tablePropertiesView.backgroundColor = '#AAA';286 clock.tick( 500 );287 expect( tablePropertiesView.backgroundInput.errorText ).to.be.null;288 sinon.assert.calledWithExactly( spy, 'tableBackgroundColor', { value: '#AAA', batch: 'foo' } );289 } );290 } );291 describe( '#width', () => {292 it( 'should affect the editor state', () => {293 const spy = testUtils.sinon.stub( editor, 'execute' );294 tablePropertiesView.width = '12px';295 sinon.assert.calledOnce( spy );296 sinon.assert.calledWithExactly( spy, 'tableWidth', { value: '12px', batch: 'foo' } );297 } );298 it( 'should display an error message if value is invalid', () => {299 const spy = testUtils.sinon.stub( editor, 'execute' );300 // First, let's pass an invalid value and check what happens.301 tablePropertiesView.width = 'wrong';302 clock.tick( 500 );303 expect( tablePropertiesView.widthInput.errorText ).to.match( /^The value is invalid/ );304 sinon.assert.notCalled( spy );305 // And now let's pass a valid value and check if the error text will be gone.306 tablePropertiesView.width = '3em';307 clock.tick( 500 );308 expect( tablePropertiesView.backgroundInput.errorText ).to.be.null;309 sinon.assert.calledWithExactly( spy, 'tableWidth', { value: '3em', batch: 'foo' } );310 } );311 } );312 describe( '#height', () => {313 it( 'should affect the editor state', () => {314 const spy = testUtils.sinon.stub( editor, 'execute' );315 tablePropertiesView.height = '12px';316 sinon.assert.calledOnce( spy );317 sinon.assert.calledWithExactly( spy, 'tableHeight', { value: '12px', batch: 'foo' } );318 } );319 it( 'should display an error message if value is invalid', () => {320 const spy = testUtils.sinon.stub( editor, 'execute' );321 // First, let's pass an invalid value and check what happens.322 tablePropertiesView.height = 'wrong';323 clock.tick( 500 );324 expect( tablePropertiesView.heightInput.errorText ).to.match( /^The value is invalid/ );325 sinon.assert.notCalled( spy );326 // And now let's pass a valid value and check if the error text will be gone.327 tablePropertiesView.height = '3em';328 clock.tick( 500 );329 expect( tablePropertiesView.backgroundInput.errorText ).to.be.null;330 sinon.assert.calledWithExactly( spy, 'tableHeight', { value: '3em', batch: 'foo' } );331 } );332 } );333 describe( '#alignment', () => {334 it( 'should affect the editor state', () => {335 const spy = testUtils.sinon.stub( editor, 'execute' );336 tablePropertiesView.alignment = 'right';337 sinon.assert.calledOnce( spy );338 sinon.assert.calledWithExactly( spy, 'tableAlignment', { value: 'right', batch: 'foo' } );339 } );340 } );341 it( 'should not display an error text if user managed to fix the value before the UI timeout', () => {342 // First, let's pass an invalid value.343 tablePropertiesView.borderColor = '#';344 clock.tick( 100 );345 // Then the user managed to quickly type the correct value.346 tablePropertiesView.borderColor = '#aaa';347 clock.tick( 400 );348 // Because they were quick, they should see no error349 expect( tablePropertiesView.borderColorInput.errorText ).to.be.null;350 } );351 it( 'should not affect the editor state if internal property has changed', () => {352 const spy = testUtils.sinon.stub( editor, 'execute' );353 tablePropertiesView.set( 'internalProp', 'foo' );354 tablePropertiesView.internalProp = 'bar';355 sinon.assert.notCalled( spy );356 } );357 } );358 } );359 describe( 'Showing the #view', () => {360 beforeEach( () => {361 editor.model.change( writer => {362 writer.setSelection( editor.model.document.getRoot().getChild( 0 ).getChild( 0 ).getChild( 0 ), 0 );363 } );364 } );365 it( 'should create a new undoable batch for further #view cancel', () => {366 tablePropertiesButton.fire( 'execute' );367 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );368 const firstBatch = tablePropertiesUI._undoStepBatch;369 expect( firstBatch ).to.be.instanceOf( Batch );370 tablePropertiesView.fire( 'submit' );371 expect( contextualBalloon.visibleView ).to.be.null;372 tablePropertiesButton.fire( 'execute' );373 const secondBatch = tablePropertiesUI._undoStepBatch;374 expect( secondBatch ).to.be.instanceOf( Batch );375 expect( firstBatch ).to.not.equal( secondBatch );376 } );377 describe( 'initial data', () => {378 it( 'should be set from the command values', () => {379 editor.commands.get( 'tableBorderStyle' ).value = 'a';380 editor.commands.get( 'tableBorderColor' ).value = 'b';381 editor.commands.get( 'tableBorderWidth' ).value = 'c';382 editor.commands.get( 'tableBackgroundColor' ).value = 'd';383 editor.commands.get( 'tableWidth' ).value = 'e';384 editor.commands.get( 'tableHeight' ).value = 'f';385 editor.commands.get( 'tableAlignment' ).value = 'g';386 tablePropertiesButton.fire( 'execute' );387 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );388 expect( tablePropertiesView ).to.include( {389 borderStyle: 'a',390 borderColor: 'b',391 borderWidth: 'c',392 backgroundColor: 'd',393 width: 'e',394 height: 'f',395 alignment: 'g'396 } );397 } );398 it( 'should use default values when command has no value', () => {399 editor.commands.get( 'tableBorderStyle' ).value = null;400 editor.commands.get( 'tableBorderColor' ).value = null;401 editor.commands.get( 'tableBorderWidth' ).value = null;402 editor.commands.get( 'tableBackgroundColor' ).value = null;403 editor.commands.get( 'tableWidth' ).value = null;404 editor.commands.get( 'tableHeight' ).value = null;405 editor.commands.get( 'tableAlignment' ).value = null;406 tablePropertiesButton.fire( 'execute' );407 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );408 expect( tablePropertiesView ).to.include( {409 borderStyle: '',410 borderColor: '',411 borderWidth: '',412 backgroundColor: '',413 width: '',414 height: '',415 alignment: ''416 } );417 } );418 } );419 it( 'should focus the form view', () => {420 const spy = testUtils.sinon.spy( tablePropertiesView, 'focus' );421 tablePropertiesButton.fire( 'execute' );422 sinon.assert.calledOnce( spy );423 } );424 } );425 describe( 'Hiding the #view', () => {426 beforeEach( () => {427 editor.model.change( writer => {428 writer.setSelection( editor.model.document.getRoot().getChild( 0 ).getChild( 0 ).getChild( 0 ), 0 );429 } );430 } );431 it( 'should stop listening to EditorUI#update', () => {432 const spy = testUtils.sinon.spy( tablePropertiesUI, 'stopListening' );433 tablePropertiesButton.fire( 'execute' );434 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );435 tablePropertiesView.fire( 'submit' );436 expect( contextualBalloon.visibleView ).to.be.null;437 sinon.assert.calledOnce( spy );438 sinon.assert.calledWithExactly( spy, editor.ui, 'update' );439 } );440 it( 'should focus the editing view so the focus is not lost', () => {441 const spy = testUtils.sinon.spy( editor.editing.view, 'focus' );442 tablePropertiesButton.fire( 'execute' );443 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );444 tablePropertiesView.fire( 'submit' );445 sinon.assert.calledOnce( spy );446 } );447 } );448 } );...

Full Screen

Full Screen

additional_properties.js

Source:additional_properties.js Github

copy

Full Screen

1// @tags: [requires_non_retryable_commands]2/**3 * Tests for the JSON Schema 'additionalProperties' keyword.4 */5(function() {6 "use strict";7 load("jstests/libs/assert_schema_match.js");8 const coll = db.schema_allowed_properties;9 // Tests for {additionalProperties:false} at the top level.10 assertSchemaMatch(11 coll, {properties: {_id: {}, a: {}}, additionalProperties: false}, {_id: 1}, true);12 assertSchemaMatch(13 coll, {properties: {_id: {}, a: {}}, additionalProperties: false}, {_id: 1, a: 1}, true);14 assertSchemaMatch(15 coll, {properties: {_id: {}, a: {}}, additionalProperties: false}, {_id: 1, b: 1}, false);16 assertSchemaMatch(coll,17 {properties: {_id: {}, a: {}}, additionalProperties: false},18 {_id: 1, a: 1, b: 1},19 false);20 // Tests for {additionalProperties:true} at the top level.21 assertSchemaMatch(22 coll, {properties: {_id: {}, a: {}}, additionalProperties: true}, {_id: 1}, true);23 assertSchemaMatch(24 coll, {properties: {_id: {}, a: {}}, additionalProperties: true}, {_id: 1, a: 1}, true);25 assertSchemaMatch(26 coll, {properties: {_id: {}, a: {}}, additionalProperties: true}, {_id: 1, b: 1}, true);27 assertSchemaMatch(coll,28 {properties: {_id: {}, a: {}}, additionalProperties: true},29 {_id: 1, a: 1, b: 1},30 true);31 // Tests for additionalProperties with a nested schema at the top level.32 assertSchemaMatch(coll,33 {properties: {_id: {}, a: {}}, additionalProperties: {type: "number"}},34 {_id: 1},35 true);36 assertSchemaMatch(coll,37 {properties: {_id: {}, a: {}}, additionalProperties: {type: "number"}},38 {_id: 1, a: 1},39 true);40 assertSchemaMatch(coll,41 {properties: {_id: {}, a: {}}, additionalProperties: {type: "number"}},42 {_id: 1, b: 1},43 true);44 assertSchemaMatch(coll,45 {properties: {_id: {}, a: {}}, additionalProperties: {type: "number"}},46 {_id: 1, b: "str"},47 false);48 // Tests for additionalProperties together with patternProperties at the top level.49 assertSchemaMatch(coll,50 {51 properties: {_id: {}, a: {}},52 patternProperties: {"^b": {type: "string"}},53 additionalProperties: {type: "number"}54 },55 {_id: 1},56 true);57 assertSchemaMatch(coll,58 {59 properties: {_id: {}, a: {}},60 patternProperties: {"^b": {type: "string"}},61 additionalProperties: {type: "number"}62 },63 {_id: 1, a: 1},64 true);65 assertSchemaMatch(coll,66 {67 properties: {_id: {}, a: {}},68 patternProperties: {"^b": {type: "string"}},69 additionalProperties: {type: "number"}70 },71 {_id: 1, a: 1, ba: "str"},72 true);73 assertSchemaMatch(coll,74 {75 properties: {_id: {}, a: {}},76 patternProperties: {"^b": {type: "string"}},77 additionalProperties: {type: "number"}78 },79 {_id: 1, a: 1, ba: "str", other: 1},80 true);81 assertSchemaMatch(coll,82 {83 properties: {_id: {}, a: {}},84 patternProperties: {"^b": {type: "string"}},85 additionalProperties: {type: "number"}86 },87 {_id: 1, a: 1, ba: "str", other: "str"},88 false);89 assertSchemaMatch(coll,90 {91 properties: {_id: {}, a: {}},92 patternProperties: {"^b": {type: "string"}},93 additionalProperties: {type: "number"}94 },95 {_id: 1, a: 1, ba: 1, other: 1},96 false);97 assertSchemaMatch(coll,98 {99 properties: {_id: {}, a: {}},100 patternProperties: {"^b": {type: "string"}},101 additionalProperties: false102 },103 {_id: 1, a: 1, ba: "str"},104 true);105 assertSchemaMatch(coll,106 {107 properties: {_id: {}, a: {}},108 patternProperties: {"^b": {type: "string"}},109 additionalProperties: false110 },111 {_id: 1, a: 1, ba: "str", other: 1},112 false);113 // Tests for {additionalProperties:false} in a nested schema.114 assertSchemaMatch(115 coll, {properties: {obj: {properties: {a: {}}, additionalProperties: false}}}, {}, true);116 assertSchemaMatch(coll,117 {properties: {obj: {properties: {a: {}}, additionalProperties: false}}},118 {obj: 1},119 true);120 assertSchemaMatch(coll,121 {properties: {obj: {properties: {a: {}}, additionalProperties: false}}},122 {obj: {}},123 true);124 assertSchemaMatch(coll,125 {properties: {obj: {properties: {a: {}}, additionalProperties: false}}},126 {obj: {a: 1}},127 true);128 assertSchemaMatch(coll,129 {properties: {obj: {properties: {a: {}}, additionalProperties: false}}},130 {obj: {a: 1, b: 1}},131 false);132 assertSchemaMatch(coll,133 {properties: {obj: {properties: {a: {}}, additionalProperties: false}}},134 {obj: {b: 1}},135 false);136 // Tests for {additionalProperties:true} in a nested schema.137 assertSchemaMatch(coll,138 {properties: {obj: {properties: {a: {}}, additionalProperties: true}}},139 {obj: {}},140 true);141 assertSchemaMatch(coll,142 {properties: {obj: {properties: {a: {}}, additionalProperties: true}}},143 {obj: {a: 1}},144 true);145 assertSchemaMatch(coll,146 {properties: {obj: {properties: {a: {}}, additionalProperties: true}}},147 {obj: {a: 1, b: 1}},148 true);149 assertSchemaMatch(coll,150 {properties: {obj: {properties: {a: {}}, additionalProperties: true}}},151 {obj: {b: 1}},152 true);153 // Tests for additionalProperties whose value is a nested schema, which is itself contained154 // within a nested schema.155 assertSchemaMatch(156 coll,157 {properties: {obj: {properties: {a: {}}, additionalProperties: {type: "number"}}}},158 {},159 true);160 assertSchemaMatch(161 coll,162 {properties: {obj: {properties: {a: {}}, additionalProperties: {type: "number"}}}},163 {obj: 1},164 true);165 assertSchemaMatch(166 coll,167 {properties: {obj: {properties: {a: {}}, additionalProperties: {type: "number"}}}},168 {obj: {}},169 true);170 assertSchemaMatch(171 coll,172 {properties: {obj: {properties: {a: {}}, additionalProperties: {type: "number"}}}},173 {obj: {a: 1}},174 true);175 assertSchemaMatch(176 coll,177 {properties: {obj: {properties: {a: {}}, additionalProperties: {type: "number"}}}},178 {obj: {a: 1, b: 1}},179 true);180 assertSchemaMatch(181 coll,182 {properties: {obj: {properties: {a: {}}, additionalProperties: {type: "number"}}}},183 {obj: {a: 1, b: "str"}},184 false);185 assertSchemaMatch(186 coll,187 {properties: {obj: {properties: {a: {}}, additionalProperties: {type: "number"}}}},188 {obj: {b: "str"}},189 false);190 // Tests for additionalProperties together with patternProperties, both inside a nested schema.191 assertSchemaMatch(coll,192 {193 properties: {194 obj: {195 properties: {a: {}},196 patternProperties: {"^b": {type: "string"}},197 additionalProperties: {type: "number"}198 }199 }200 },201 {obj: {}},202 true);203 assertSchemaMatch(coll,204 {205 properties: {206 obj: {207 properties: {a: {}},208 patternProperties: {"^b": {type: "string"}},209 additionalProperties: {type: "number"}210 }211 }212 },213 {obj: {a: 1, ba: "str", c: 1}},214 true);215 assertSchemaMatch(coll,216 {217 properties: {218 obj: {219 properties: {a: {}},220 patternProperties: {"^b": {type: "string"}},221 additionalProperties: {type: "number"}222 }223 }224 },225 {obj: {a: 1, ba: 1, c: 1}},226 false);227 assertSchemaMatch(coll,228 {229 properties: {230 obj: {231 properties: {a: {}},232 patternProperties: {"^b": {type: "string"}},233 additionalProperties: {type: "number"}234 }235 }236 },237 {obj: {a: 1, ba: 1, c: "str"}},238 false);...

Full Screen

Full Screen

ObjectMakr-0.2.2.js

Source:ObjectMakr-0.2.2.js Github

copy

Full Screen

1var ObjectMakr;2(function (ObjectMakr_1) {3 "use strict";4 /**5 * An factory for JavaScript classes that automates the process of6 * setting constructors' prototypal inheritance. A sketch of class inheritance7 * and a listing of properties for each class is taken in, and dynamically8 * accessible constructors keyed by String names are made available.9 */10 var ObjectMakr = (function () {11 /**12 * Initializes a new instance of the ObjectMakr class.13 *14 * @param settings Settings to be used for initialization.15 */16 function ObjectMakr(settings) {17 if (typeof settings === "undefined") {18 throw new Error("No settings object given to ObjectMakr.");19 }20 if (typeof settings.inheritance === "undefined") {21 throw new Error("No inheritance given to ObjectMakr.");22 }23 this.inheritance = settings.inheritance;24 this.properties = settings.properties || {};25 this.doPropertiesFull = settings.doPropertiesFull;26 this.indexMap = settings.indexMap;27 this.onMake = settings.onMake;28 this.functions = {};29 if (this.doPropertiesFull) {30 this.propertiesFull = {};31 }32 if (this.indexMap) {33 this.processProperties(this.properties);34 }35 this.processFunctions(this.inheritance, Object, "Object");36 }37 /* Simple gets38 */39 /**40 * @returns The complete inheritance mapping.41 */42 ObjectMakr.prototype.getInheritance = function () {43 return this.inheritance;44 };45 /**46 * @returns The complete properties mapping.47 */48 ObjectMakr.prototype.getProperties = function () {49 return this.properties;50 };51 /**52 * @returns The properties for a particular class.53 */54 ObjectMakr.prototype.getPropertiesOf = function (title) {55 return this.properties[title];56 };57 /**58 * @returns Full properties, if doPropertiesFull is true.59 */60 ObjectMakr.prototype.getFullProperties = function () {61 return this.propertiesFull;62 };63 /**64 * @returns Full properties for a particular class, if65 * doPropertiesFull is true.66 */67 ObjectMakr.prototype.getFullPropertiesOf = function (title) {68 return this.doPropertiesFull ? this.propertiesFull[title] : undefined;69 };70 /**71 * @returns The full mapping of class constructors.72 */73 ObjectMakr.prototype.getFunctions = function () {74 return this.functions;75 };76 /**77 * @param name The name of a class to retrieve.78 * @returns The constructor for the given class.79 */80 ObjectMakr.prototype.getFunction = function (name) {81 return this.functions[name];82 };83 /**84 * @param type The name of a class to check for.85 * @returns Whether that class exists.86 */87 ObjectMakr.prototype.hasFunction = function (name) {88 return this.functions.hasOwnProperty(name);89 };90 /**91 * @returns The optional mapping of indices.92 */93 ObjectMakr.prototype.getIndexMap = function () {94 return this.indexMap;95 };96 /* Core usage97 */98 /**99 * Creates a new instance of the specified type and returns it.100 * If desired, any settings are applied to it (deep copy using proliferate).101 *102 * @param name The name of the type to initialize a new instance of.103 * @param [settings] Additional attributes to add to the new instance.104 * @returns A newly created instance of the specified type.105 */106 ObjectMakr.prototype.make = function (name, settings) {107 var output;108 // Make sure the type actually exists in Functions109 if (!this.functions.hasOwnProperty(name)) {110 throw new Error("Unknown type given to ObjectMakr: " + name);111 }112 // Create the new object, copying any given settings113 output = new this.functions[name]();114 if (settings) {115 this.proliferate(output, settings);116 }117 // onMake triggers are handled respecting doPropertiesFull.118 if (this.onMake && output[this.onMake]) {119 output[this.onMake](output, name, settings, (this.doPropertiesFull ? this.propertiesFull : this.properties)[name]);120 }121 return output;122 };123 /* Core parsing124 */125 /**126 * Parser that calls processPropertyArray on all properties given as arrays127 *128 * @param properties Type properties for classes to create.129 * @remarks Only call this if indexMap is given as an array130 */131 ObjectMakr.prototype.processProperties = function (properties) {132 var name;133 // For each of the given properties:134 for (name in properties) {135 if (properties.hasOwnProperty(name)) {136 // If it's an Array, replace it with a mapped version137 if (properties[name] instanceof Array) {138 properties[name] = this.processPropertyArray(properties[name]);139 }140 }141 }142 };143 /**144 * Creates an output properties object with the mapping shown in indexMap145 *146 * @param properties An Array with indiced versions of properties147 * @example148 * this.indexMap = ["width", "height"];149 * this.processPropertyArray([7, 14]);150 * // { "width": 7, "height": 14 }151 */152 ObjectMakr.prototype.processPropertyArray = function (properties) {153 var output = {}, i;154 // For each [i] in properties, set that property as under indexMap[i]155 for (i = properties.length - 1; i >= 0; --i) {156 output[this.indexMap[i]] = properties[i];157 }158 return output;159 };160 /**161 * Recursive parser to generate each Function, starting from the base.162 *163 * @param base An object whose keys are the names of Functions to164 * made, and whose values are objects whose keys are165 * for children that inherit from these Functions166 * @param parent The parent class Function of the classes about to be made.167 * @param [parentName] The name of the parent class to be inherited from,168 * if it is a generated one (and not Object itself).169 */170 ObjectMakr.prototype.processFunctions = function (base, parent, parentName) {171 var name, ref;172 // For each name in the current object:173 for (name in base) {174 if (base.hasOwnProperty(name)) {175 this.functions[name] = (new Function());176 // This sets the Function as inheriting from the parent177 this.functions[name].prototype = new parent();178 this.functions[name].prototype.constructor = this.functions[name];179 // Add each property from properties to the Function prototype180 for (ref in this.properties[name]) {181 if (this.properties[name].hasOwnProperty(ref)) {182 this.functions[name].prototype[ref] = this.properties[name][ref];183 }184 }185 // If the entire property tree is being mapped, copy everything186 // from both this and its parent to its equivalent187 if (this.doPropertiesFull) {188 this.propertiesFull[name] = {};189 if (parentName) {190 for (ref in this.propertiesFull[parentName]) {191 if (this.propertiesFull[parentName].hasOwnProperty(ref)) {192 this.propertiesFull[name][ref] = this.propertiesFull[parentName][ref];193 }194 }195 }196 for (ref in this.properties[name]) {197 if (this.properties[name].hasOwnProperty(ref)) {198 this.propertiesFull[name][ref] = this.properties[name][ref];199 }200 }201 }202 this.processFunctions(base[name], this.functions[name], name);203 }204 }205 };206 /* Utilities207 */208 /**209 * Proliferates all members of the donor to the recipient recursively, as210 * a deep copy.211 *212 * @param recipient An object receiving the donor's members.213 * @param donor An object whose members are copied to recipient.214 * @param [noOverride] If recipient properties may be overriden (by default, false).215 */216 ObjectMakr.prototype.proliferate = function (recipient, donor, noOverride) {217 var setting, i;218 // For each attribute of the donor:219 for (i in donor) {220 // If noOverride is specified, don't override if it already exists221 if (noOverride && recipient.hasOwnProperty(i)) {222 continue;223 }224 // If it's an object, recurse on a new version of it225 setting = donor[i];226 if (typeof setting === "object") {227 if (!recipient.hasOwnProperty(i)) {228 recipient[i] = new setting.constructor();229 }230 this.proliferate(recipient[i], setting, noOverride);231 }232 else {233 // Regular primitives are easy to copy otherwise234 recipient[i] = setting;235 }236 }237 return recipient;238 };239 return ObjectMakr;240 })();241 ObjectMakr_1.ObjectMakr = ObjectMakr;...

Full Screen

Full Screen

AndroidProject.js

Source:AndroidProject.js Github

copy

Full Screen

1/**2 Licensed to the Apache Software Foundation (ASF) under one3 or more contributor license agreements. See the NOTICE file4 distributed with this work for additional information5 regarding copyright ownership. The ASF licenses this file6 to you under the Apache License, Version 2.0 (the7 "License"); you may not use this file except in compliance8 with the License. You may obtain a copy of the License at9 http://www.apache.org/licenses/LICENSE-2.010 Unless required by applicable law or agreed to in writing,11 software distributed under the License is distributed on an12 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13 KIND, either express or implied. See the License for the14 specific language governing permissions and limitations15 under the License.16*/17var fs = require('fs');18var path = require('path');19var properties_parser = require('properties-parser');20var AndroidManifest = require('./AndroidManifest');21var projectFileCache = {};22function addToPropertyList(projectProperties, key, value) {23 var i = 1;24 while (projectProperties.get(key + '.' + i))25 i++;26 projectProperties.set(key + '.' + i, value);27 projectProperties.dirty = true;28}29function removeFromPropertyList(projectProperties, key, value) {30 var i = 1;31 var currentValue;32 while ((currentValue = projectProperties.get(key + '.' + i))) {33 if (currentValue === value) {34 while ((currentValue = projectProperties.get(key + '.' + (i + 1)))) {35 projectProperties.set(key + '.' + i, currentValue);36 i++;37 }38 projectProperties.set(key + '.' + i);39 break;40 }41 i++;42 }43 projectProperties.dirty = true;44}45function getRelativeLibraryPath (parentDir, subDir) {46 var libraryPath = path.relative(parentDir, subDir);47 return (path.sep == '\\') ? libraryPath.replace(/\\/g, '/') : libraryPath;48}49function AndroidProject(projectDir) {50 this._propertiesEditors = {};51 this._subProjectDirs = {};52 this._dirty = false;53 this.projectDir = projectDir;54 this.platformWww = path.join(this.projectDir, 'platform_www');55 this.www = path.join(this.projectDir, 'assets/www');56}57AndroidProject.getProjectFile = function (projectDir) {58 if (!projectFileCache[projectDir]) {59 projectFileCache[projectDir] = new AndroidProject(projectDir);60 }61 return projectFileCache[projectDir];62};63AndroidProject.purgeCache = function (projectDir) {64 if (projectDir) {65 delete projectFileCache[projectDir];66 } else {67 projectFileCache = {};68 }69};70/**71 * Reads the package name out of the Android Manifest file72 *73 * @param {String} projectDir The absolute path to the directory containing the project74 *75 * @return {String} The name of the package76 */77AndroidProject.prototype.getPackageName = function() {78 return new AndroidManifest(path.join(this.projectDir, 'AndroidManifest.xml')).getPackageId();79};80AndroidProject.prototype.getCustomSubprojectRelativeDir = function(plugin_id, src) {81 // All custom subprojects are prefixed with the last portion of the package id.82 // This is to avoid collisions when opening multiple projects in Eclipse that have subprojects with the same name.83 var packageName = this.getPackageName();84 var lastDotIndex = packageName.lastIndexOf('.');85 var prefix = packageName.substring(lastDotIndex + 1);86 var subRelativeDir = path.join(plugin_id, prefix + '-' + path.basename(src));87 return subRelativeDir;88};89AndroidProject.prototype.addSubProject = function(parentDir, subDir) {90 var parentProjectFile = path.resolve(parentDir, 'project.properties');91 var subProjectFile = path.resolve(subDir, 'project.properties');92 var parentProperties = this._getPropertiesFile(parentProjectFile);93 // TODO: Setting the target needs to happen only for pre-3.7.0 projects94 if (fs.existsSync(subProjectFile)) {95 var subProperties = this._getPropertiesFile(subProjectFile);96 subProperties.set('target', parentProperties.get('target'));97 subProperties.dirty = true;98 this._subProjectDirs[subDir] = true;99 }100 addToPropertyList(parentProperties, 'android.library.reference', getRelativeLibraryPath(parentDir, subDir));101 this._dirty = true;102};103AndroidProject.prototype.removeSubProject = function(parentDir, subDir) {104 var parentProjectFile = path.resolve(parentDir, 'project.properties');105 var parentProperties = this._getPropertiesFile(parentProjectFile);106 removeFromPropertyList(parentProperties, 'android.library.reference', getRelativeLibraryPath(parentDir, subDir));107 delete this._subProjectDirs[subDir];108 this._dirty = true;109};110AndroidProject.prototype.addGradleReference = function(parentDir, subDir) {111 var parentProjectFile = path.resolve(parentDir, 'project.properties');112 var parentProperties = this._getPropertiesFile(parentProjectFile);113 addToPropertyList(parentProperties, 'cordova.gradle.include', getRelativeLibraryPath(parentDir, subDir));114 this._dirty = true;115};116AndroidProject.prototype.removeGradleReference = function(parentDir, subDir) {117 var parentProjectFile = path.resolve(parentDir, 'project.properties');118 var parentProperties = this._getPropertiesFile(parentProjectFile);119 removeFromPropertyList(parentProperties, 'cordova.gradle.include', getRelativeLibraryPath(parentDir, subDir));120 this._dirty = true;121};122AndroidProject.prototype.addSystemLibrary = function(parentDir, value) {123 var parentProjectFile = path.resolve(parentDir, 'project.properties');124 var parentProperties = this._getPropertiesFile(parentProjectFile);125 addToPropertyList(parentProperties, 'cordova.system.library', value);126 this._dirty = true;127};128AndroidProject.prototype.removeSystemLibrary = function(parentDir, value) {129 var parentProjectFile = path.resolve(parentDir, 'project.properties');130 var parentProperties = this._getPropertiesFile(parentProjectFile);131 removeFromPropertyList(parentProperties, 'cordova.system.library', value);132 this._dirty = true;133};134AndroidProject.prototype.write = function() {135 if (!this._dirty) {136 return;137 }138 this._dirty = false;139 for (var filename in this._propertiesEditors) {140 var editor = this._propertiesEditors[filename];141 if (editor.dirty) {142 fs.writeFileSync(filename, editor.toString());143 editor.dirty = false;144 }145 }146};147AndroidProject.prototype._getPropertiesFile = function (filename) {148 if (!this._propertiesEditors[filename]) {149 if (fs.existsSync(filename)) {150 this._propertiesEditors[filename] = properties_parser.createEditor(filename);151 } else {152 this._propertiesEditors[filename] = properties_parser.createEditor();153 }154 }155 return this._propertiesEditors[filename];156};...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pandera automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful