|
| 1 | +/** |
| 2 | + * Copyright 2018, Google, LLC. |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +'use strict'; |
| 17 | + |
| 18 | +const {assert} = require('chai'); |
| 19 | +const cp = require('child_process'); |
| 20 | + |
| 21 | +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); |
| 22 | + |
| 23 | +const cmdDataset = 'node automlTranslationDataset.js'; |
| 24 | +const cmdModel = 'node automlTranslationModel.js'; |
| 25 | +const cmdPredict = 'node automlTranslationPredict.js'; |
| 26 | + |
| 27 | +const testDataSetName = 'testDataSet'; |
| 28 | +const dummyDataSet = 'dummyDataSet'; |
| 29 | +const testModelName = 'dummyModel'; |
| 30 | +const sampleText = './resources/testInput.txt'; |
| 31 | +const donotdeleteModelId = 'TRL188026453969732486'; |
| 32 | + |
| 33 | +describe.skip('automl sample tests', () => { |
| 34 | + it(`should create a create, list, and delete a dataset`, async () => { |
| 35 | + // Check to see that this dataset does not yet exist |
| 36 | + let output = execSync(`${cmdDataset} list-datasets`); |
| 37 | + assert.match(output, new RegExp(testDataSetName)); |
| 38 | + |
| 39 | + // Create dataset |
| 40 | + output = execSync(`${cmdDataset} create-dataset -n "${testDataSetName}"`); |
| 41 | + const dataSetId = output |
| 42 | + .split(`\n`)[1] |
| 43 | + .split(`:`)[1] |
| 44 | + .trim(); |
| 45 | + assert.match( |
| 46 | + output, |
| 47 | + new RegExp(`Dataset display name: ${testDataSetName}`) |
| 48 | + ); |
| 49 | + |
| 50 | + // Delete dataset |
| 51 | + output = execSync(`${cmdDataset} delete-dataset -i "${dataSetId}"`); |
| 52 | + assert.match(output, /Dataset deleted./); |
| 53 | + }); |
| 54 | + |
| 55 | + // We make two models running this test, see hard-coded workaround below |
| 56 | + it(`should create a dataset, import data, and start making a model`, async () => { |
| 57 | + // Check to see that this dataset does not yet exist |
| 58 | + let output = execSync(`${cmdDataset} list-datasets`); |
| 59 | + assert.notMatch(output, new RegExp(dummyDataSet)); |
| 60 | + |
| 61 | + // Create dataset |
| 62 | + output = execSync(`${cmdDataset} create-dataset -n "${dummyDataSet}"`); |
| 63 | + const dataSetId = output |
| 64 | + .split(`\n`)[1] |
| 65 | + .split(`:`)[1] |
| 66 | + .trim(); |
| 67 | + assert.match(output, new RegExp(`Dataset display name: ${dummyDataSet}`)); |
| 68 | + |
| 69 | + // Import Data |
| 70 | + output = execSync( |
| 71 | + `${cmdDataset} import-data -i "${dataSetId}" -p "gs://nodejs-docs-samples-vcm/flowerTraindata20lines.csv"` |
| 72 | + ); |
| 73 | + assert.match(output, /Data imported./); |
| 74 | + |
| 75 | + // Check to make sure model doesn't already exist |
| 76 | + output = execSync(`${cmdModel} list-models`); |
| 77 | + assert.notMatch(output, testModelName); |
| 78 | + |
| 79 | + // Begin training dataset, getting operation ID for next operation |
| 80 | + output = execSync( |
| 81 | + `${cmdModel} create-model -i "${dataSetId}" -m "${testModelName}" -t "2"` |
| 82 | + ); |
| 83 | + const operationName = output |
| 84 | + .split(`\n`)[0] |
| 85 | + .split(`:`)[1] |
| 86 | + .trim(); |
| 87 | + assert.match(output, `Training started...`); |
| 88 | + |
| 89 | + // Poll operation status, here confirming that operation is not complete yet |
| 90 | + output = execSync( |
| 91 | + `${cmdModel} get-operation-status -i "${dataSetId}" -o "${operationName}"` |
| 92 | + ); |
| 93 | + assert.match(output, /done: false/); |
| 94 | + }); |
| 95 | + |
| 96 | + it(`should run get model (from a prexisting model)`, async () => { |
| 97 | + // Confirm dataset exists |
| 98 | + let output = execSync(`${cmdDataset} list-datasets`); |
| 99 | + assert.match(output, /me_do_not_delete/); |
| 100 | + |
| 101 | + // List model evaluations, confirm model exists |
| 102 | + output = execSync( |
| 103 | + `${cmdModel} list-model-evaluations -a "${donotdeleteModelId}"` |
| 104 | + ); |
| 105 | + assert.match(output, /translationEvaluationMetrics:/); |
| 106 | + |
| 107 | + // Get model evaluation |
| 108 | + output = execSync(`${cmdModel} get-model -a "${donotdeleteModelId}"`); |
| 109 | + assert.match(output, /Model deployment state: DEPLOYED/); |
| 110 | + }); |
| 111 | + |
| 112 | + it(`should run Prediction from prexisting model`, async () => { |
| 113 | + // Confirm dataset exists |
| 114 | + let output = execSync(`${cmdDataset} list-datasets`); |
| 115 | + assert.match(output, /me_do_not_delete/); |
| 116 | + |
| 117 | + // List model evaluations, confirm model exists |
| 118 | + output = execSync( |
| 119 | + `${cmdModel} list-model-evaluations -a "${donotdeleteModelId}"` |
| 120 | + ); |
| 121 | + assert.match(output, `translationEvaluationMetrics:`); |
| 122 | + |
| 123 | + // Run prediction on 'testImage.jpg' in resources folder |
| 124 | + output = execSync( |
| 125 | + `${cmdPredict} predict -i "${donotdeleteModelId}" -f "${sampleText}" -t "False"` |
| 126 | + ); |
| 127 | + assert.match( |
| 128 | + output, |
| 129 | + /Translated Content: {2}これがどのように終わるか教えて/ |
| 130 | + ); |
| 131 | + }); |
| 132 | + |
| 133 | + // List datasets |
| 134 | + it(`should list datasets`, async () => { |
| 135 | + const output = execSync(`${cmdDataset} list-datasets`); |
| 136 | + assert.match(output, /List of datasets:/); |
| 137 | + }); |
| 138 | +}); |
0 commit comments