• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Tests for python_lang_utils module."""
16
17from tensorflow.python.autograph.operators import variables
18from tensorflow.python.platform import test
19
20
21class SpecialValuesTest(test.TestCase):
22
23  def test_undefined(self):
24    undefined_symbol = variables.Undefined('name')
25    undefined_symbol2 = variables.Undefined('name')
26
27    self.assertEqual(undefined_symbol.symbol_name, 'name')
28    self.assertEqual(undefined_symbol2.symbol_name, 'name')
29    self.assertNotEqual(undefined_symbol, undefined_symbol2)
30
31  def test_undefined_operations(self):
32    undefined_symbol = variables.Undefined('name')
33
34    self.assertIsInstance(undefined_symbol.foo, variables.Undefined)
35    self.assertIsInstance(undefined_symbol[0], variables.Undefined)
36    self.assertNotIsInstance(undefined_symbol.__class__, variables.Undefined)
37
38  def test_read(self):
39    self.assertEqual(variables.ld(1), 1)
40    o = object()
41    self.assertEqual(variables.ld(o), o)
42
43    self.assertIsNone(variables.ld(None))
44
45  def test_read_undefined(self):
46    with self.assertRaisesRegex(UnboundLocalError, 'used before assignment'):
47      variables.ld(variables.Undefined('a'))
48
49
50if __name__ == '__main__':
51  test.main()
52