Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions tfjs-node/src/image_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2019 Google Inc. All Rights Reserved.
* Copyright 2020 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -14,10 +14,12 @@
* limitations under the License.
* =============================================================================
*/

import {memory, setBackend, test_util} from '@tensorflow/tfjs';
import {memory, registerBackend, setBackend, test_util} from '@tensorflow/tfjs';
// tslint:disable-next-line: no-imports-from-dist
import {TestKernelBackend} from '@tensorflow/tfjs-core/dist/jasmine_util';
import * as fs from 'fs';
import {promisify} from 'util';

import {getImageType, ImageType} from './image';
import * as tf from './index';

Expand Down Expand Up @@ -221,14 +223,18 @@ describe('decode images', () => {

it('throw error if backend is not tensorflow', async done => {
try {
setBackend('cpu');
const testBackend = new TestKernelBackend();
registerBackend('fake', () => testBackend);
setBackend('fake');

const uint8array = await getUint8ArrayFromImage(
'test_objects/images/image_png_test.png');
tf.node.decodeImage(uint8array);
done.fail();
} catch (err) {
expect(err.message)
.toBe('Expect the current backend to be "tensorflow", but got "cpu"');
.toBe(
'Expect the current backend to be "tensorflow", but got "fake"');
setBackend('tensorflow');
done();
}
Expand Down
11 changes: 9 additions & 2 deletions tfjs-node/src/nodejs_kernel_backend_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/

import * as tf from '@tensorflow/tfjs';
// tslint:disable-next-line: no-imports-from-dist
import {TestKernelBackend} from '@tensorflow/tfjs-core/dist/jasmine_util';

import {createTensorsTypeOpAttr, createTypeOpAttr, ensureTensorflowBackend, getTFDType, nodeBackend, NodeJSKernelBackend} from './nodejs_kernel_backend';

describe('delayed upload', () => {
Expand Down Expand Up @@ -74,12 +77,16 @@ describe('Exposes Backend for internal Op execution.', () => {

it('throw error if backend is not tensorflow', async done => {
try {
tf.setBackend('cpu');
const testBackend = new TestKernelBackend();
tf.registerBackend('fake', () => testBackend);
tf.setBackend('fake');

ensureTensorflowBackend();
done.fail();
} catch (err) {
expect(err.message)
.toBe('Expect the current backend to be "tensorflow", but got "cpu"');
.toBe(
'Expect the current backend to be "tensorflow", but got "fake"');
tf.setBackend('tensorflow');
done();
}
Expand Down
16 changes: 10 additions & 6 deletions tfjs-node/src/run_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ process.on('unhandledRejection', e => {
throw e;
});

jasmine_util.setTestEnvs(
[{name: 'test-tensorflow', backendName: 'tensorflow', flags: {}}]);
jasmine_util.setTestEnvs([{
name: 'test-tensorflow',
backendName: 'tensorflow',
flags: {},
isDataSync: true
}]);

const IGNORE_LIST: string[] = [
// Always ignore version tests:
Expand Down Expand Up @@ -90,11 +94,11 @@ if (process.platform === 'win32') {
'maxPool test-tensorflow {} [x=[3,3,1] f=[2,2] s=1 ignores NaNs');
}

const coreTests = 'node_modules/@tensorflow/tfjs-core/dist/**/*_test.js';
const nodeTests = 'src/**/*_test.ts';

const runner = new jasmineCtor();
runner.loadConfig({spec_files: [coreTests, nodeTests], random: false});
runner.loadConfig({spec_files: ['src/**/*_test.ts'], random: false});
// Also import tests from core.
// tslint:disable-next-line: no-imports-from-dist
import '@tensorflow/tfjs-core/dist/tests';

if (process.env.JASMINE_SEED) {
runner.seed(process.env.JASMINE_SEED);
Expand Down