Skip to content

Commit 8c00b47

Browse files
tafsiricaisq
authored andcommitted
Update test spy to match changes in core (#573)
* Update test spy to match changes in core The internal mechanism of weightsLoader in tfjs-core changed to use ENV.platform.fetch instead of util.fetch. DEV
1 parent 8e044b9 commit 8c00b47

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/models_test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* =============================================================================
99
*/
1010

11-
import {DataType, io, memory, ones, randomNormal, Scalar, scalar, serialization, sum, Tensor, tensor1d, tensor2d, tensor3d, train, zeros, util} from '@tensorflow/tfjs-core';
11+
import {DataType, ENV, io, memory, ones, randomNormal, Scalar, scalar, serialization, sum, Tensor, tensor1d, tensor2d, tensor3d, train, zeros} from '@tensorflow/tfjs-core';
1212
import {ConfigDict} from '@tensorflow/tfjs-core/dist/serialization';
1313

1414
import {LayersModel} from './engine/training';
@@ -549,7 +549,7 @@ describeMathCPU('loadLayersModel from URL', () => {
549549
const setupFakeWeightFiles =
550550
(fileBufferMap:
551551
{[filename: string]: Float32Array|Int32Array|ArrayBuffer}) => {
552-
spyOn(util, 'fetch')
552+
spyOn(ENV.platform, 'fetch')
553553
.and.callFake((path: string) => new Promise(resolve => {
554554
resolve(new Response(fileBufferMap[path], {
555555
'headers': {'Content-Type': OCTET_STREAM_TYPE}
@@ -631,7 +631,7 @@ describeMathCPU('loadLayersModel from URL', () => {
631631
}
632632
];
633633

634-
spyOn(util, 'fetch').and.callFake((path: string) => {
634+
spyOn(ENV.platform, 'fetch').and.callFake((path: string) => {
635635
return new Promise((resolve, reject) => {
636636
if (path === 'model/model.json') {
637637
resolve(new Response(
@@ -683,7 +683,7 @@ describeMathCPU('loadLayersModel from URL', () => {
683683
}
684684
];
685685

686-
spyOn(util, 'fetch').and.callFake((path: string) => {
686+
spyOn(ENV.platform, 'fetch').and.callFake((path: string) => {
687687
return new Promise((resolve, reject) => {
688688
if (path === 'model/model.json') {
689689
resolve(new Response(
@@ -743,7 +743,7 @@ describeMathCPU('loadLayersModel from URL', () => {
743743
}
744744
];
745745

746-
spyOn(util, 'fetch').and.callFake((path: string) => {
746+
spyOn(ENV.platform, 'fetch').and.callFake((path: string) => {
747747
return new Promise((resolve, reject) => {
748748
if (path === 'https://url/to/model/model.json') {
749749
resolve(new Response(
@@ -806,7 +806,7 @@ describeMathCPU('loadLayersModel from URL', () => {
806806

807807
const kernelData = ones([32, 32], 'float32').dataSync() as Float32Array;
808808
const biasData = zeros([32], 'float32').dataSync() as Float32Array;
809-
spyOn(util, 'fetch').and.callFake((path: string) => {
809+
spyOn(ENV.platform, 'fetch').and.callFake((path: string) => {
810810
return new Promise((resolve, reject) => {
811811
if (path === 'model/model.json') {
812812
resolve(new Response(
@@ -871,7 +871,7 @@ describeMathCPU('loadLayersModel from URL', () => {
871871
[{'name': `dense_2/bias`, 'dtype': 'float32', 'shape': [1]}],
872872
}
873873
];
874-
spyOn(util, 'fetch').and.callFake((path: string) => {
874+
spyOn(ENV.platform, 'fetch').and.callFake((path: string) => {
875875
return new Promise((resolve, reject) => {
876876
if (path === 'model/model.json') {
877877
resolve(new Response(
@@ -940,7 +940,7 @@ describeMathCPU('loadLayersModel from URL', () => {
940940
'weights': [{'name': `dense_2/bias`, 'dtype': 'float32', 'shape': [1]}],
941941
}
942942
];
943-
spyOn(util, 'fetch').and.callFake((path: string) => {
943+
spyOn(ENV.platform, 'fetch').and.callFake((path: string) => {
944944
return new Promise((resolve, reject) => {
945945
if (path === 'model/model.json') {
946946
resolve(new Response(
@@ -1007,7 +1007,7 @@ describeMathCPU('loadLayersModel from URL', () => {
10071007

10081008
const requestHeaders: Array<{[key: string]: string | {}}> = [];
10091009
const requestCredentials: string[] = [];
1010-
spyOn(util, 'fetch')
1010+
spyOn(ENV.platform, 'fetch')
10111011
.and.callFake((path: string, requestInit?: RequestInit) => {
10121012
if (requestInit != null) {
10131013
requestHeaders.push(requestInit.headers as {});
@@ -1085,7 +1085,7 @@ describeMathCPU('loadLayersModel from URL', () => {
10851085
[{'name': `dense_6/bias`, 'dtype': 'float32', 'shape': [32]}],
10861086
}
10871087
];
1088-
spyOn(util, 'fetch').and.callFake((path: string) => {
1088+
spyOn(ENV.platform, 'fetch').and.callFake((path: string) => {
10891089
return new Promise((resolve, reject) => {
10901090
if (path === `${protocol}localhost:8888/models/model.json`) {
10911091
resolve(new Response(

0 commit comments

Comments
 (0)