UNPKG

3.87 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright 2019 Google LLC. All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 * =============================================================================
16 */
17import * as device_util from './device_util';
18import * as tf from './index';
19describe('DEBUG', () => {
20 beforeEach(() => {
21 tf.env().reset();
22 spyOn(console, 'warn').and.callFake((msg) => { });
23 });
24 afterAll(() => tf.env().reset());
25 it('disabled by default', () => {
26 expect(tf.env().getBool('DEBUG')).toBe(false);
27 });
28 it('warns when enabled', () => {
29 const consoleWarnSpy = console.warn;
30 tf.env().set('DEBUG', true);
31 expect(consoleWarnSpy.calls.count()).toBe(1);
32 expect(consoleWarnSpy.calls.first().args[0]
33 .startsWith('Debugging mode is ON. '))
34 .toBe(true);
35 expect(tf.env().getBool('DEBUG')).toBe(true);
36 expect(consoleWarnSpy.calls.count()).toBe(1);
37 });
38});
39// TODO (yassogba) figure out why this spy is not working / fix this test.
40describe('IS_BROWSER', () => {
41 let isBrowser;
42 beforeEach(() => {
43 tf.env().reset();
44 spyOn(device_util, 'isBrowser').and.callFake(() => isBrowser);
45 });
46 afterAll(() => tf.env().reset());
47 // tslint:disable-next-line: ban
48 xit('isBrowser: true', () => {
49 isBrowser = true;
50 expect(tf.env().getBool('IS_BROWSER')).toBe(true);
51 });
52 // tslint:disable-next-line: ban
53 xit('isBrowser: false', () => {
54 isBrowser = false;
55 expect(tf.env().getBool('IS_BROWSER')).toBe(false);
56 });
57});
58describe('PROD', () => {
59 beforeEach(() => tf.env().reset());
60 afterAll(() => tf.env().reset());
61 it('disabled by default', () => {
62 expect(tf.env().getBool('PROD')).toBe(false);
63 });
64});
65describe('TENSORLIKE_CHECK_SHAPE_CONSISTENCY', () => {
66 beforeEach(() => tf.env().reset());
67 afterAll(() => tf.env().reset());
68 it('disabled when debug is disabled', () => {
69 tf.env().set('DEBUG', false);
70 expect(tf.env().getBool('TENSORLIKE_CHECK_SHAPE_CONSISTENCY')).toBe(false);
71 });
72 it('enabled when debug is enabled', () => {
73 // Silence debug warnings.
74 spyOn(console, 'warn');
75 tf.enableDebugMode();
76 expect(tf.env().getBool('TENSORLIKE_CHECK_SHAPE_CONSISTENCY')).toBe(true);
77 });
78});
79describe('DEPRECATION_WARNINGS_ENABLED', () => {
80 beforeEach(() => tf.env().reset());
81 afterAll(() => tf.env().reset());
82 it('enabled by default', () => {
83 expect(tf.env().getBool('DEPRECATION_WARNINGS_ENABLED')).toBe(true);
84 });
85});
86describe('IS_TEST', () => {
87 beforeEach(() => tf.env().reset());
88 afterAll(() => tf.env().reset());
89 it('disabled by default', () => {
90 expect(tf.env().getBool('IS_TEST')).toBe(false);
91 });
92});
93describe('async flags test', () => {
94 const asyncFlagName = 'ASYNC_FLAG';
95 beforeEach(() => tf.env().registerFlag(asyncFlagName, async () => true));
96 afterEach(() => tf.env().reset());
97 it('evaluating async flag works', async () => {
98 const flagVal = await tf.env().getAsync(asyncFlagName);
99 expect(flagVal).toBe(true);
100 });
101 it('evaluating async flag synchronously fails', async () => {
102 expect(() => tf.env().get(asyncFlagName)).toThrow();
103 });
104});
105//# sourceMappingURL=flags_test.js.map
\No newline at end of file