Skip to content

Commit

Permalink
chore: corrected batch tests (#619)
Browse files Browse the repository at this point in the history
* chore: corrected batch tests

* removed report files

* fixed lints and reversed hybrid test
  • Loading branch information
munkhuushmgl authored and Ace Nassri committed Nov 17, 2022
1 parent 1efb237 commit a2fe318
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
54 changes: 26 additions & 28 deletions translate/test/v3/translate_batch_translate_text.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const REGION_TAG = 'translate_batch_translate_text';

describe(REGION_TAG, function () {
this.retries(3);
describe(REGION_TAG, () => {
const translationClient = new TranslationServiceClient();
const location = 'us-central1';
const bucketUuid = uuid.v4();
Expand All @@ -48,32 +47,31 @@ describe(REGION_TAG, function () {
console.error(error);
}
});
});
}),
it('should batch translate the input text', async function () {
this.retries(3);
const projectId = await translationClient.getProjectId();
const inputUri = 'gs://cloud-samples-data/translation/text.txt';

it('should batch translate the input text', async () => {
const projectId = await translationClient.getProjectId();
const inputUri = 'gs://cloud-samples-data/translation/text.txt';

const outputUri = `gs://${projectId}/${bucketName}`;
const output = execSync(
`node v3/${REGION_TAG}.js ${projectId} ${location} ${inputUri} ${outputUri}`
);
assert.match(output, /Total Characters: 13/);
assert.match(output, /Translated Characters: 13/);
});

// Delete the folder from GCS for cleanup
after(async () => {
const projectId = await translationClient.getProjectId();
const options = {
prefix: `translation-${bucketUuid}`,
};
const outputUri = `gs://${projectId}/${bucketName}`;
const output = execSync(
`node v3/${REGION_TAG}.js ${projectId} ${location} ${inputUri} ${outputUri}`
);
assert.match(output, /Total Characters: 13/);
assert.match(output, /Translated Characters: 13/);
}),
// Delete the folder from GCS for cleanup
after(async () => {
const projectId = await translationClient.getProjectId();
const options = {
prefix: `translation-${bucketUuid}`,
};

const bucket = await storage.bucket(projectId);
const [files] = await bucket.getFiles(options);
const length = files.length;
if (length > 0) {
await Promise.all(files.map(file => file.delete()));
}
});
const bucket = await storage.bucket(projectId);
const [files] = await bucket.getFiles(options);
const length = files.length;
if (length > 0) {
await Promise.all(files.map(file => file.delete()));
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const REGION_TAG = 'translate_batch_translate_text_with_glossary_and_model';

describe(REGION_TAG, function () {
this.retries(3);
describe(REGION_TAG, () => {
const translationClient = new TranslationServiceClient();
const location = 'us-central1';
const glossaryId = `my_test_glossary_${uuid.v4()}`;
Expand Down Expand Up @@ -74,6 +73,7 @@ describe(REGION_TAG, function () {
});

it('should batch translate the input text with a glossary', async function () {
this.retries(3);
const projectId = await translationClient.getProjectId();
const inputUri =
'gs://cloud-samples-data/translation/text_with_custom_model_and_glossary.txt';
Expand Down

0 comments on commit a2fe318

Please sign in to comment.