1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import * as device_util from './device_util';
|
18 | import * as tf from './index';
|
19 | describe('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 |
|
40 | describe('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 |
|
48 | xit('isBrowser: true', () => {
|
49 | isBrowser = true;
|
50 | expect(tf.env().getBool('IS_BROWSER')).toBe(true);
|
51 | });
|
52 |
|
53 | xit('isBrowser: false', () => {
|
54 | isBrowser = false;
|
55 | expect(tf.env().getBool('IS_BROWSER')).toBe(false);
|
56 | });
|
57 | });
|
58 | describe('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 | });
|
65 | describe('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 |
|
74 | spyOn(console, 'warn');
|
75 | tf.enableDebugMode();
|
76 | expect(tf.env().getBool('TENSORLIKE_CHECK_SHAPE_CONSISTENCY')).toBe(true);
|
77 | });
|
78 | });
|
79 | describe('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 | });
|
86 | describe('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 | });
|
93 | describe('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 |
|
\ | No newline at end of file |