Skip to content

Commit e55dd98

Browse files
authored
Merge pull request #101 from lizlooney/pr_fix_toolbox_tests
Make toolbox_tests use extended python generator.
2 parents 465d26f + 2e74141 commit e55dd98

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const App: React.FC = () => {
134134

135135
openStorage();
136136
initializeBlocks();
137-
//testAllBlocksInToolbox(toolbox.getToolboxJSON([], []).contents);
137+
//testAllBlocksInToolbox();
138138
}, []);
139139

140140
const openStorage = async () => {

src/toolbox/toolbox.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {category as methodsCategory} from './methods_category';
3131

3232
export function getToolboxJSON(
3333
opt_includeExportedBlocksFromProject: toolboxItems.ContentsType[],
34-
shownPythonToolboxCategories: Set<string>) {
34+
shownPythonToolboxCategories: Set<string> | null) {
3535
const contents: toolboxItems.ContentsType[] = generatedToolbox.getToolboxCategories();
3636
filterGeneratedCategories(contents, shownPythonToolboxCategories);
3737

@@ -81,7 +81,7 @@ export function getToolboxJSON(
8181
}
8282

8383
function filterGeneratedCategories(
84-
contents: toolboxItems.ContentsType[], shownPythonToolboxCategories: Set<string>) {
84+
contents: toolboxItems.ContentsType[], shownPythonToolboxCategories: Set<string> | null) {
8585
contents.forEach((item) => {
8686
if (item.kind === 'category') {
8787
const category = item as toolboxItems.Category;
@@ -91,15 +91,15 @@ function filterGeneratedCategories(
9191
}
9292
if ((category as toolboxItems.PythonModuleCategory).moduleName) {
9393
const moduleName = (item as toolboxItems.PythonModuleCategory).moduleName;
94-
if (!shownPythonToolboxCategories.has(moduleName)) {
94+
if (shownPythonToolboxCategories != null && !shownPythonToolboxCategories.has(moduleName)) {
9595
if (category.contents) {
9696
removeBlocksAndSeparators(category.contents);
9797
}
9898
}
9999
}
100100
if ((category as toolboxItems.PythonClassCategory).className) {
101101
const className = (item as toolboxItems.PythonClassCategory).className;
102-
if (!shownPythonToolboxCategories.has(className)) {
102+
if (shownPythonToolboxCategories != null && !shownPythonToolboxCategories.has(className)) {
103103
if (category.contents) {
104104
removeBlocksAndSeparators(category.contents);
105105
}
@@ -123,7 +123,7 @@ function removeBlocksAndSeparators(contents: toolboxItems.ContentsType[]) {
123123
}
124124

125125
function removeEmptyCategories(
126-
contents: toolboxItems.ContentsType[], shownPythonToolboxCategories: Set<string>) {
126+
contents: toolboxItems.ContentsType[], shownPythonToolboxCategories: Set<string> | null) {
127127
let i = 0;
128128
while (i < contents.length) {
129129
let remove = false;
@@ -137,7 +137,7 @@ function removeEmptyCategories(
137137
}
138138
if (category.contents &&
139139
category.contents.length == 0 &&
140-
!shownPythonToolboxCategories.has(fullCategoryName)) {
140+
shownPythonToolboxCategories != null && !shownPythonToolboxCategories.has(fullCategoryName)) {
141141
remove = true;
142142
}
143143
}

src/toolbox/toolbox_tests.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
*/
2121

2222
import * as Blockly from 'blockly/core';
23-
import { pythonGenerator } from 'blockly/python';
23+
import { extendedPythonGenerator } from '../editor/extended_python_generator';
2424
import * as toolboxItems from './items';
25+
import { getToolboxJSON } from '../toolbox/toolbox';
2526

2627

2728
// Tests
2829

29-
export function testAllBlocksInToolbox(contents: toolboxItems.ContentsType[]) {
30+
export function testAllBlocksInToolbox() {
31+
const contents: toolboxItems.ContentsType[] = getToolboxJSON([], null).contents;
3032
alert('Press OK to run tests on all blocks from the toolbox.');
3133
const toolboxTestData = new ToolboxTestData(contents, () => {
3234
alert('Completed tests on all blocks in the toolbox. See console for any errors.');
@@ -104,24 +106,24 @@ class ToolboxTestData {
104106
}
105107

106108
private testBlockPython(block: Blockly.Block) {
107-
pythonGenerator.init(this.blocklyWorkspace);
109+
extendedPythonGenerator.init(this.blocklyWorkspace);
108110
let code = null;
109111
try {
110-
code = pythonGenerator.blockToCode(block);
112+
code = extendedPythonGenerator.blockToCode(block);
111113
} catch (e) {
112114
console.log('Error - ' + e + ' - Unable to test block...'); console.log(block);
113115
}
114116
if (block.outputConnection) {
115117
if (!Array.isArray(code)) {
116118
console.log(
117-
'Error - pythonGenerator.forBlock["' + block.type + '"] ' +
119+
'Error - extendedPythonGenerator.forBlock["' + block.type + '"] ' +
118120
'generated a ' + (typeof code) +
119121
', but it should generate an array because the block has an output connection.');
120122
}
121123
} else {
122124
if (typeof code != 'string') {
123125
console.log(
124-
'Error - pythonGenerator.forBlock["' + block.type + '"] ' +
126+
'Error - extendedPythonGenerator.forBlock["' + block.type + '"] ' +
125127
'generated a ' + (typeof code) +
126128
', but should generate a string because the block does not have an output connection.');
127129
}

0 commit comments

Comments
 (0)